Shrinkage of the Sample Covariance matrix

Question: Assume we have N independent and identically distributed random vectors $X_1, X_2, ..., X_N$ where each of them is of size p $\times$ 1. The sample covariance matrix, denoted here by $S$, is computed as $(1/N)XX'$ where $X$ is now a matrix having the $X_i$ as columns, $i = 1, 2, ..., N$.
As we all know that $S$, has no structure, unbiased but has a lot of estimation error(ill-conditioned). In addition, $S$ becomes singular when $p>=N$.
So the obvious idea is to try by shrinking the unbiased covariance matrix $S$ towards a biased (with less variance) structured covariance often called "The shrinkage Target". The shrinkage formula can be expressed as follows:
$~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~$$(1-\alpha)S + \alpha F$
Where $\alpha$ is the shrinkage intensity (between 0 and 1), and $F$ is the shrinkage target.
In shrinkage, the most challenging part is how to compute (automatically) the shrinkage intensity. So following the article of Ledoit and Wolf in 2003 "Improved Estimation of the Covariance Matrix of Stock Returns
With an Application to Portfolio Selection", they computed an automatic optimal shrinkage intensity after minimizing a certain loss function based on the Frobenius distance.
Ok great! My question now is from this article. In page 8, I want to know how they just computed $[E(\alpha f_{ij} + (1 - \alpha)s_{ij} - \delta_{ij}]^2$. Ok, in the article, they used the single index model as shrinkage target $F$. But in fact, let us compute this squared expected value for a general shrinkage target. I just want to know how they computed this squared expectation (I am just interested for this expectation in page 8 before they did the derivation w.r.t $\alpha$)...
Kindly any help will be very very appreciated!!
Comment: Maybe I'm looking at the wrong version, but on p.7 of http://www.ledoit.net/ole2.pdf they have $(\mathbb{E}[\alpha f_{ij} + (1-\alpha)s_{ij} - \sigma_{ij}])^2$ (not $\delta_{ij}^2$). If that's the right version, then they just wrote $$ \alpha (f-\phi) + (1-\alpha)(s-\sigma) + \alpha \phi + (1-\alpha)\sigma - \sigma, $$ where $\phi=\mathbb{E}[f]$ and $\sigma=\mathbb{E}[s]$ and expanded the expectation of the square as $$ \alpha^2 \mathbb{V}[f] + (1-\alpha)^2\mathbb{V}[s] + 2\alpha(1-\alpha)\mathrm{Cov}(f,s) + \alpha^2(\phi - \sigma)^2 $$ using the usual definition of variance. Is this close?
Comment: Thank you very much for your time and reading my problem! but really I am still not understanding. Can you please put your explanation as an answer and explain me in details how you got your first line and then how you got $2 \alpha (1-\alpha)Cov(f,s) + \alpha^2 (\phi - \delta)^2$. And can you generalize your answer by considering that F is an identity matrix. Kindly your answer will be sooo appreciated for me!
Comment: Wow Christina, you really seem to have some kind of covariance estimation and shrinkage thing going on with many questions on this general topic.  Are you doing some kind of research in the area?
Comment: Hallo, yes I want to present next week at my university the work of this article in details and some alternatives of it such as the work of shafer and strimmer in 2005. This is a great topic really
Answer: What they evaluate there is
$$ \mathbb{E}\big[ (\alpha f + (1-\alpha)s - \sigma)^2 \big], $$
(note this isn't identical to what you wrote in the question) where you are given
$$ \mathbb{E}[f] = \phi, \qquad \mathbb{E}[s] = \sigma. $$
They evaluate this by writing
$$ \alpha f + (1-\alpha)s-\sigma =: X, $$
and using the identity
$$ \mathbb{E}[X^2] = \mathbb{V}[X] + (\mathbb{E}[X])^2. $$
Since $\phi$ and $\sigma$ are constants here,
$$ \mathbb{V}[X] = \alpha^2 \mathbb{V}[f] + (1-\alpha)^2 \mathbb{V}[s] + \alpha(1-\alpha)\mathrm{Cov}[f,s], $$
and
$$ \mathbb{E}[X] = \alpha(\phi-\sigma) $$
due to $\mathbb{E}[f]=\phi$, $\mathbb{E}[s]=\sigma$, and the usual variance-of-sum formula.
To generalize this to any other $\phi$, note that none of the properties of their matrices $\mathbf{F}$, $\mathbf{S}$, $\mathbf{\Sigma}$ are actually being used: this is simply an identity in terms of random variables $f,s$ and their means $\phi,\sigma$. It does not matter whether $\phi$ are the identity matrix elements or something else.
Comment: Okay so their proposal was very general and can be applied to any other target matrices as well. Thank you very much for your time. best regards


Multiple Cascades of Multiple Simultaneous Animations

Question: I'm teaching myself jQuery right now and just for fun I thought I'd expand on the example here: http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_animation.
I'm trying to edit this simple animation so it both fades in then fades out with each successive step of the rectangle. So as the height changes the first time, I want it to simultaneously fade out. Then, as the width changes, I want it to simultaneously fade in, etc., etc. I thought I understood how to do this using function callbacks with fadeIn() and fadeOut(), but what ended up happening was ALL animations defined would run simultaneously. So I then tried the same thing using the "complete:" attribute, but that yielded the same result. What am I doing wrong? Help! Thanks in advance.
Here's the code snippet for my animations:
    $(document).ready(function(){
            $("button").click(animation1());
        });

        function animation1() {
            $("div").animate({height:300},{duration: 2000, queue: false});
            $("div").fadeOut({duration: 2000, queue:false, complete:animation2());
        }

        function animation2() {
            $("div").animate({width:300},{duration:2000,queue:false});
            $("div").fadeIn({duration: 2000, queue:false, complete:animation3()});
        }

        function animation3() {
            $("div").animate({height:100},{duration:2000,queue:false});
            $("div").fadeOut({duration:2000, queue:false, complete:animation4()});
        }

        function animation4() {
            $("div").animate({width:100},{duration:2000,queue:false});
            $("div").fadeIn({duration:2000,queue:false});
        }

Answer: Remove the parentheses from the complete callback, e.g.
function animation1() {
    $("div").animate({height:300},{duration: 2000, queue: false});
    $("div").fadeOut({duration: 2000, queue:false, complete:animation2});
}                                                          no parens ^^^

Also, .fadeOut() uses a different syntax from .animate(). The functions should look like this:
function animation1() {
    $("div").animate({height:300},{duration: 2000, queue: false});
    $("div").fadeOut(2000, animation2);
}

I would not recommend using W3Schools as your primary JavaScript/jQuery/etc. resource. Alternatives:

Mozilla Dev Network for HTML, CSS, JavaScript, and more
The jQuery API docs for jQuery
Comment: Your missing the } at the end `});`
Comment: Thanks :) the syntax for `fadeOut` is different, anyway.


Mean Value of Probability Distribution Function where the Integral is equals 0

Question: According to my studies,

The mean $μ_X$ of a continuous random variable $X$ with probability
density function $f_X(x)$ is $$μ_X=E(X)=\int_{-\infty}^{+\infty}x\cdot
f_X(x)$$ but we may, and often do, restrict the integral to points
where $f_X(x)>0$

References
The Probability Distribution Function I'm working out is
$$f_X(x)=x(x³-x)+2$$
where $f_X(x)$ is in the interval $[-1,1]$ and with Normalizing Constant of $15/56$.
Following the reference to obtain the Mean Value:
$$μ_X=E(X)=\frac{15}{56}\int_{-1}^{+1}x[\cdot x(x³-x)+2]$$
which is equal to 0.
I have for sure that's not the answer. And it is said that "we may, and often do, restrict the integral to points where $f_X(x)>0$".
So here is my QUESTION which interval may I use?
$$\int_{0}^{1}x[\cdot x(x³-x)+2]$$
which is equals to $\frac{11}{12}$ once the interval must be $<1$
or
$$\int_{0}^{2}x[\cdot x(x³-x)+2]$$
wich is equals to $\frac{20}{7}$ once I have to respect the distance in the interval $[-1,1]$.
Thankyou!
Comment: $f_X(x)>0$ for all $x\in [-1,1]$. You do not have to restrict the integral, and the expected value is indeed 0 (try graphing the pdf).
Comment: $f_X(x)$ is even and symmetric around $x=0$, so $E(X)=0$ is correct.  Calculation not needed.
Comment: Thankyou guys! Thats such a relief.
Answer: The sentence "we may, and often do, restrict the integral to points where $f_X(x)>0$ simply means that we can safely ignore the parts where $f_X(x)=0$ in the integral. It does not mean that the expected value cannot be zero. For example, consider the pdf of a $U(0,1)$ distribution: $$f_X(x)=\begin{cases}
1, & x\in [0,1]\\
0, & \text{otherwise}
\end{cases}$$
In this case the expected value can be calculated as $$\int _0^1x\cdot 1\,dx=0.5$$
instead of $\int _{-\infty}^\infty f_X(x)\,dx$ because $f_X(x)=0$ for any values of $x$ not in $[0,1]$.
Comment: @AJY made an edit
Comment: Shouldn't that integral be $1$, not $0.5$?
Comment: Thanks for the example. it was a great help
Answer: The expectation being zero is not a problem.
You have :
$$f(x)=\dfrac{15}{56}\cdot\begin{cases}(x^4-x^2+2)&:& -1\leqslant x\leqslant 1\\[1ex]0&:&\text{otherwise}\end{cases}$$
The reason why we may restrict the integral to the the region where the probability density function is non-zero (called its 'support') is because, by definition, elsewhere the pdf contributes zero to the overall integral.
We know for certain that these sections will integrate to zero so we may ignore them.   That the integration over the support turns out to evaluate to zero is not a problem; we just did not know it would do so without investigating.
$$\begin{align}\int_{-\infty}^\infty xf(x)\,\mathrm d x &= \int_{-\infty}^{-1}0\,\mathrm d x+\tfrac{15}{56}\int_{-1}^{1}x\cdot(x^4-x^2+2)\,\mathrm d x+\int_{1}^\infty 0\,\mathrm d x\\[1ex]&=\tfrac{15}{56}\int_{-1}^{1}(x^5-x^3+2x)\,\mathrm d x\\[1ex]&=0\end{align}$$
Comment: "because, by definition, elsewhere the pdf contributes zero to the overall integral" That's a great explanation. Thankyou!


Find area under the curve of a standard normal distribution

Question: Given a standard normal distribution, how can I find the
area under the curve that lies:
1. to the left of z = −1.39;
2. to the right of z = 1.96;
3. between z = −2.16 and z = −0.65;
Answer: The areas for one, two, and three standard deviations about the mean are well known, as .68, .95, .997 roughly. But in general, there's no way to find the area under the standard normal distribution without using a computer, calculator, or a chart.
edit1: most charts will give the area to the left of a given $z$-score. To find other values, use symmetry and complements. For example,
$\operatorname{Pr}(Z > -.5) = 1 - \operatorname{Pr}(Z < -.5)$
and
$\operatorname{Pr}(Z < - 1) = \operatorname{Pr}(Z > 1)$
edit2: I'm not careful above about whether to use "$\ge$" or "$>$" because the answers will always be the same for a continuous distribution like a normal distribution. Be careful you don't switch them around for discrete distributions because then it will affect the answer.
Comment: http://lmgtfy.com/?q=standard+normal+distribution+chart
Comment: Could you possibly provide reference to such a chart?
Answer: You can use Wolfram alpha. For example, http://www.wolframalpha.com/input/?i=1%2Fsqrt%282pi%29+integral%28e%5E%28-x%5E2%2F2%29%2Cx%2C-infinity%2C-1.39%29 answers your first question. Let me point out that your the meaning of the area under the curve to the left of $-1.39$ is the probability that a standard normal is at most $-1.39$. Make sure that you understand what you're calculating.
As GFauxPas mentions, there is no "nice" expression for the integral of the normal density function (in technical terms, it is not elementary). However, some approximations can be useful:

For small $\epsilon>0$, the probability that a standard normal is between $x$ and $x+\epsilon$ is roughly $\frac{e^{-x^2/2}}{\sqrt{2\pi}} \epsilon$.
For large $x$, the probability that a standard normal is larger than $x$ is roughly $\frac{e^{-x^2/2}}{\sqrt{2\pi}x}$. (See Mike Spivey's blog.) By symmetry, the same is true for the probability that a standard normal is smaller than $-x$.


Is possible to quickly select code and put into ie try block (VS 2010)?

Question: Suppose, I have very large foreach loop. I want put this loop into try catch block, but I do not want select by SHIFT + Arrow and cut, paste...
Comment: I've never found selecting code of any length to be a problem...
Comment: Of course the question is if it's a good idea to have such a large for each loop in the first place ;)
Answer: Add try { where you want the block to begin. As soon as you add the closing } at the end, VS will automatically re-indent the contents of the try block. I'm not sure it gets any easier than that.
Comment: PS - this is the only solution that wouldn't require you to select the code.
Answer: Select the code block you wish to surround with the try block, and press CTRL K+S (or right click, "Surround with") and type or select "try".
Comment: If it helped you, consider accepting it as answer (the checkmark at the left)


Formal power series coefficient multiplication

Question: Given that I have two formal power series:
$$ A(x) = \sum_{k \ge 0} a_k x^k $$
$$ B(x) = \sum_{k \ge 0} b_k x^k $$
The Cauchy Product gives a series
$$ C(x) = \sum_{k \ge 0} c_k x^k $$
$$ c_k  = \sum_{n=0}^k a_n b_{k-n} $$
Which comes from taking the product of the two series $C(x)=A(x)B(x)$. What then, in terms of $A(x)$ and $B(x)$, is this series?
$$Y(x) = \sum_{k \ge 0} a_k b_k x^k $$
Comment: I think you have a typo in C(x), your coefficients should be c_k.
Answer: It is known as the Hadamard product $\rm\; f \star g\;$. There is no closed form for general hadamard products, but some classes of functions are known to be closed under such products, e.g. rational power series. However, algebraic series are not generally closed under Hadamard products, the standard example being $\rm\  f = g = (1-4x)^{-1/2} \;=\; \sum \binom{2n}{n}\ x^n.\ $ However, $\rm\: f\:$ rational, $\rm\: g\:$ algebraic $\rm\;\Rightarrow\; f\star g\;$ algebraic. Also D-finite power series are closed under Hadamard products, i.e. power series satisfying a linear differential equation with polynomial coefficients or, equivalently, series whose coefficients satisfy a linear recursive equation with polynomial coefficients.
Hadamard products can also be defined in terms of diagonals of multivariate series (and vice versa), e.g. see this paper, where you'll find some interesting connections with finite automata which, e.g. help one to easily observe that algebraic series over $\rm\mathbb{F}_p$ are closed under Hadamard product (which fails in characteristic 0)
Answer: $Y$ is known as the Hadamard product of $A$ and $B$, and there is no simple way to find it from $A$ and $B$ in general.  (If you don't believe me, set $A = B = e^x$.)  The closest thing I know to a formula is (with all the analytic caveats that makes everything converge)
$$Y(r) = \frac{1}{2\pi } \int_0^{2\pi} A(e^{i \theta}) B(re^{-i \theta}) d \theta$$
which follows by Parseval's theorem.  If $A$ and $B$ are sufficiently simple (for example if they are rational functions) then it is possible to evaluate this integral, but in general there's not much you can do; $Y$ can be much more complicated than $A$ or $B$.  (Another idea is to write the above as a contour integral, and if the integrand ends up being meromorphic you can try to use the residue theorem.)
Computing Hadamard products is a special case of computing the diagonal of a two-variable generating function, a problem which I describe with a few examples here using the residue theorem.
(Of course for very special $A$ it is possible to say more, e.g. when $a_k$ is a polynomial in $k$.)
Comment: Ah; actually if one of A or B is equal to e^x then there is a way to compute Y using a slightly modified Laplace transform.  But I still don't think it gives a particularly nice answer if the other of A or B is also equal to e^x.
Answer: For more on Hadamard Products or Hadamard Multiplication Theorem look for papers by Louis R. Bragg in American Mathematical Monthly, Jan. 1999, pp 36-42 or SIAM J. Math. Anal., Vol. 17, 1986, pp 220-230 for starters.


is there a way i can generate random strings from array in vb.net without it repeating

Question: what i'm tryna to create is a program that displays a random description of a person from  an array when the form loads.
i  tried this but it keeps outputing only one string and thats RAND(1)
Public Class male
Public Property stringpass
Private Sub male_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Dim RAND(2)
    RAND(0) = "Nobody's perfect of course and Frederick has plenty of less favorable characteristics too." & Environment.NewLine & " His pompous nature and desperation tend to get in the way even at the best of times." & Environment.NewLine & "Fortunately his grace is there to relift spirits when needed."

    RAND(1) = "Animal"
    RAND(2) = "Construct"
    Label2.Text = RAND(rnd)

    Label1.Text = stringpass

End Sub

Comment: What is `rnd` here? (unrelated) `Public Property stringpass` should be  `Public Property stringpass As String`. Set `Option Strict ON`, to avoid similar problems.
Comment: What it is *supposed* to do is one thing, what it actually is matters. Where and how did you declare this (Field? Local Variable?)
Comment: Or https://stackoverflow.com/a/7258884/832052. You should use `Random` class instead of legacy `RAND` function.
Comment: rnd is supposed to generate some random value from the RAND array i guess
Comment: the stringpass variable takes an input from form 1 which is a name then it opens another form with name as label1 and some random description about the name in label2 just like "my name facts app"
Comment: You can shuffle the RAND array with https://stackoverflow.com/a/5807238/832052
Answer: Declare the Random class just once at the class level. I used a List(Of T) so you can easily add to the list without changing the dimensions of an array. The .Next method of the Random class returns a number inclusive of the first parameter and exclusive of second parameter.
You may get the strings more than once. Afterall you only have 3 choices.
Public Class male
    Public Property stringpass As String
    Private rnd As New Random

    Private Sub male_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim RAND As New List(Of String)
        RAND.Add("Nobody's perfect of course and Frederick has plenty of less favorable characteristics too." & Environment.NewLine & " His pompous nature and desperation tend to get in the way even at the best of times." & Environment.NewLine & "Fortunately his grace is there to relift spirits when needed.")
        RAND.Add("Animal")
        RAND.Add("Construct")
        Label2.Text = RAND(rnd.Next(0, RAND.Count))
        Label1.Text = stringpass
    End Sub
End Class


com.sun.istack.SAXException2: class java.util.LinkedHashMap nor any of its super class is known to this context

Question: I am sending a POST request create a resource named ContentInstance.
Resource:
ContentInstance.
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2

import java.math.BigInteger;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "stateTag",
    "creator",
    "contentInfo",
    "contentSize",
    "ontologyRef",
    "content"
})
@XmlRootElement(name = "contentInstance")
public class ContentInstance
    extends AnnounceableSubordinateResource
{

    @XmlElement(required = true)
    @XmlSchemaType(name = "nonNegativeInteger")
    protected BigInteger stateTag;
    protected String creator;
    protected String contentInfo;
    @XmlElement(required = true)
    @XmlSchemaType(name = "nonNegativeInteger")
    protected BigInteger contentSize;
    @XmlSchemaType(name = "anyURI")
    protected String ontologyRef;
    @XmlElement(required = true)
    protected Object content;

    /**
     * Getter setters         *
     */
}

I send my resource object by converting it to JSON using JAXB :
Client
     ContentInstance cont = new ContentInstance();
     cont.setContent("Sid");
     cont.setStateTag(BigInteger.ONE);
     cont.setContentSize(BigInteger.TEN);

     JAXBContext ctx = JAXBContextFactory.createContext(new Class[] {ContentInstance.class}, null);

            try
            {
                Marshaller marshaller = ctx.createMarshaller();
                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
                marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
                marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);

                StringWriter sw = new StringWriter();
                System.out.println("Object=" + object);
                marshaller.marshal(object, sw);
                String jsonContent = sw.toString();
            }
            catch (JAXBException e){

                System.out.println("--------JAXB EXCEPTION------------\n" );
                e.printStackTrace();
                LOGGER.error("JAXB marshalling error!", e);
            }

      try {

         HttpEntity entity = new ByteArrayEntity(jsonContent.getBytes("UTF-8"));
         ((HttpPost) httpUriRequest).setEntity(entity);
         System.out.println("ENTITY" + entity);

       } catch (UnsupportedEncodingException e) {
         e.printStackTrace();
       }

On service :
I retrieve the resource as Object type and I get a LinkedHashMap of the resource. I use ObjectMapper to convert this to my ContentInstance type
REST Service:
    @POST
    @Consumes({"application/json"})
    @Produces({"application/json"})
        public String handlePostRequest(Object resource) {

        System.out.println("\nINSIDE HANDLE POST: CONTENT CLASS " + resource.getClass());
        System.out.println("\nINSIDE HANDLE POST: " + resource);

        ObjectMapper objectMapper = new ObjectMapper();
        ContentInstance container = objectMapper.convertValue(resource, ContentInstance.class);
        System.out.println("\n State Tag: " + container.getStateTag() + "\nContent SIZE" + container.getContentSize() + "\nContent " + container.getContent());
        return "Dummy Data";
        }

My SOP prints:
INSIDE HANDLE POST: CONTENT CLASS class java.util.LinkedHashMap
INSIDE HANDLE POST: {stateTag=1, contentSize=10, content={type=string, value=Sid}}
State Tag: 1
Content SIZE10
Content {type=string, value=Sid}

So my SOP is prints that it get a LinkedHashMap intially and then after conversion via ObjectMapper it prints corrects data. But in request validation I get exception.
SERVER LOG:
INSIDE HANDLE POST: CONTENT CLASS class java.util.LinkedHashMap
INSIDE HANDLE POST: {stateTag=1, contentSize=10, content={type=string, value=Sid}}
WriteValueAsString {"stateTag":1,"contentSize":10,"content":{"type":"string","value":"Sid"}}
 inside processRequest
 inside validateRequest
 inside validateRequestWithXSD
10:48:31,946 ERROR [common.utils.XmlMapper] (http--192.168.105.213-8080-1) SAXException error!: org.xml.sax.SAXParseException
    at javax.xml.bind.util.JAXBSource$1.parse(JAXBSource.java:225) [jboss-jaxb-api_2.2_spec-1.0.3.Final.jar:1.0.3.Final]
    at javax.xml.bind.util.JAXBSource$1.parse(JAXBSource.java:210) [jboss-jaxb-api_2.2_spec-1.0.3.Final.jar:1.0.3.Final]
    at org.apache.xerces.jaxp.validation.ValidatorHandlerImpl.validate(ValidatorHandlerImpl.java:715)
    at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:96)
    at javax.xml.validation.Validator.validate(Validator.java:124) [rt.jar:1.7.0_40]
    at common.utils.XmlMapper.validateObject(XmlMapper.java:103) [common.jar:]
    at platform.receiverActions.requestProcedures.business.RequestValidationBean.validateRequestWithXSD(RequestValidationBean.java:77) [receiverActions.jar:]
    at platform.receiverActions.requestProcedures.business.RequestValidationBean.validateRequest(RequestValidationBean.java:33) [receiverActions.jar:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_40]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_40]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_40]
    at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_40]
    at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:202) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:306) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:32) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at platform.receiverActions.requestProcedures.business.RequestValidation$$$view15.validateRequest(Unknown Source) [receiverActions.jar:]
    at platform.receiverActions.requestProcedures.business.RequestProcessingBean.processRequest(RequestProcessingBean.java:36) [receiverActions.jar:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_40]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_40]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_40]
    at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_40]
    at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:32) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
    at platform.receiverActions.requestProcedures.business.RequestProcessing$$$view14.processRequest(Unknown Source) [receiverActions.jar:]
    at comm.http.RestHttpServlet.handleRequest(RestHttpServlet.java:221)
    at comm.http.RestHttpServlet.handlePostRequest(RestHttpServlet.java:123)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_40]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_40]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_40]
    at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_40]
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:155) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.2.Final.jar:]
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.2.Final.jar:]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
    at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_40]
Caused by: javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: class java.util.LinkedHashMap nor any of its super class is known to this context.
javax.xml.bind.JAXBException: class java.util.LinkedHashMap nor any of its super class is known to this context.]
    at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:326)
    at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:251)
    at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:102) [jboss-jaxb-api_2.2_spec-1.0.3.Final.jar:1.0.3.Final]
    at javax.xml.bind.util.JAXBSource$1.parse(JAXBSource.java:222) [jboss-jaxb-api_2.2_spec-1.0.3.Final.jar:1.0.3.Final]
    ... 117 more
Caused by: com.sun.istack.SAXException2: class java.util.LinkedHashMap nor any of its super class is known to this context.
javax.xml.bind.JAXBException: class java.util.LinkedHashMap nor any of its super class is known to this context.
    at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:250)
    at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:265)
    at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:657)
    at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:158)
    at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:356)
    at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:597)
    at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:338)
    at com.sun.xml.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBody(ArrayReferenceNodeProperty.java:118)
    at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:159)
    at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:356)
    at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:700)
    at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:158)
    at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:356)
    at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:597)
    at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:338)
    at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:498)
    at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:323)
    ... 120 more
Caused by: javax.xml.bind.JAXBException: class java.util.LinkedHashMap nor any of its super class is known to this context.
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:588)
    at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:652)
    ... 134 more

Related: Convert LinkedHashMap<String,String> to an object in Java
Comment: Do you mind adding the complete stack trace . Usually the marshaller is used to convert object to xml or json (unmarshaller is used to convert json/xml to object). So I am curious to know how and who is triggering your validation
Comment: Related: http://stackoverflow.com/questions/12105687/convert-linkedhashmapstring-string-to-an-object-in-java
Comment: Are you getting the error in request validation or response validation? (I am confused because if it was an error in the request validation it should not have hit your POST service method) or am i missing something?
Comment: I get it in Request validation. Actually the request is validated after it lands on the server.
Comment: Also did you try testing it with a Response.ok (instead of returning a String) (like in http://stackoverflow.com/questions/4687271/jax-rs-how-to-return-json-and-http-status-code-together) ..I still suspect the marshaller is trying to convert your string to  json
Comment: @Rohit: I have added the server logs. Check the edit to the question
Comment: ok -I can only guess that your request validator (which I presume to be your custom framework or application code) is not correctly determining if the content type is xml or json (and validate accordingly). To me it seems that it is trying to parse and validate your json against an XSD which is bound to fail if your input is json. Check if your common.utils.XmlMapper is called correctly (it should be invoked only for xml response) . It is also very odd to perform request validation after you return the response and exit the controller.
Comment: It seems you have 2 issues 1) The filter or interceptor that triggers your business rules (which in turn validates your request) is not setup correctly i.e. it is getting invoked after your exit the controller 2) the  RequestValidationBean is not able to detect your json input and is validating it as xml
Comment: @Rohit: The issue got resolved after using Jackson library in client too than use JAXB for my conversion to json from POJO. Check my answer
Answer: If I understand your environment set up, you are using Jackson-JAXB framework to marshal and unmarshal data-objects. Please correct me if I am wrong.
Try below these 2 options first separately and then perhaps together:

Change the type of input parameter in handlePostRequest method to String:

public String handlePostRequest(String resource) {
System.out.println("\nINSIDE HANDLE POST: " + resource);
}

Please let me know if it runs and what it prints. I suspect framework is trying to map object type to LinkedHashMap which is default mapping.

Modify the annotation tags with following:
@POST
@Produces({"application/xml", "application/json"})

@Consumes({"application/xml", "application/json"})

Answer: The issue got resolved after I used jackson library in client too for converting POJO to json rather than JAXB.
Client code now:
 ContentInstance cont = new ContentInstance();
 cont.setContent("Sid");
 cont.setStateTag(BigInteger.ONE);
 cont.setContentSize(BigInteger.TEN);

 ObjectMapper om = new ObjectMapper();
 om.setPropertyNamingStrategy(new CustomNamingStrategy());

        try {
            System.out.print("OBJECT MAPPER:---> JSON STRING" + om.writerWithDefaultPrettyPrinter().writeValueAsString(cont));
            jsonContent = om.writerWithDefaultPrettyPrinter().writeValueAsString(cont);
        } catch (JsonGenerationException e) {
            e.printStackTrace();
        } catch (JsonMappingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

The issue was my content parameter in my POJO was of type Object and JAXB was making a LinkedHashMap after converting to json, which was not provided in the JAXB context (thus the error).
Now, using ObjectMapper, content is corrrectly converted to Json.
Ex:
Earlier using JAXB content was converted to a LinkedaHashMap
content: {"type":"String", "value":"Sid"}

Using Jackson ObjectMapper:
{content: "Sid"}
Comment: Would you be able to help my question? https://stackoverflow.com/questions/58171947/jaxb-and-linkedhashmap-xml-serialization-failure

I am having the same issue but instead of serializing to JSON I am trying to serialize to XML. Thanks!
Comment: @Yaz: You could also use jackson for XML with `jackson-dataformat-xml jar` if that works for your case
Comment: The question was answered. Thanks


How to display the username in view

Question: I'm new to Drupal 7 and I have created a content revision view. For that I have added a column of author in which I have also specified the user author relationship in view.
Problem is i am creating the content type using mobile device using web services  for this created content i have content revision view in D7 here for all the content created user name displaying as admin i,e if I check the user name column in content revision column, then it shows the same admin name for all content created through multiple users, as shown in this screen print:
Answer: In advanced section add a relationship by author like this :

Then add a field, choose User:name (the user or the author name) :

make sure that you have the relationship "author" in the field setting :

Now you should see the correct author name.
Comment: yes your right:) but thing is in my case i am creating the content using mobile device using web services so whenever i create the content via mobile device the user name is taking admin
Comment: in this case you are always logged in as admin. So please modify your question and describe how you connect to your site.
Comment: i have edited the question do u know this why?
Comment: no I don't know, but it's important to offer a clear question so maybe someone else know what you mean

How to display the username in view


Tension in hand while playing tetrads (4 notes chords)

Question: I have been playing piano for 2.5 years now, and recently I started playing an arrangement for piano of "The Sugar Plum Fairy" from The Nutcracker.
Below is an excerpt from this arrangement. There are a few bars with tetrads in them.
When I try to play them I feel like I need to apply more force in order to play them as opposed to when I try to play only three notes at a time (I leave the 3rd note out).
Am I doing something wrong, or is it really physically harder (pressure-wise) to play 4 noted at once?
Answer: It is 33% harder to strike four keys than three.
If you have an acoustic piano, it's worth opening up the covers to look at the mechanism. You can see that the hammer mechanism for each key is completely independent of other keys.
The same goes for electronic keyboards, but often the mechanism is less accessible so you can see what's going on.
However you'll also get 33% more vibration, because of your extra string, which will be perceptible as loudness. The relationship between force and loudness is non-linear. The harder you strike the keys, the louder it gets, but the graph is not a straight line.
So use your ears, and get the loudness that sounds right in the context of the piece.
Answer: This question is more appropriately answerable by a private teacher or pianist friend who can watch / listen how you play and make qualified statements.
That said, it may be possible that because you are using a fourth finger (a weaker finger perhaps,) then you are trying to compensate by playing the chords more aggressively.  It could also be a psychological trigger in which you see large chords so you play aggressively.  Wind players often suffer from something similar - what we call "black note fever."
I would strongly suggest talking to a real person about this, but in the meantime you may think about playing through the chords as softly as you can, working on having all of the notes sound as evenly as possible.
Much like playing percussion (which the piano is much closer to,) volume is determined by the velocity of the strike, NOT the ferocity of the fingers.  Playing loud isn't a function of slamming the keys, but rather increasing the hammer velocity with your fingers.  Thinking about it this way can help reduce tension.
Lastly, I must suggest that the term "tetrachord" is more commonly used than "tetrad."
Answer: You want to produce roughly the same acceleration to more mass (more keys + hammer mechanisms + strings). So, yes, more force is required. C.f. Newton's Second Law of Motion.


how to differentiate this equation (contains absolute and norm)

Question: how can I differentiate the following wrt $\mathbf{d}_i$?
$\frac{|\mathbf{d}_i^T\mathbf{d}_j|}{\|\mathbf{d}_i\|_2\|\mathbf{d}_j\|_2}$
Thanks in advance.
Answer: Hints:
For $x,y \in \mathbb{R}^n$,
$$\nabla_{x} |x^Ty|= \text{sign}(|x^Ty|)y,\qquad  \nabla_{x}\|x\|_2 = \dfrac{ x }{ \|x\|_2 }, $$
So $$\nabla_x \left(\dfrac{|x^Ty|}{\|x\|_2\|y\|_2}\right) = \dfrac{\|x\|_2\nabla_{x}|x^Ty|+|x^Ty|\nabla_{x}\|x\|_2}{\|x\|_2^2\|y\|_2}=\ldots $$
Comment: $sign(|x^Ty|)$ is that correct?
Comment: @user570593 yes, for $g(t)=|f(t)|$ we have $g'(t)=\text{sign}(f(t))f'(t)= \frac{f(t)}{|f(t)|}f'(t)$ for $f(t)\neq 0$


Convergence of GANs

Question: My understanding of convergence of GANs (at least in theory) is that when the discriminator can no longer distinguish between real and fake examples the GANs have converged.  Given a real example the discriminator is only 50% sure whether it is real or fake (same for when it is given a fake) i.e. it is resorting to a coin toss!  That means that the generator has successfully "learnt" the density function so that anything it creates looks like a real example.  Is that correct? Thx.
Answer: Theoretically what you said is right, that a GAN converges only when the discriminator cannot distinguish generated image from sampled image, but you can just think about how impossible it is. Images lie in $\mathbb{R}^n$, where $n$ is at least 784 (for MNIST). Just think about it, how can you capture a distribution in $\mathbb{R}^{784}$?
In fact it has been proven that $p_{G}$ have no intersection with $p_{data}$ almost everywhere in a 2017 paper.
Empirically, GAN convergence is hard to capture because GAN loss are always vibrating. What I use is to see how the generated samples look like and that may give some sense (after a sufficiently long time, say 20 epochs). Of course it is not an ideal method, but that is currently the only way.
Answer: Your understanding seems to be based on Proposition 1 of Goodfellow et al (2014) https://arxiv.org/abs/1406.2661, that is, the optimal discriminator result
$$D_G^*(x)=\frac{{\rm p}_d(x)}{{\rm p}_d(x)+{\rm p}_g(x)}$$
where ${\rm p}_d(x)$ is the data PDF and ${\rm p}_g(x)$ is the generator output PDF. Clearly if ${\rm p}_d(x)={\rm p}_g(x)$ (almost everywhere in $x$), then $D_G^*(x)=\frac{1}{2}$, which is where the 50% figure comes from. Recent research by myself and a collaborator has shown that the optimal discriminator result requires ${\rm dim}(z)\geq{\rm dim}(x)$, that is, the dimension of the latent variable is at least equal to that of the data. This is however not the case that applies in practice: most of the time for GANs we have ${\rm dim}(z)<{\rm dim}(x)$. In this case it can be shown that the generator output PDF contains ${\rm dim}(x)-{\rm dim}(z)$ delta functions. This invalidates the application of variational calculus used in the proof of the optimal discriminator result. The proof of these claims is contained in a peer reviewed IEEE Access paper: Convergence & Optimality of low dimensional GANs.
The same paper also has a quasi-analytical counter-example for the simplest case of ${\rm dim}(z)={\rm dim}(x)=1$, i.e., a one-dimensional LSGAN, which uses a least-squares loss function. (Here quasi-analytical means that the results can be obtained to high accuracy via a simple 1-D Monte Carlo integration that does not require approximation of the expectations in the GAN loss function.) The convergence of this 1-D LSGAN generally does not achieve ${\rm p}_d(x)={\rm p}_g(x)$ with the parameters reaching a saddle point. Instead the parameters converge to a plateau where the gradients of the loss function are zero. The exact convergence point depends on initialisation, generator & data PDF and on the optimisation step size. For certain parameter values, divergence results even in this simple case. This paper has some interesting visualisations to illustrate these points.
Note that none of this invalidates the utility of GANs, but the theoretical claims need further qualification.

Convergence of GANs


Stop and Wait Link Utilization and Throughput

Question: Consider the stop-and-wait data link protocol operating over a link whose parameters are as follows: Tprop = d/v where d is the distance between transmitter and receiver in meters and v is signal propagation speed in meters per second, and Tf = L/R where L is the frame length in bits, and R is the link transmission rate in bits per second. Ignoring the Tack and Tproc , it is required to answer the following questions:
a) Plot the link utilization as a function of the link transmission, U(R) for R ϵ [0,∞).
b) Find the quantities lim 'R→ ∞' U(R) and lim 'R→ 0+' U(R).
c) Plot the link throughput in bit per second, Throbps(R) for R ϵ [0,∞).
d) Plot the link throughput in frames per second, Throfps(R) for R ϵ [0,∞).
e) Find the quantities lim 'R→ ∞' Throfps(R) and lim 'R→ 0+' Throfps(R).
The labels for all plots as well as all computed quantities should be in terms of the link parameters.
Comment: Part b) mean finding the limit (where R goes to infinity) for the function U(R); as well as part e). Thanks,
Answer: Actually I could observe how to answer the question
U(R) = (L/R) / ((L/R) + 2 Tprob)
Now:
by taking the limit:
lim 'R→ ∞' U(R) = lim 'R→ ∞' (L/R) / ((L/R) + 2 Tprob)
put R = ∞, we get:
(L/∞) / ((L/∞) + 2 Tprob) = 0 / (0+2Tprop) = 0
the same for lim 'R→ 0+'.
Also, the same for the throughput.
After we get the limits, we can plot the graph easily according to the values we get.
Regards,


How to use a Dictionary or Hashtable for LINQ query performance underneath an OData service

Question: I am very new to OData (only started on it yesterday) so please excuse me if this question is too dumb :-)
I have built a test project as a Proof of Concept for migrating our current web services to OData. For this test project, I am using Reflection Providers to expose POCO classes via OData. These POCO classes come from in-memory cache. Below is the code so far:
<code>public class DataSource
{
    public IQueryable<Category> CategoryList
    {
        get
        {
            List<Category> categoryList = GetCategoryListFromCache();
            return categoryList.AsQueryable();
        }
    }
    // below method is only required to allow navigation
    // from Category to Product via OData urls
    // eg: OData.svc/CategoryList(1)/ProductList(2) and so on
    public IQueryable<Category> ProductList
    {
        get
        {
            return null;
        }
    }
}

[DataServiceKeyAttribute("CategoryId")]
public class Category
{
    public int CategoryId { get; set; }
    public string CategoryName { get; set; }
    public List<Product> ProductList { get; set; }
}

[DataServiceKeyAttribute("ProductId")]
public class Product
{
    public int ProductId { get; set; }
    public string ProductName { get; set; }
}
</code>
To the best of my knowledge, OData is going to use LINQ behind the scenes to query these in-memory objects, ie: List in this case if somebody navigates to OData.svc/CategoryList(1)/ProductList(2) and so on.
Here is the problem though: In the real world scenario, I am looking at over 18 million records inside the cache representing over 24 different entities.
The current production web services make very good use of .NET Dictionary and Hashtable collections to ensure very fast look ups and to avoid a lot of looping. So to get to a Product having ProductID 2 under Category having CategoryID 1, the current web services just do 2 look ups, ie: first one to locate the Category and the second one to locate the Product inside the Category. Something like a btree.
I wanted to know how could I follow a similar architecture with OData where I could tell OData and LINQ to use Dictionary or Hashtables for locating records rather than looping over a Generic List?
Is it possible using Reflection Providers or I am left with no other choice but to write my custom provider for OData?
Thanks in advance.
Answer: You will need to process expression trees, so you will need at least partial IQueryable implementation over the underlying LINQ to Objects. For this you don't need a full blown custom provider though, just return you IQueryable from the propties on the context class.
In that IQueryable you would have to recognize filters on the "key" properties (.Where(p => p.ProductID = 2)) and translate that into a dictionary/hashtable lookup. Then you can use LINQ to objects to process the rest of the query.
But if the client issues a query with filter which doesn't touch the key property, it will end up doing a full scan. Although, your custom IQueryable could detect that and fail such query if you choose so.
Comment: great... any examples of this in the real odata world you have come across? i have found none on google so far
Comment: I don't know about a public sample of this. Take a look at this http://blogs.msdn.com/b/vitek/archive/2010/02/25/data-services-expressions-part-1-intro.aspx. It in itself describes the expression trees you may encounter. And there's a link there to Matt's blog series about LINQ providers in general as well.


How do I auto-reset exposed filters?

Question: I am using views along with solr search api to display search results. Within results I need to add filters so I have used views exposed filter for the indexed fields. Now that I have exposed filter I am trying to reset all views exposed filters every time when someone tries to search something in the search field.
How do I achieve this?
I am using Search: Fulltext search (exposed) exposed filter to search for keywords using views.
Answer: In exposed form settings enable reset button and give label save it you will get reset button

How do I auto-reset exposed filters?


Import error with OPENCV in Python on M1 Mac

Question: I'm trying to use OpenCV with Python but I'm continuously getting errors while importing. I'm using Anaconda virtual env and ZSH on Mac M1.
I have tried installing it using
conda install -c anaconda opencv
and pip3 install opencv-python
but I'm getting this error:
from .cv2 import * ImportError: dlopen(/Users/username/Library/Python/3.8/lib/python/site-packages/cv2/cv2.cpython-38-darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/ffmpeg/lib/libavcodec.58.dylib Referenced from: /Users/username/Library/Python/3.8/lib/python/site-packages/cv2/cv2.cpython-38-darwin.so Reason: tried: '/opt/homebrew/opt/ffmpeg/lib/libavcodec.58.dylib' (no such file), '/usr/local/lib/libavcodec.58.dylib' (no such file), '/usr/lib/libavcodec.58.dylib' (no such file)
Comment: Looks to me like it needs ffmpeg installed.
Comment: Also, you may want to review specific instructions regarding ffmpeg on m1: https://ffmpegfromzerotohero.com/blog/compile-ffmpeg-for-apple-m1-silicon/
Comment: opencv doesn't work on m1 perfectly yet. I solved the error simply by using Anaconda instead of native python distribution.
Answer: First you should make sure that ffmpeg is installed.
for me the issue was that the ffmpeg which I had installed by brew was named like ffmpeg@4 in opt/homebrew/opt/ so it couldn't find it.
I renamed the folder to ffmpeg and the issue was fixed.


Element not visible - Protractor

Question: Failed: element not visible
Estou tentado acessar um item de menu, mas está retornando como não visível. Tentei de duas formas:
var formalizationLink = element(by.id('menu7'));
browser.executeScript("arguments[0].scrollIntoView();", formalizationLink.getWebElement());
formalizationLink.click();

E também:
let formalizationLink = element(by.id("menu7"));

if (formalizationLink.isPresent()) {
  formalizationLink.click();
  browser.sleep(500);
} else {
  return false;
}

Os itens do menu acima deste estão funcionando normalmente, alguém poderia me ajudar?
Answer: Oi.
Também sou novo no protractor. Você só quer clicar no element com o ID 'menu7'?
Se for isso, pode fazer da forma mais simples:
element(by.id('menu7')).click().then(() =>{
      //Fazer alguma coisa depois do menu estiver aberto
});

Element not visible - Protractor


How do I AjaxResponse on a custom AJAX call?

Question: I have some custom Javascripts.  at the part of code I want to leverage Drupal AjaxResponse but looks like it's only working when there Triggered by Drupal Form's ajax element. ( my ajax call verb is POST)
I mean when I can this endpoint from js, I see the response in browser network, but it does not work and not applied.
Response:
[{"command":"alert","text":"just to test trigger Drupal command"}]

Route:
picture_park.preset_selector:
  path: '/admin/media/picture-park/preset-selector'
  defaults:
    _title: 'Preset Selector Picture Park images as Media'
    _controller: '\Drupal\media_entity_remote_picture_park\Controller\MediaController::presetSelector'
  requirements:
    _permission: 'Remote Image Picture Park: Create new media'

Controller method:
  public function presetSelector(): AjaxResponse
  {
    $response = new AjaxResponse();
    $response->addCommand(new AlertCommand("just to test trigger Drupal command"));

    return $response;
  }

JS:
  function postData(data) {
    return jQuery.post("/admin/media/picture-park/preset-selector?_wrapper_format=drupal_ajax", {
      "data": data,
      "js": true,
      "_drupal_ajax": 1,
    })
  }

So, what I'm looking for is, how can I make Drupal AjaxResponse runs and get executed when the endpoint is called from a custom js?
Comment: The simplest way is `Drupal.ajax({url: endpoint}).execute();` where endpoint is the URL of your Ajax controller. See https://drupal.stackexchange.com/questions/230312/how-to-trigger-existing-non-form-ajax-from-javascript-event
Comment: Thank you @4uk4. sounds feasible. how can i add payload to the request?
Comment: @4uk4 I found it. it can be done with `submit`  param. thanks for hint
Answer: You should be able to trigger the commands with the following:
ajaxObject = Drupal.ajax({
  url: "",
  base: false,
  element: false,
  // Use the 'submit' key to pass data.
  // Leave this key out if not passing any data.
  submit: {"data":"test"},
  progress: false
});

// Trigger ajax commands.
ajaxObject.success(data, "success");

Add the above to a success callback of your Ajax response. Note you may also need to add the following to process any Ajax inserted content:
Drupal.attachBehaviors();

Comment: Thank you!.
how request payload set? I didn't find data in `Drupa.ajax` . sounds like it needs `Ajax. options` to pass data.?
Comment: I found it.
it's with `submit` key.


How to align SQL result set in tree structure hierarchy

Question: I have 4 result sets that need to form tree structure hierarchy as follows:
Result sets:

College
HeadOfDepartment
Teacher
Student

Now the hierarchy should be as follows:
College1
   HeadOfDepartment1
       Teacher1
           Student1
           Student2
       Teacher2
           Student3
   HeadOfDepartment2
       Teacher3
           Student4
           Student5
       Teacher4
           Student6
College2
............

What is the feasible solution to form this hierarchy?
 I have tried row_number() over the corresponding group to sort.
Sample Data
ObjectID    Stream      Category    University  Percentage  Subject
College1    Engineering             University1
College2    Medical                 University2
                    ObjectID        Stream      Category    University  Percentage  Subject
Belongs to College1 HOD1        Management
Belongs to College1 HOD2        Technical

                ObjectID    Stream  Category    University  Percentage  Subject
Belongs to HOD1 Teacher1                                                SQL
Belongs to HOD2 Teacher2                                                Java

                    ObjectID    Stream  Category    University  Percentage  Subject
Belongs to Teacher1 Student1                                            90  SQL
Belongs to Teacher2 Student2                                            80  Hibernate

Desired Output :
ObjectID    Stream      Category       University   Percentage  Subject
College1    Engineering                University1
HOD1        Management
Teacher1                                                        SQL
Student1                                            90          SQL
HOD2        Technical
Teacher2                                                        Java
Student2                                            80          Hibernate
College2    Medical                    University2

Comment: I think SQL can never give you the result in hierarchy. So what is your expected output in tabular format.
Comment: yup, in a tabular format!
Comment: added sample data and desired output..couldn't format the resultset :(
Comment: Thanks for formatting my query! I hope sample data and desired output are giving some understanding for you people to guide my query.
Comment: Your sample data and desired output is unclear and unreadable - Please format your sample data and desired output with [Format Text as Table](https://senseful.github.io/text-table/) -HTH ;).
Comment: was away for few days and I formatted in a possible way now.
Answer: A way with using union all is:
;with combination as (
    -- Colleges
    select cast(id as char(5)) id,
        [name]
    from College
    union all
    -- HeadOfDepartments
    select cast(CollegeId as char(5)) + cast(id as char(5))
        , '    ' + [name]
    from HeadOfDepartment
    union all
    -- Teachers
    select cast(h.CollegeId as char(5)) + cast(h.id as char(5)) + cast(t.id as char(5))
        , '        ' + t.[name]
    from Teacher t
    join HeadOfDepartment h
      on t.HeadOfDepartmentId = h.id
    union all
    -- Students
    select cast(h.CollegeId as char(5)) + cast(h.id as char(5)) + cast(t.id as char(5)) + cast(s.id as char(5))
        , '            ' + s.[name]
    from Student s
    join Teacher t
      on s.TeacherId = t.id
    join HeadOfDepartment h
      on t.HeadOfDepartmentId = h.id
)
select [name]
from combination
order by id;

SQL Fiddle Demo


Finding distance using rates of change -- best approach?

Question: The question:
A man drives from state $A$ to state $B$ going $60 \frac{miles}{hour}$. Then he returns from state $B$ to state $A$, driving $45 \frac{miles}{hour}$. His total driving time is $2.5 hour$. How many miles is the distance from state $A$ to state $B$?

Possible solution:
Using $distance = rate \times time$, we observe
$d=60 \frac{miles}{hour} \times p (2.5 hour)$,
where $p$ denotes the proportion of time driving from $A$ to $B$, and
$d=45 \frac{miles}{hour} \times (1-p) (2.5 hour)$.
Solving these two equations,
\begin{align*}
60 \frac{miles}{hour} \times p (2.5 hour)&=45 \frac{miles}{hour} \times (1-p) (2.5 hour) \\
150p miles &= (112.5-112.5p) miles \\
262.5p miles &= 112.5 miles \\
p&= \frac{112.5}{262.5}
\end{align*}
Now we solve
$d=60 \frac{miles}{hour} \times p (2.5 hour) \approx 64 miles $.

It works, but maybe isn't the most time-efficient approach during a GRE exam where you should spend less than a minute on a given question. When practicing and timing myself, this is the approach I started with, decided to skip it, and never had time to come back to it until after my time was up. Is this how you would solve this question, or is there a more straightforward and faster approach?
P.S. I notice we're talking about rates of change and determining the total change -- could this problem be expressed differently and solved using calculus in a faster way?
Trying to get faster and appreciate your advice!
Answer: Let the one way distance be $d$. Then ${ d \over 60} + {d \over 45} = { 5 \over 2}$.
Then $d = { { 5 \over 2} \over { 1 \over 60} + {1 \over 45}} = { 450 \over 7} \approx 64.29$.
Comment: Awesome. How did you come up with that construction? Is this considered a "combined work" problem?
Comment: Ah. This is simply $t_1+t_2=2.5$. Then, using $d=r_1\times t_1$ and $d=r_2 \times t_2$, the first equation can be rewritten as $\frac{d}{r_1}+\frac{d}{r_2}=2.5$, or $\frac{d}{60}+\frac{d}{45}=2.5$. Thank you for your help.


How to assign primitive data types to custom classes directly in java

Question: How do I create a wrapper class for a primitive data type such as int, boolean, and String?
I want to create my own classes that handle these types easier for when I'm doing my java projects.
    AltString s = "Hello world";

As opposed to calling the constructor:
    AltString s = new AltString("Hello world");

Answer: You can't. Java doesn't allow you to define custom conversion operators (or indeed any operators).
(You can certainly create your own wrapper classes, but you can't make the assignment work the way you want.)
As a side-note, String isn't a primitive type. From the Java Language Specification section 4.2:

PrimitiveType:
    NumericType
    boolean

NumericType:
    IntegralType
    FloatingPointType

IntegralType: one of
   byte short int long char

FloatingPointType: one of
    float double

Comment: also it should be noted that Strings aren't really primitive data types, they're Objects. they're just so commonly used that the designers allowed us to create them without having to call a constructor
Comment: @JeffHawthorne: True - will note that.
Comment: Thanks. Kind of hoping it wouldn't be that way, but that makes sense as well.
Answer: You can't overload operators in Java


how to study a distribution that is not identically distributed?

Question: My distribution histogram looks like it is not identically distributed, as in the negative counts have a different shape than the positive counts. Here is an image:

The chart has 800 data points, and the tallest count of 40 is for 0.
I don't know a formal approach, but looking at it, it appears to me it is not identically distributed. My guess is that the negative counts (to the left of 0) are closer to a normal distribution, while the positive counts (to the right of 0) are closer to a Laplace distribution, or have higher kurtosis than the left side.
Is this possible, are there cases where this happens, is there a topic in probability that studies it? Or, is this just my eyes playing tricks on me, or not having enough sample data or some other simple reason?
Thanks in advance for any help.
Comment: Do you mean *symmetrically* instead of *indentically*?
Comment: "Identically distributed" is a standard term in probability theory, and its meaning in standard usage is not at all what seems to be meant by it here.  Two or more random variables are identically distributed if they have the same distribution.  That has nothing to do with what's being asked about in this problem.
Comment: dl, "shape parameters" are used to describe changes, such as "skewness", in a family of distributions other than those generated by "location" or "scale" parameters. See wikipedia (http://en.wikipedia.org/wiki/Shape_parameter) for some examples of families with a shape parameter. Your distribution actually looks like a product of two normal distributions with different means, like $N(-1,1)\cdot N(1,1)$.
Comment: Thank you cardinal and Mr Hardy for your comments, I was using the wrong term. I think "symmetrically" is closer to my meaning.
Comment: Thank you B R, I think your comment points me in the right direction. I wish I could mark it as the accepted answer.
Comment: I can do that!${}$
Answer: "Shape parameters" are used to describe changes, such as "skewness", in a family of distributions other than those generated by "location" or "scale" parameters. There are many examples of distributions with shape parameters. Your distribution actually looks like a product of two normal distributions with different means, like $N(−1,1)⋅N(1,1)$.
Answer: As @cardinal wrote, you probably don't mean "identically distributed": that's something you can't really tell from a histogram.  If you want to test whether this is a normal distribution, you might use a D'Agostino-Pearson test, a Shapiro-Wilk test, or a Kolmogorov-Smirnov test.  See e.g. http://www.graphpad.com/faq/viewfaq.cfm?faq=959 and references there.
Comment: Yes, of course it can.  The only requirements on a PDF are that it is nonnegative everywhere and its integral over the real line is $1$.
Comment: Thank you for the comments and guidance, I suppose I should rephrase the question as:  Can a distribution have 2 different PDF formulas for the right and left side, or different shape parameters?


Intel Parallel Studio use only 2GB RAM

Question: I have large project and I want to debug it with IPS (Inspector). But my project by default eat about 1 Gb RAM and with Inspector it try to eat more then 2Gb RAM. So, I have 16 Gb RAM installed but when Inspector eat more then 2 GB of them it stops debugging and say what memory limit was exceeded. How I can increase memory limit for Intel Inspector?
Comment: Are you working on a Windows 32 bit system?
Comment: x64 but my application is x32
Answer: 32-bit systems can address up to 2GB of memory per process (technically 2^31), regardless of how much memory exists in the system, so perhaps this is the reason your process never exceeds that limit.
In addition, even if your computer system is 64-bit, it's possible your process is itself 32-bit. In this case, the same thing as above applies. You'd need to recompile your application in x64 to be able to take advantage of the extra memory available in your system.
Comment: Technically, if you link with `LARGEADDRESSAWARE`, a x64 application can use more than 2GB, but not quite up to 4GB. (And 3GB in a 32-bit OS when enabling 3GB user-space)
Comment: @MatsPetersson: Thanks, good point. I think you meant to say x86 application though.
Comment: well, I meant "a 32-bit application on a 64-bit OS".
Comment: djikay answer is accurate. If your 32bit app is already consuming more than 1 Gb of RAM, then you will be much closer to 2 Gb boundary with Inspector XE. In such cases the "official answer" from Inspector XE forums would mostly always be - consider recompiling your application for x64. While on Windows Inspector XE GUI is 32bits process, it's perfectly and seamlessly capable of profiling/dispatching both 32bits and 64bits target applications

Intel Parallel Studio use only 2GB RAM


How to set min and max replicas for deployment level?

Question: Can we set min and max limit for deployments at deployment level, not at cluster or replica set level in kubernetes ?
Comment: This setting here would be obvious: `kubectl explain deployment.spec.replicas`, but I suspect that is not what you mean.
Answer: On deployment level it is not possible, but there is an option to do this indirectly. You should use a HorizontalPodAutoscaler (HPA for short):

HPA automatically updates a workload resource (such as a Deployment or
StatefulSet), with the aim of automatically scaling the workload to
match demand.

Example code for HPA:
<code>apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: php-apache
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache
  minReplicas: 1
  maxReplicas: 10
</code>
More information can be found in Kubernetes documentation.
Answer: At deployment level only replicas attribute is there.  When you define hpa there is an option for min and max


website resize differently on different platforms

Question: I am making a website using Masonry and Magnific Popup. My goal is to make this web site responsive on different devices.
I have resized the browser on desktop to preview it, it resize very well on desktop. But the actual look in my phone is very different.
What it looks like in a resized browser:

What it looks like on iPhone:
What it looks like in iphone http://media-cache-cd0.pinimg.com/736x/f3/86/9b/f3869b476e6fc31338965a2f6689aa02.jpg
It looks like the whole layout got shift to the left in the phone.The similar problem also occurs in ipad/mini.
Any advises are deeply appreciated.
Comment: Its time to learn a responsive CSS framework, try Bootstrap or Foundation.
Comment: You need to post your code. And whilst Bootstrap and Foundation are great resources, there is nothing wrong with trying to use pure css to deal with responsiveness.
Answer: Right now, the YouTube video is messing up the page width. Try adding some jQuery to make the youtube width responsive, for example:
<code>  $('iframe').attr('width',$( window ).width());
  $('iframe').attr('height',$( window ).height());
</code>
But seriously, this won't solve everything down the line. You should learn Foundation or Bootstrap.


Replace assignment with deferred assignment

Question: In my angular.js page I extend $scope with all attributes I need.
Before, I simply extended $scope with
angular.extend($scope,{
    myAttr : aService.getValues()
});

However, turns out I have to add a promise (angular file access) to aService.getValues. Hence, I cant keep the above syntax but have to replace it with
angular.extend($scope,{
myAttr : null
});
aService.getValues().then(function(values){$scope.myAttr = values;})

That's annoying because I have to replace quite a bit of code and am afraid to add bugs. Any alternatives?
Answer: The only thing I can suggest is a slightly prettier re-doing of your own solution:
aService.getValues().then(function(values) {
  angular.extend($scope, {
    myAttr: values
  })
});

Is it critical that $scope is extended synchronously? If it is, I don't see any way of feeding asynchronous data into it any other way.
EDIT
If you're reworking your logic, consider using $stateProvider with a resolve property: https://github.com/angular-ui/ui-router/wiki (Scroll down to the section that talks about resolve). Long story short, everything in the resolve must run before the state controller is initialized. This way you can do all your async operations in the resolve, and only let it load after you have everything you need.
Comment: It is a key to initialize my whole view controller. I believe I will have to reshuffle the init logic in the controller then. Thanks for re-doing the code, looks better now :)
Comment: Added a suggested fix.
Comment: Oh great, that makes sense. However, is that applicable in the controler where I could assign values to $scope.myAttr ?
Comment: Well, yes, I think -- if I'm understanding you correctly, yes. The `resolve` should not be in the controller, but rather your config file (aka where you do `angular.module('myApp').config()...run()`). The code in the resolve will run before the controller initializes.


Proving that a proposition is a tautology

Question: I did it but I am not sure that I solved it in the right way...
[I tried to solve that $((p \lor q) \land (\lnot p \lor r)) \to (q \lor r)$]
Comment: When you have $((p \wedge \neg r) \vee r) \vee q$ inbetween lines 8 and 9, you should be careful about just dropping parentheses. The $\vee$ operation distributes over parentheses (https://en.wikipedia.org/wiki/Distributive_property#Propositional_logic), so you should have something like $((p \vee r) \wedge (\neg r \vee r)) \vee q$
Answer: Almost good: you need to keep parenthesis in the line "DeMorgan's laws" because in general $(A \land B) \lor C \neq A \land (B \lor C)$ (for example when $A=B=0, C=1$), so the last five lines are not valid.
Two faster ways to do the exercise:

if $P=0$ then the proposition becomes $Q \Rightarrow Q \lor R$ which is true; if $P=1$ then the proposition becomes $R \Rightarrow Q \lor R$ which is true again, so the original proposition is true;
use the implication rule for the outer implication to obtain
$$(\lnot[(p \lor q) \land (\lnot p \lor r)])\lor(q \lor r)$$
$$[\lnot p \land \lnot q] \lor [p \land \lnot r] \lor q \lor r$$
Now notice that $(A \land \lnot B) \lor B = A \lor B$, so we obtain
$$([\lnot p \land \lnot q] \lor q) \lor([p \land \lnot r] \lor r)$$
$$\lnot p \lor  q \lor p \lor r$$


How to calculate the power of my quantile regression model?

Question: I have a quantile regression model that I fit with the rq() function in the quantreg package in R.
However, since my sample size if fairly small (n = 36) compared to  the number of X variables (= 8), I need to estimate power for the various regression coefficients. How can I do that?
It would be great to be pointed to a function in R that can do that for a quantreg model, but a general explanation of how to calculate power in such a model would be fine as well (I can then code that in R myself).
How can I determine the power for a given quantile regression model with a given dataset?
Comment: Simulation is the way
Comment: You shouldn't really calculate power *post-hoc*. That's because the point estimate of the study is within a range of the "truth" ($\pm$ some variability), and the upper limit of the 95% CI will almost always tell you your study is adequately powered while the lower limit will almost always not. However +1 because there's a lot of curiosity on the power of quantile regression.
Comment: I've seen some work of an earnest MS student on the topic. They authored an R package (not on CRAN) here https://rdrr.io/github/tnt198785/rqsamplesize/
Answer: Sorry, I don't know what you say clearly. If you want to compare different rq model with different variable that which is better, AIC and BIC
are common ways, no matter what your regression model is.
In R:
fit1 <- rq(...)
fit2 <- rq(...)
AIC(fit1)
AIC(fit2)

BIC(fit1)
BIC(fit2)

## briefly
AIC(fit1, fit2)
BIC(fit1, fit2)

And if you want to check which variable is more important to effect the results(feature selection), I have no idea about so.
Comment: Thanks, I appreciate your effort. What I am after is a way to approximate the probability of detecting a "true" effect when it exists, given my dataset and the set of X's in my quantile regression model. So, with the specific data that I am working with (and its limited size) and some choice of variables in the quantile regression, what would be the power to find a true effect for a coefficient, if it exists?


Lease table is not updated when new shards are added causing stale workers in KCL

Question: I am using the amazon-kclpy version "2.1.3" (the python library that uses the MultiLangDaemon).
According to aws docs (here) when I add new shards for my stream or when a new worker (pod in Kubernetes in my case) starts up a resharding event should occur.
Following the resharding I should see new records in my lease table.
However, in both cases, I do not see any new records in the lease table making the new workers added to be stale and go into a sleep cycle...
<code>2023-12-24 17:46:34,750 [multi-lang-daemon-0000] INFO  s.a.kinesis.coordinator.Scheduler [NONE] - Initializing LeaseCoordinator attempt 1
2023-12-24 17:46:37,860 [multi-lang-daemon-0000] INFO  s.a.k.leases.LeaseCleanupManager [NONE] - Starting lease cleanup thread.
2023-12-24 17:46:37,861 [multi-lang-daemon-0000] INFO  s.a.kinesis.coordinator.Scheduler [NONE] - Starting LeaseCoordinator
2023-12-24 17:46:37,861 [pool-15-thread-1] INFO  s.a.k.leases.LeaseCleanupManager [NONE] - Number of pending leases to clean before the scan : 0
2023-12-24 17:46:37,926 [multi-lang-daemon-0000] INFO  s.a.kinesis.coordinator.Scheduler [NONE] - Scheduling periodicShardSync
2023-12-24 17:46:37,928 [multi-lang-daemon-0000] INFO  s.a.kinesis.coordinator.Scheduler [NONE] - Initialization complete. Starting worker loop.
2023-12-24 17:46:38,026 [multi-lang-daemon-0000] INFO  s.a.k.c.DeterministicShuffleShardSyncLeaderDecider [NONE] - Elected leaders: fe86945c-96d7-423e-a157-97c5c6ad6f79
2023-12-24 17:47:05,036 [multi-lang-daemon-0000] INFO  s.a.k.c.DiagnosticEventLogger [NONE] - Current thread pool executor state: ExecutorStateEvent(executorName=SchedulerThreadPoolExecutor, currentQueueSize=0, activeThreads=0, coreThreads=0, leasesOwned=0, largestPoolSize=0, maximumPoolSize=2147483647)
2023-12-24 17:47:35,044 [multi-lang-daemon-0000] INFO  s.a.kinesis.coordinator.Scheduler [NONE] - No activities assigned
2023-12-24 17:47:35,045 [multi-lang-daemon-0000] INFO  s.a.k.c.DiagnosticEventLogger [NONE] - Current thread pool executor state: ExecutorStateEvent(executorName=SchedulerThreadPoolExecutor, currentQueueSize=0, activeThreads=0, coreThreads=0, leasesOwned=0, largestPoolSize=0, maximumPoolSize=2147483647)
2023-12-24 17:47:35,045 [multi-lang-daemon-0000] INFO  s.a.kinesis.coordinator.Scheduler [NONE] - Sleeping ...
</code>
I am not sure what I am missing in order to cause new pods to be assigned with those new shards so the pods will actually process records.
Is this a permission issue? maybe something with the python code?
Answer: I cannot say the source of the issue, but I saw the issue stopped once I replaced the worker_id attribute in the properties file with the pod name (the properties file that is read as part of the KCL run command).


Is it true that currently we cannot compute p-values or confidence intervals for the coefficients from a Lasso regression problem?

Question: I found a textbook online that had the following to say regarding the Lasso,

"Computing the p-values or confidence intervals for the coefficients of a model fitted with lasso, remains an open problem."

Why is it that currently inference on the coefficients is not possible? Is it that structurally the variance of the coefficient estimators have no closed form? Or is it something else?
Comment: Permutation testing? Bootstrap?
Comment: Does this answer your question: [How to obtain Confidence Intervals for a LASSO regression?](https://stats.stackexchange.com/questions/402267/how-to-obtain-confidence-intervals-for-a-lasso-regression)
Comment: https://projecteuclid.org/journals/annals-of-statistics/volume-42/issue-2/A-significance-test-for-the-lasso/10.1214/13-AOS1175.full (alternatively https://arxiv.org/abs/1301.7161)
Answer:
Why is it that currently inference on the coefficients is not possible? Is it that structurally the variance of the coefficient estimators have no closed form? Or is it something else?

Prior to some work in the area of selective inference, the bias in the estimates of the coefficients complicated the theory for testing coefficients.  What's more, there may (or may not have, I can't recall) been some theory for fixed regularization strength, but we almost always estimate the regularization strength from the data, which further added to the complexity.
Around 2014/2015, work started to come out on selective inference which provided some theoretical grounding on how to do inference on penalized models such as LASSO. I'm not sure if it is very mainstream as of yet, I haven't seen it be used often, but it is an active area of research.
Comment: If you run a Bayesian _lasso_ (or any other penalized regression) you automatically get the full inference machine.  Posterior distributions are interpreted as simply as if there were no penalization.  It's the frequentist setting in which things are very complicated.
Comment: @FrankHarrell Makes a good point (though it should be mentioned that the posterior medians correspond to the estimate resulting from a LASSO).  However, doing a Bayesian sort of Lasso would require some intuition on the variance of the priors, which correspond to the regularizing strength.
Comment: The intuition required to specify the scaling factor for the priors is exactly the same challenge of finding the value of the lasso penalty factor $\lambda$.
Comment: @FrankHarrell I'm not sure I follow. Cross validation is usually the method for selecting the lambda, where as either prior knowledge or prior predictive checks are the method for determining the scaling factor. How are these equivalent?
Comment: The scale factor on the Laplace prior for the Bayesian lasso is exactly the reciprocal of lasso's $\lambda$.   The question is how do you solve for $\lambda$ with _lasso_ or how do you select/pre-specify $\lambda$ for Bayes.
Answer: Confidence intervals are a frequentist measure of uncertainty.
The researcher determines a population parameter of interest (say average income in a country) that they want to learn.
Then, the researcher collects a random sample from the population and feeds this data into a formula that puts out an interval. The formula is designed so that, if it is applied to a random sample, it yields an interval that covers the true population parameter with a fixed probability - say 95%. In other words, before the researcher collects the data they anticipate that in 95% of cases they will collect a sample on which they will compute a confidence interval that covers the true parameter.
Translating this idea to LASSO regression, one may declare the "true values" of the estimated non-zero coefficients to be the parameters of interest. In this case, the justification above does not go through since parameter selection is a property of the data sample, i.e., the researcher does not know what the parameters of interest are before they collect the data sample.
The framework of conditional inference provides a way of translating the idea of a confidence interval to scenarios where the parameters of interest depend on the data. This is not a strategy for computing traditional confidence intervals. This is a strategy for computing something that is similar to confidence intervals. The interpretation and justification is slightly different though and, as pointed out by in the answer by Pananos, not familiar to most practitioners.
I also want to note that in many applications of LASSO regression it is not really meaningful to compute any kind measure of significance for the estimated coefficients since the coefficients do not (and are not meant to) have any kind of interpretation as population parameters. In pure prediction excercises, the researcher is only interested in computing good predictive values and very different configurations of parameter values will give similar predicted values. To assess the predictive power of the estimated model one would typically assess the properties of the predicted values (e.g. via out-of-sample error), not "significance" of the estimated coefficients.
Lastly, if it is known that e.g. out of 100 variables 90 have a zero coefficient and the others have "sufficiently large" coefficients (we don't know which ones!) then it can be shown that the Lasso selects the 10 variables with non-zero coefficients with probability one if the sample size is sufficiently large. In this case, fitting a normal OLS ("post Lasso) using only the variables selected by the Lasso will yield valid confidence intervals.
Comment: Regarding your last paragraph, what about the inconsistency of LASSO as opposed to consistency of the adaptive LASSO w.r.t. variable selection?


How can I show just distinct names (from my model) in my view?

Question: Problem
How can I return back just the distinct names in my view? I can't cast the string returned by my distinct() method back to an Inumerable object.
For simplification, if you see a person named John Smith in the database, we assume all quotes from John Smith are from the same person.
Code
Data
id                name          quote
1                 Finn          Mathematical
2                 Jake          Aw, man!
3                 Shredder      Tonight, I dine on turtle soup.
4                 Shredder      Nooooo

Model
    namespace Quotes_Sample.Models
{
    public class QuoteDB
    {

        public int Id { get; set; }
        public string name { get; set; }
        public string quote { get; set; }
        public bool IsSelected { get; set; }

    }

    public class QuoteDBContext : DbContext
    {
        public DbSet<QuoteDB> Quotes { get; set; }
    }

}

Controller
 private QuoteDBContext db = new QuoteDBContext();

    // GET: Quotes
    public ActionResult Index()
    {
        return View(db.Quotes.ToList());
    }

View
@model IEnumerable<Quotes_Sample.Models.QuoteDB>

@{
    Layout = null;
}

<!DOCTYPE html>

    <meta name="viewport" content="width=device-width" />
    <title>Index</title>

        @Html.ActionLink("Create New", "Create")

    @using (Html.BeginForm("SubmitSelected", "Quotes", FormMethod.Post, new { encType = "multipart/form-data", name="myform"}))
    {

                   @Html.DisplayNameFor(model => model.name)

            @foreach (var item in (IEnumerable<Quotes_Sample.Models.QuoteDB>)Model.Select(x => x.name).Distinct())
            {

                        @Html.DisplayFor(modelItem => item.name)

            }

    }

Error
An exception of type 'System.InvalidCastException' occurred in App_Web_cied5w21.dll but was not handled in user code
Additional information: Unable to cast object of type '<DistinctIterator>d__81`1[System.String]' to type 'System.Collections.Generic.IEnumerable`1[Quotes_Sample.Models.QuoteDB]'.

Attempts

I can just remove the casting and have duplicates, but it's really
ugly.
I thought about writing a temp variable that remembers last
name in loop, if same it breaks. That is just plain gross? Seems hacky too.
Just having 1 name to 1 quote relationship in my database, but that avoids the problem completely.
This, which actually brought me to this problem.
This below:

           @Html.DisplayNameFor(model => model.name)

    @foreach (string name in Model.Select(x => x.name).Distinct())
    {

                @Html.DisplayText(name);

    }

But that really weirds me out. It gives me the following:
name

;
;
;

Thanks for your patience and assistance.
Comment: Your issue is when you you call `Model.Select(x => x.name)`, the concept of the `QuoteDB` object is lost - you now have an `IEnumerable`
Comment: @Jonesy Right, I was investigating the error and you can see my attempt to fix it, but still getting bizarre output?
Comment: Also, if you achieve `IEnumerable` with distinct names, what quote value would you expect Shredder to have?  I think you're looking for `GroupBy`.
Answer: You can get Distinct records by name using:
Model.GroupBy(x => x.name).Select(x => x.First())

But you should do this in your Controller, not View.
Also you can use DistinctBy method:
Model.DistinctBy(x => x.name)

Comment: This worked. Please, one more comment. Is the reason this logic belongs in the controller for two reasons. 1. Controller handles the data then passes to view by definition. 2. It would be sluggish and nasty to do it in a view.
Comment: the purpose of View is displaying the data, all other stuff (filtering, projecting etc.) should be done in Contoller.
Comment: Sanity check here. By model, you mean QuoteDBContext db, yes?
Comment: no it's the ViewModel but ofcourse you need  to use your DbContext if you are gonna do this in your controller


Prove that for every prime number $p>3$, $4p^2+1$ can be written as the sum of three square numbers

Question: Given that $p>3$ prove that $4p^2+1$ can be written as the sum of three distinct positive square numbers.
Plugging in $5$ I get $101=49+36+16=7^2+6^2+4^2$
I also know that all primes greater than $3$ can be written in the form $3k+1$ and $3k+2$ but plugging those values in I get:
$36k^2+24k+5$,  $36k^2+48k+17$ and the solution probably lies in arranging these numbers in such a way that we get the desired squares, but I can't come up with a combination ,or is my "idea" not even in the right direction?
Comment: Unfortunately, "natural numbers" in some places includes $0$, so you should said "positive integers" to be clear.
Comment: It looks to me like $2p$, $1$ and $0$ will work for any $p$.
Comment: I assume one of them must be nonzero?
Comment: yes $p$ can only be a prime EDIT: it says so in the title
Comment: only natural numbers forgot to add that part
Comment: Oops will delete last comment.
Answer: We know that $p=6n\pm1$. Here
$$
4(6n-1)^2+1=144n^2-48n+5=(8n-1)^2+(8n-2)^2+(4n)^2.
$$
You figure out what changes are needed to do the case with plus signs.
Comment: In other words, $p$ being a prime number plays no real role. Any integer congruent to $\pm1\pmod6$ will do. I suspected as much, as it is a bit difficult to see how primeness of $p$ would be used.
Answer: If $p=6k\pm 1$ then $4p^2+1 = 144k^2\pm 48k +5$.
So you might want to write $$4p^2+1 = (ak+1)^2+(bk+2)^2+(ck)^2=(a^2+b^2+c^2)k^2+(2a+4b)k+5$$
So you need to find $a,b,c$ so that $a^2+b^2+c^2=144, a+2b=\pm 24$, and $c\neq 0$.
I'll leave it to you to solve for $a,b,c$.
But you might get a quess of what they are by looking at the case $p=7$ along with your solution for $p=5:$
$$4\cdot 7^2+1 = 9^2+10^2+4^4$$