Plain old singleton or spring singleton bean?

Question: I have a service in my application which is a singleton.
My application is being bloated with the use of spring framework.
I am confused over to use the singleton service as
1: Plain Old Singleton [Access them statically when required]
OR as a
2: Spring singleton bean. [Use DI to inject when required]
Which approach is correct ?
Answer: The Spring singleton scope is not the same as the Singleton design pattern, which is not the same as a class with static methods.
From the documentation
"Please be aware that Spring's concept of a singleton bean is quite different from the Singleton pattern as defined in the seminal Gang of Four (GoF) patterns book. The GoF Singleton hardcodes the scope of an object such that one and only one instance of a particular class will ever be created per ClassLoader. The scope of the Spring singleton is best described as per container and per bean. This means that if you define one bean for a particular class in a single Spring container, then the Spring container will create one and only one instance of the class defined by that bean definition."
Also, note you need to be very careful using a Spring singleton as a service that web requests will utilize.  Since each request is on its own thread, you can have threading issues if your singleton maintains any state.
To answer your question: Create a class that implements an interface, and use Spring to DI it appropriately.  If your service does not maintain state, you can scope it to singleton, otherwise you can scope it to prototype.
Comment: My service has no state except static reference. The spring is being used only to manage the inter BO relationships. The argument is going on to use it in other layers based on [need for managing the complex object dependencies]. Some designers think that Spring  DI does not provide advantage since there are not complex inter object dependencies in those layers.
Comment: Spring is not just about DI.  It is about IoC as well.  And it does a lot for you.  For example, you want transactions around your services right?
Comment: K in which scenarios the first approach is preferred ?
Comment: @snake using a singleton as a service is never preferred.  sometimes classes with only static methods on them are used as helpers/utilities.
Comment: @hvgotcodes Can you please explain why using a singleton as a service is never preferred. We have many services designed that way.
Comment: there is no need for it, for starters.  Use a singleton when you need to limit the number of objects of a type to 1.  Services do not need to be limited in this way.  No need to put an abstraction around service access -- its over engineering and gets you nothing.  Plus, a class with static methods is not a singleton.  So if you intended to use the singleton pattern, you didn't do it correctly.
Comment: @snake furthermore, by using a class with static methods as a service, you lose the ability to use a lot of the OO features of java in your services.  For example you can't have an abstract service implementing an interface, with a chain of service implementations underneath that.
Comment: @hvgotcodes  I think you misunderstood me. Please let me clarify,
Comment: @hvgotcodes The singleton service do not have static methods, only public methods that process input(parameters to method)  and return only output produced using inputs. The singleton service has no state and only a static reference to other class to which further processing will be delegated to get the response.
The reason behind singleton is - there will be only 1 instance of service that the invokers will use in whole application. I hope this will make things clear.
Comment: @snake i thought your option 1 read otherwise.  My advise is still, if you are using spring, just use spring for everything you can.  It is good at everything it does.
Answer: I use Spring's beans whenever possible. The framework was designed to manage these things, and it is probably better than me at it. Another reason to use Spring's dependency injection is the possibility to unit-test with mocks instead of the real utility code, thus focusing the unit-test to the exact scope.
EDIT:
To answer the question in the comment, the only case I can think of for a non-bean singleton would be a utility code class, which would contain short pieces of generally reusable code in public static methods. Anything else requires instantiation, and therefore - a bean.
Comment: K in which scenarios the first approach is preferred ?


Find the solution set of $\lfloor{2x+3}\rfloor\leq8$ inequality.

Question: The question is easy,
Find the solution set of $\lfloor{2x+3}\rfloor\leq8$ inequality.
$$\lfloor{2x+3}\rfloor\leq8$$
$$\lfloor2x\rfloor+3\leq8$$
$$\lfloor2x\rfloor\leq5$$
$$2x<6$$
$$x<3$$
$$(-\infty,3)$$
In this solution, I could not unserstand how $\lfloor2x\rfloor\leq5\Rightarrow2x<6$. Can you explain to me, please?
Edit: $2x\leq6$ changed to $2x<6$ with $x\leq3$ to $x<3$.
Comment: What definition are you using for $[ \cdot ]$? There are three different definitions I often see: greatest integer, least integer, and nearest integer.
Comment: It should be **greatest integer**. I am also editing the question. Thanks!
Comment: It might also be noteworthy that the solution is wrong: for example, take $x=-10$. Then $|2x+3| = |-19| = 19$ but $19$ is greater than $8$.
Comment: Sorry, you are right. I edited the question, you can look at it again.
Comment: @HAMIDINESOUMARE Post an answer to my question. I will accept it, you have solved it. Also, sorry for misunderstand the correct typing of greatest integer with $[|.|]$ this showed in my textbook. We use this typing for it. But, I learned how to type it correct. Thanks for your helps! I'm waiting you to post an answer.
Comment: Not needed. You answered it to your own.
Comment: It is also useful to see that since $\lfloor x\rfloor=k$ on interval $[k,k+1)$ then $\lfloor nx\rfloor=k$ on interval $[k/n,(k+1)/n)$ for $n\in\mathbb{Z}$. Therefore $\lfloor 2x\rfloor=5$ on interval $[5/2,3)$.
Comment: @JohnWaylandBales I didn't understand the main idea of equation that you wrote. Could you tell me the explanation of the equation with words, please? Also if you can give some examples with some various values, it would make me happy! Thanks!
Comment: In my comment, I should have specified that $k$ is an integer and $n$ is a *positive* integer. For example, if you wish to solve $\lfloor 3x-7\rfloor\le-2$, you rewrite it as $\lfloor 3x\rfloor-7\le-2$ then $\lfloor 3x\rfloor\le5$. Then we conclude that $\lfloor 3x\rfloor=5$ for $x\in[5/3,6/3)=[5/3,2)$ so $x<2$.
Comment: @JohnWaylandBales Oh, wow! I understood. It gives in which range of numbers' greatest integer value will 5. This is very useful! Have a good day, sir!
Answer: Note that $$\lfloor2x\rfloor\leq5\Rightarrow2x<6$$ Not $$\lfloor2x\rfloor\leq5\Rightarrow2x\le6$$
because  $$2x=6\implies \lfloor 2x \rfloor =6$$
Therefore you have $$2x<6$$ which implies $$x<3$$
Comment: Could you please explain  $2x=6\implies \lfloor 2x \rfloor =6$? I guess the right-hand-side needs to stay as 5. An example would help. Thanks.
Comment: I agree with @NoChange. Thanks.
Comment: Note that the floor of an integer is the same as that integer. Therefore if $2x=6$ which is an integer we get $\lfloor 2x \rfloor =6$
Comment: True, but the question is not about integers only, as far as I can tell. I see that x has to be <= 2.5.
Comment: Oh, I see. @MohammedRiazi-Kermani means, I have wrong in the question. I'm editing it now. Thanks for your attention!
Comment: @MohammadRiazi-Kermani I will give you positive vote when I got 15 reputations.
Comment: Thanks for your attention
Answer: Note that
$$2x= \lfloor 2x \rfloor + \{ 2x \} < \lfloor 2x \rfloor +1 \leq 5+1=6$$
since the fractional part $\{ 2x \} \in [0,1)$.
Comment: This looks like, the best equation to show relations between things. Can you explain the equation with words, please? I can't understand the meaning of it. Also, $\{.\}$ or $\{2x\}$ stands for what?


Universal cover $\mathbb{S}^3 \rightarrow SO(3)$ through Quaternions.

Question: I'm trying to prove that the map given by
\begin{equation*}
\begin{gathered}
 \varpi: \mathbb{S}^3 \rightarrow SO(3)\\
\mu \mapsto M(f_\mu)
\end{gathered}
\end{equation*}
 where $f_\mu: \mathbb{R}^3 \rightarrow \mathbb{R}^3$ ($a \mapsto \mu a \mu^{-1}$), and $M(f)$ stands for the matrix of $f$, is a covering (in fact, the universal cover).
(In the sense that $a \in \mathbb{R}^3 = Im(\mathbb{H})$, $\mu \in \mathbb{S}^3 = \{q \in \mathbb{H} : |q| = 1\}$ and $\mu a \mu^{-1}$ denotes the quaternion product).
I've already proved that is well defined and is surjective using the relations between the quaternions and the rotations in $\mathbb{R}^3$.
https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
(Obviously, it is also continuous).
However I don't know how to prove that is a local homeomorphism.
In the book $\textit{Conformal Geometry of Surfaces in $\mathbb{S}^4$ and Quaternions}$ by F. E. BURSTALL, D. FERUS, K. LESCHKE, F. PEDIT and U. PINKALL
the differential of the mapping is computed and it is proved that is a local isomorphism (and then $\varpi$ is a local diffeomorphism).
It is written that for $\mu \in \mathbb{S}^3, v\in T_{\mu}\mathbb{S}^3 = (\mathbb{R}_{\mu})^{\bot}$ the differential is
\begin{equation*}
d_{\mu}\varpi(v)(a) = va\mu^{-1} - \mu a \mu^{-1}v\mu^{-1} =\mu(\mu^{-1}va - a\mu^{-1}v )\mu^{-1}.
\end{equation*}
But I don't know where this formula come from. ¿How I should calculate this?
From there, it is easy to show that the differential is a local isomorphism because $\mu^{-1}v$ commutes with all $a\in Im(\mathbb{H})$ if and only if $v = r\mu$ for some real $r$. But then $v = 0$ since $v \bot \mu$.
Comment: No idea personally, but $\mu(\mu^{-1}va - a\mu^{-1}v )\mu^{-1} = \mu[\mu^{-1}v, a]\mu^{-1}$ looks like a lie bracket. :P
Answer: You dont need this ; your map is an homomomorphism between two Lie groups, and it is differentiable. The  rank of its derivative is constant (as this is an homomomorphism). As your map is surjective the rank must be maximal, and your map is a local diffeomorphism.
Answer: It's easier than I though.
Fixed $\mu \in \mathbb{S}^3$, the differential of $\varpi$ at $\mu$ is
\begin{equation}
\begin{gathered}
d\varpi(\mu): T_{\mu}\mathbb{S}^3 \rightarrow T_{\varpi{(\mu)}}SO(3)\\
\hspace{2cm}v \mapsto d\varpi(\mu)(v)
\end{gathered}
\end{equation}
The space $T_{\varpi{(\mu)}}SO(3)$ is a matrix space. In fact, is exactly the Lie Algebra $\mathfrak{so}(3)$ of skew-symmetric 3x3 matrices.
https://en.wikipedia.org/wiki/Rotation_group_SO(3)
(Although we don't need this).
Therefore, the notation $d_{\mu}\varpi(v)(a)$ makes sense since it is the vector of $\mathbb{R}^3$ given by the multiplication of the matrix $d\varpi(\mu)(v)$ and the vector $a\in\mathbb{R}^3$.
Also, the formula comes from the direction derivative:
\begin{equation}
\begin{gathered}
d_{\mu}\varpi(v)(a) = d\varpi(\mu)(v)(a) = \frac{d}{dt}\mid_{t = 0} \varpi(\mu + tv)a = \frac{d}{dt}\mid_{t = 0}(\mu + tv)a(\mu + tv)^{-1} = (va + (\mu + tv)\cdot 0)(\mu + tv)^{-1} + (\mu + tv)a \frac{-v}{(\mu + tv)^2}\mid_{t = 0} = va\mu^{-1} - \mu a \mu^{-1}v\mu^{-1}.
\end{gathered}
\end{equation}
As we wanted.


Adding an A record where the host name has a forward slash

Question: I want to add an A record www.mydomain.com/customer and point it to say 123.456.789.001 where www.mydomain.com is my domain.
When i tried to enter the value i am getting an invalid host name error and on doing a little check i found that "/" is not allowed.
But my domain reseller service wants me to add an A record with the host name as www.mydomain.com/customer How do i manage it?
Is it even possible to add an A record which has a / in it?
Answer: DNS is not HTTP.  It knows nothing about URLs.  It only deals with domain names.
Therefore, adding an A or CNAME record that refers to a portion of your domain won't be possible.  A record applies to the whole domain.  If /customer is intended to be on a whole other server, then consider a subdomain like customer.mydomain.com.   (Any DNS host that's worth the money you pay them will let you add records for subdomains besides "www".)
Comment: My DNS host allows me to add subdomains and i have added the customer.mydomain.com pointing to the IP address i was given but now I get a server not found error. I understand that it is normal for the DNS propagation to take some time.. how long do you suppose it will take for it to resolve? Is there any other way to find out if the settings worked?


Get variable from ng-repeat to javascript

Question: I'm trying to call a script that will open up a new page with some info about that "thing" I just clicked.
The problem is that data is dynamic and I loop through it with angular, this is the HTML part:

 {{ producto.name }} {{ producto.id }}

How can I pass that angularjs id to the "details" script? I already know about the ng-click,  I need to pass it to javascript though, unless ng-click can call a JS script in the header. Every id="{{ producto.id }}" shows up correctly but the one in the onclick event. Is it possible at all to achieve? Or, is it possible to call with ng-click a JS function that is placed locally in the header or it'll only call functions in the Main
Comment: If you can call onclick="details(...)", then for sure you can call details function from controller. $scope.details = function(id) { details(id )} and to call this one use ng-click
Answer: Use ng-click instead of onclick:
ng-click="details(producto.id);"

And define details function on scope in controller.
$scope.details = function (productId) {
    // Code here

Also,
You don't need mustache for ng-src(or any other angular directive) in
 ng-src="{{ producto.image }}"

Use
 ng-src="producto.image"

Comment: @AndreiLorincz Then, you can call your function in JS header, from the controller. Like `$scope.details = function() {details(arguments)}`;
Answer: TIL that if you want to pass an angularJS variable to a local JS script to the header you need to do it like this:

 {{ producto.name }} {{ producto.id }}

And not like in the initial question.


Computation of the commutator of permutations of $J_n$

Question: I've been slowly going through some of the material in Serge Lang's Alegbra, and I've just stumbled upon some computations that's puzzling me at the moment. It's a specific step in the proof of a theorem, namely:

Theorem: If $n\geq 5$ then $S_n$ is not solvable.

The step that's troubling me is the following one :

Let $i,j,k,r,s$ be five distincts integers in $J_n=\{1,2,\ldots,n\}$ and let $\sigma=[ijk]$ and $\tau=[krs]$. Then direct computation gives their commutator : $$\sigma\tau\sigma^{-1}\tau^{-1}=[rki]$$

I don't think I really understant how the computation works here, I'm definitely unable to get to the result. So if anyone could explain it, I'd appreciate it thanks.
Answer: Hint
Compute the image of all $l \in J_n$ under $\omega = \sigma\tau\sigma^{-1}\tau^{-1}$
For $l \notin \{i,j,k,r,s\}$, $\omega(l) = l$ is clear.
Now for example
$$\omega(i)=\sigma\tau\sigma^{-1}\tau^{-1}(i)=\sigma\tau\sigma^{-1}(\tau^{-1}(i)) = \sigma\tau\sigma^{-1}(i)=\sigma\tau(\sigma^{-1}(i))=\sigma\tau(k)=\sigma(r)=r=[rki](i).$$
Do the same for $j, k, r,s$.
A shorter proof can use the fact that for any cycle $\tau = [i_1 \ i_2 \ \dots \ i_k]$ and any element $\sigma \in \mathcal S_n$, you have
$$\sigma \tau \sigma^{-1} = [\sigma(i_1) \ \sigma(i_2) \ \dots \ \sigma(i_k)].$$
Applying that to the commutator $\sigma\tau\sigma^{-1}\tau^{-1}$, you get
$$\sigma\tau\sigma^{-1}\tau^{-1} = [i \ r \ s ] \tau^{-1} = [i \ r \ s ][k \ s \ r ] = [r \ k \ i]$$
Answer: Recall that the product of two permutations written in cycle notation is defined as the composition, and therefore should be computed right-to-left.
As an example, to compute $(12)(23)$ you should write $(1$, then compute
$$([12][23]).1 = [12].([23].1) = [12].1 = 2$$
and hence write $(12$. Then
$$([12][23]).2 = [12].([23].2) = [12].3 = 3$$
and hence write $(123$. Then
$$([12][23]).3 = [12].([23].3) = [12].2 = 1$$
and so you close the bracket, and get $(123)$.
Now, just use the associative property to do one product at a time, as described above. You get:
$$[ijk][krs][ikj][ksr] = [ijk][krs][iksrj] = [ijk][irj] = [irk] = [rki]$$
The standard notation is to put as leftmost element of a cycle the smallest one, but when letters are involved you can freely shuffle them around. What I mean is that $[irk]=[rki]=[kir]$.


How to provide additional data to a go handler

Question: Good Morning,
The way to pass additional parameters to a go handler is quite fuzzy. I thus summarize here my problem:
Considering I have a windows service that read a config file and start a smtp listener :
func (m *myservice) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {

    Configurationx := loadConfiguration();
    log.Println("test : Foo is : "+Configurationx.foo )   //<<  ok

     go func(  ) {
        smtpd.ListenAndServe("127.0.0.1:25", mailHandler, "myServer", "")
    }();

// Here below there is no problem
    changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
loop:
    //< service loop that is skipped ;>
}

The following mail handler is working good
func mailHandler(origin net.Addr, from string, to []string, data []byte) error {
   // the handler recieve the incoming mails
}

But if I want it to handle mail using configuration information from the var "Configurationx" , what is the best way to do ? Within mailHandler, "Configurationx" is not accessible.
Thank you for your help
Answer: Well, there is an interesting conjecture : just post a question and you'll find a solution yourself.
func CreateHandler ( Conf Configuration ) smtpd.Handler {
    // ...
    // then return the original handler
   return func (origin net.Addr, from string, to []string, data []byte) error {

   log.Println("test : Foo is : "+Conf.foo )   //<<  ok

    return nil
}

Call to ListenAndServe:
smtpd.ListenAndServe(os.Args[1], CreateHandler(Configurationx), "MyServerApp", "")


$\mathbb R^2$ surface with no image in $\mathbb R^3$

Question:
"It was not immediately appreciated that Gauss' approach allowed mathematicians to define surfaces as regions of the plane with a particular metric that are not to be obtained from surfaces in Euclidean 3-dimensional space. Of course, if one defines a surface as the image of a map from a piece of $\mathbb R^2$ to $\mathbb R^3$, then of course it is in $\mathbb R^3$. But if one defines a surface as a region of $\mathbb R^2$ with a particular metric, then there may be no surface in $\mathbb R^3$ to which it corresponds. The first person to appreciate this seems to have been Riemann, who also extended this idea to any number of dimensions. (Quote from Stanford Encyclopedia of Philosophy)

What is an example of that particular metric?
Did Riemann conceive of Riemannian geometries initially to eliminate discontinuities (infinities, gaps, imaginary or otherwise undefined values) that resulted when rotating or reflecting a non-euclidean curve about the x or y axis?
Comment: Projective space $P_2$ exists in four dimensions, and can be embedded in $R^3$ only by being self-intersecting.  Called a Steiner surface, I think.  I recall this from Spivak's Differential Geometry Volume I.
Answer: If the author had in mind a particular non-embeddable metric on a plane region, it was almost certainly the hyperbolic plane, which may be viewed (among infinitely many other ways) as

The conformal disk model
$$
ds^{2} = \frac{dx^{2} + dy^{2}}{(1 - x^{2} - y^{2})^{2}},\qquad
x^{2} + y^{2} < 1.
$$
The conformal upper half-plane model
$$
ds^{2} = \frac{dx^{2} + dy^{2}}{y^{2}},\qquad
0 < y.
$$

By a famous theorem of Hilbert, neither immerses isometrically in Euclidean three-space. (Arbitrarily large hyperbolic disks can be embedded in Euclidean three-space, however.)
I'm not a historian, but believe Riemann's goal was to frame geometry intrinsically. Gauss had shown that the product of the principal curvatures of a surface in Euclidean three-space (which a priori depends on the "extrinsic bending" of the surface) is determined by angular defects in small geodesic triangles (which can be measured without leaving the surface). It's natural to investigate what other geometric aspects of surfaces can be defined and studied intrinsically.
If it matters, in this intrinsic sense we can assert our own universe is curved (geodesic triangles can have interior angle different from a straight angle) without there being any higher-dimensional space in which our universe is embedded.


Prove that the plane through the point $(\alpha, \beta, \gamma)$ and the line $x = py + q = rz + s$

Question: Prove that the plane through the point $(\alpha, \beta, \gamma)$ and the line $x = py + q = rz + s$ is
$${\begin{vmatrix} x& py+q& rz+s\\
\alpha& p\beta+q& r\gamma+s\\
1& 1& 1\\
\end{vmatrix}} = 0$$
My Attempt:
The equation of line is
$x = py + q = rz + s$
$$\implies x = p (y + \frac {q}{p}) = r ( z + \frac {s}{r}) $$
$$\implies \frac { x - 0}{1} = \frac {y + \frac {q}{p}}{\frac {1}{p}} = \frac {z + \frac {s}{r}}{\frac {1}{r}}$$
The equation of plane through this line is
$$a(x-0) + b(y+\frac {q}{p}) + c(z+\frac {s}{r}) = 0$$
where $a,b,c$ are the direction ratios of the line normal to the plane.
Now,
$$a\cdot 1 + b\cdot (y+\frac {q}{p}) + c\cdot (z + \frac {s}{r}) = 0$$
Also, the plane passes through the point $(\alpha, \beta, \gamma)$,
$$a(\alpha - 0) + b(\beta + \frac {q}{p}) + c(\gamma + \frac {s}{r}) = 0$$
How to proceed further from here?
Comment: Get the vector in the direction of the perpendicular dropped from the point to the line. Then take the cross product between this vector and $\left (1,\dfrac{1}{p},\dfrac{1}{r}\right )$ which gives a vector in the direction $(a,b,c)$.
Answer: SAs per OP's work the line passes throught $A(0,-q/p,-s/r)$ its direction vector is $\vec L=(1,1/p,1/r)$. The plane passes through $B(u,v,w)$. Normal to the plane $\vec n=\vec{AB}\times \vec L=(n_1,n_2,n_3)$, then the equation of the plane is
$$n_1(x-u)+n_2(y-v)+n_3(z-w)=0.$$ This equation can also be written as
$$(\vec r-\vec B).(\vec{AB} \times \vec L)=0 \implies\begin{vmatrix} x-u & y-v & z -w  \\ 0-u & -q/p-v & -s/r-w \\ 1 & 1/p & 1/r \end{vmatrix}=0,$$ that gives the equation of the required plane.
Next, $C_2'\to p C_2, C_3' \to rC_3$ to get
$$\begin{vmatrix} x-u & py-pv & rx-rw \\ u & q+vp & s+rw \\ 1 & 1 & 1\end{vmatrix}=0$$
Next, Perform $R_1'\to R_1+R_2$ to get the required form:
$$\begin{vmatrix} x & py+q & rx+s \\ u & vp+q & rw+s \\ 1 & 1 & 1\end{vmatrix}=0$$
Answer: Hint:
$\frac { x - 0}{1} = \frac {y + \frac {q}{p}}{\frac {1}{p}} = \frac {z + \frac {s}{r}}{\frac {1}{r}}$
One of the points on the line is $P \,$ $(0,-\frac{q}{p}, -\frac{s}{r}$).
Direction vector from this point to $Q \,$ $(\alpha, \beta, \gamma)$ is $\vec{PQ} \, (\alpha, \beta + \frac{q}{p}, \gamma + \frac{s}{r})$.
As the given line and $\vec{PQ}$ are in the plane we take a cross product of vectors $\, (\alpha, \beta + \frac{q}{p}, \gamma + \frac{s}{r})$ and $(1, \frac{1}{p}, \frac{1}{r}) \,$to find the normal vector to the plane say, $(a, b, c)$.
Then the equation of the plane is $a(x-\alpha) + b(y-\beta) + c(z-\gamma) = 0$


Is It valid to use a Linear Mixed effect Model to quantify a group 'summary' value and plot it when the factors are all categorical?

Question: I currently have a dataset with two factors: Gene and Timepoint. Both of these factors are categorical in nature where Gene has 2 levels defined as control vs disease, and timepoint has 4 levels: Month 1, 2, 4, and 6. The justification for having categorical time instead of a continious variable is that the month can act as a proxy for disease state. For every subject, they have a specific number of technical replicates that can vary across subjects as well. The question I want to answer is whethe response is affected by Time and Gene: $\ H_0: \beta_{interaction} = 0$ Thus I have built a Linear Mixed Effect Model using fitlme in Matlab where the formula is:
$\ y_i \approx \beta_0 + \beta_1 \cdot Time + \beta_2 \cdot Gene + \beta_3 \cdot Gene * Time + \epsilon + Z_i$
where $Z_i$ is the intra subject variance (as subject is the random factor) and $\beta_{interaction} = \beta_3$. The reality of the equation is that they are dummy encoded, so there are more than 3 Betas, there's up to 7; one for each class. The beforementioned formula acts as a summary for what was intended to be asked mathematically.
How Matlab (and I'm assuming a bunch of other languages do) does is that it takes one class and assigns it to be the reference values, i.e. $\beta_0$ becomes the summary value for that particular class. All other class values are in reference to the intercept. A classic output in Matlab would look like:

The output in text form is as follows:
Linear mixed-effects model fit by ML
Model information:

Number of observations             736
Fixed effects coefficients           8
Random effects coefficients        207
Covariance parameters                2

Formula:

Strength ~ 1 + Timepoint*Genotype + (1 | Complete_ID)

Model fit statistics:
AIC       BIC       LogLikelihood    Deviance
2417.9    2463.9    -1198.9          2397.9

Fixed effects coefficients (95% CIs):
Name                                    Estimate    SE         tStat      DF     pValue         Lower       Upper
{'(Intercept)'                 }          5.6218    0.21269     26.431    728    1.8785e-108      5.2042     6.0393
{'Timepoint_Month4'            }         0.36013    0.28287     1.2731    728        0.20337     -0.1952    0.91547
{'Timepoint_Month1'            }         0.82175    0.28695     2.8638    728      0.0043066     0.25841     1.3851
{'Timepoint_Month2'            }         0.63884     0.2847     2.2439    728       0.025138    0.079909     1.1978
{'Genotype_WT'                 }         0.63632    0.28542     2.2294    728        0.02609    0.075977     1.1967
{'Timepoint_Month4:Genotype_WT'}        -0.55392     0.3972    -1.3946    728        0.16358     -1.3337    0.22588
{'Timepoint_Month1:Genotype_WT'}        -0.38871    0.40222    -0.9664    728        0.33417     -1.1784    0.40095
{'Timepoint_Month2:Genotype_WT'}        -0.54137    0.39186    -1.3815    728        0.16754     -1.3107    0.22794

Random effects covariance parameters (95% CIs):
Group: Complete_ID (207 Levels)
Name1                  Name2                  Type           Estimate    Lower      Upper
{'(Intercept)'}        {'(Intercept)'}        {'std'}        0.81521     0.70306    0.94525

Group: Error
Name               Estimate    Lower     Upper
{'Res Std'}        1.0533      0.9916    1.1188

As one can see, there are a bunch of estimates, and my understanding is these are the estimates that describe the classes' effect on the response. For example, the class Timepoint_month2 has a 5.6218 + 0.6334 response value since 0.6334 is the quantified 'effect' of the class on the response if Timepoint_month2 was true, and 5.6218 is the intercept (when all $\beta_n = 0, n > 0$).
I have taken those estimates and the corresponding addition of each classes estimates to the intercept as the "representative" value for the response for each group. I have interpreted them in the same manner as how one would interpret the arithemtic mean for each class. So the questions are as follows:

Is the intepretation of the intercept and the estimates of coefficients for each class correct (addition of the estimates for each respective class to the intercept would produce the "representative" group value)?
Can I plot those values onto a barchart if they can be interpreted as valid "representative" values?
Would it be considered misleading if I were to plot the arithmetic mean and variance from the mentioned calculation instead of the coefficients and the SE associated with it calculated from the LME? The concern here is that I am running a statistical test on the estimated coefficients from the LME, not from the values quantified by arithemtic mean and then doing an ANOVA on those values.
A somewhat tangential question but my understanding of the pValues in the image designate the likelihood of type 1 Error of whether the estimated coefficients are not 0 (so in this example, the type 1 error probability that a class is different from intercept). How would I go about doing a post-hoc test assuming the interaction term was found to be significant (done by using the anova function on the model in Matlab)?
Comment: @EdM Thanks for the suggestion, I have done so, please let me know what you think!
Comment: It's very hard to read the summary table, even with the full link to the image. Could you please edit the question to include that information in legible text format? Surrounding text with backticks should do the trick; see the instructions for "Code" input. I think there might be an issue with how Matlab is choosing the reference classes, but I can't quite make it out from the image.
Answer: You seem to have started on the right path, but there are some potential missteps to avoid. I'll assume that you have found that the assumptions underlying the model have been met adequately.
With respect to the first question
First, the Intercept is the estimated outcome when all predictors are at reference levels (evidently Month6 for Timepoint and the non-WT Genotype). So adding the Timepoint_Month2 coefficient to the intercept only gives you the estimate for the reference (non-WT) level of Geneotype at Month2.
Second, you have to continue that coefficient-addition process carefully as you proceed to predictions that involve the interaction coefficients. For example, to get the  Timepoint_Month2 estimate for the non-reference value of Genotype (WT) you would start with the above sum to get the reference value at Month2, then add the coefficient for the non-reference level (Genotype_WT, for its difference at the reference Month6), and finally add the Timepoint_month2:Genotype_WT interaction term that estimates the further difference from what would be predicted based solely on the lower-level coefficients.
Third, any such estimate should be accompanied by a corresponding standard error or confidence interval. For that you need access to the coefficient covariance matrix, which is presumably produced as part of the model fit but isn't shown in your model summary. Then use the formula for the variance of a weighted sum of correlated variables to get the variance of whatever linear combination of coefficients that you wish.
With respect to the fourth question
There are a few potential problems when you say that you want to do post-hoc tests "assuming the interaction term was found to be significant."
First, when there are interactions the apparent "significance" of any coefficient depends on how its interacting predictors are coded. See this page, for example.
Second, you don't have a single interaction coefficient. You have 3. I assume that Matlab's anova function can give you an overall estimate of the "significance" of all the interaction terms together, but be warned that some ANOVA methods can give misleading results when data are imbalanced. See this page, for example.
Third, there's no need to limit yourself to a situation with a "significant" interaction for performing comparisons. If you have a particular comparison of interest, do it while including any interaction coefficient that's involved. Use the coefficient covariance matrix and the formula for the variance of a weighted sum of correlated variables, as above. That's the best description of your data, as lack of statistical significance does not necessarily mean lack of practical significance.
If you do several such comparisons, however, you need to take precautions against the multiple comparisons problem.
With respect to the second and third questions
Bar charts aren't often very useful. For this type of data, plots of estimated outcomes and their confidence intervals over time for each Genotype (at a random intercept value of 0, presumably what the fixed-effect coefficients represent) would be a good choice . As the linear model pools information across all time points and genotypes and individuals to get the underlying error estimates, display the point estimates and confidence intervals from the modeled values instead of from the individual Timepoint:Genotype combinations, which would be complicated here by the random-effect components.
In response to comment. The point estimates and standard errors for each combination of Timepoint and Genotype, based on the raw, unmodeled data, aren't the best description of your results if the assumptions underlying your model hold.
A linear regression model assumes that all observations share a common random error distribution around the modeled values, which is estimated after taking into account all the combinations of fixed and random effects. The reliability of each model estimate (which is presumably what you want to display) is based on that pooled information about the random error distribution, not on the vagaries of which particular sample of that error distribution was represented in any particular Timepoint and Genotype combination.
With a mixed model even the average values at each Timepoint and Genotype combination can be misleading. The random intercepts in your model are estimated by forcing a Gaussian distribution on the set of individual intercept estimates among the Complete_ID levels, each of which is like an extrapolation back to the reference situation (non-WT and Month6 here). Again, all the data are used to estimate the random effect. Using the raw averages thus doesn't represent your best estimate of the underlying process, as they depend on the vagaries of which individuals (and their random intercepts) happened to be included in each Timepoint and Genotype combination.
Final thoughts
I'm not sure whether there are tools available in Matlab to simplify the types of calculations above. R has a wide range of tools that simplify modeling and post-model calculations. For example, the emmeans package can take a mixed model (e.g., from the lmer() function of the lme4 package) and get the point estimates and confidence intervals for each of the Timepoint:Genotype combinations, with appropriate correction for multiple comparisons. The DHARMa package is particularly helpful for evaluating the quality of a mixed model fit, which can be trickier than evaluating an ordinary least squares model.
Comment: @Syuma I added a couple of paragraphs about why the modeled values are generally considered a better description of your results, if the assumptions underlying the model hold. In brief, the model smooths out the effects of random sampling involved in getting the data for each `Genotype` and `Timepoint` combination, using all the data to estimate the residual error that helps determine the reliability of the point estimates.
Comment: Thank you for the comprehensive answer! This was extremely helpful. I'm glad that my intuition about adding the coefficients was correct as confirmed by your response (I have added the interaction term coefficeint where necessary with the corresponding WT_Month6 estimate). However, I am still a little confused about the answer to my third question. You mentioned it would be better to plot the estimates and CIs from the modeled values instead from individual combinations, but don't those estimates and CIs come from the individual combinations? I was wondering if I could get more clarification!


Override drupal form output. Place two input fields side by side

Question: I am building a form using the FAPI and so far it is going fine.
I do however have a requirement for two tightly coupled values (currency and amount) that I wish to appear side by side in the form and not on separate lines.
What I need is something very similar to the way Drupal handles dates (3 inputs side by side, Im not sure, but are their input values added together to produce one value?)
Im sure this is possible using the FAPI but I cant see how off hand.
I would like to avoid any extra modules if possible.
Any takers?
thanks
Kevin
Answer: You can groupe the two fields into a field group. This gives HTML code wrapped around the fields. Just change the CSS settings of this HTML to your needs.
Comment: Field groups are a standard feature of CCK in D6 you just have to activate the module. For D7 it's an additional module.
Comment: Are you referring to the field group module? aside from the fact that I didnt want to add a new module, it appears this is not available for Drupal 6
Comment: Actually, I accepted this answer, but it was not at all what I was after. I could create custom fields no problem, but I could not insert them into my FAPI. I found a much more appropriate solution: http://www.akchauhan.com/create-drupal-form-elements-like-date-element/
Answer: In Drupal 7, you can use the Double Field module.  It even allows for prefixes and suffixes for text fields, which work great for currency fields.


Exercise 1.1.9 from West

Question: Currently I am reading the first edition "Introduction to Graph Theory" by Douglas B. West.
Exercise 1.1.9 states the following:
1.1.9. Suppose that $G$ is a simple graph having no vertex of degree $0$ and no induced subgraph with three edges. Prove that $G$ has at most four vertices.
Counter-example: Let $V(G) = ${$ 1,2,3,4,5 $}$ $ and $E(G) = ${$ 12,23,45 $}$ $.
Is this counter-example correct ?
EDIT:
Came up with this approach but I'm stuck.
Proof. Because the degree of every vertex in $G$ has degree of at least 1 then
$$
\sum_{v \in V}^{} \text{deg}(v) \geq |V|
$$
and recall that half the sum of all degrees in $G$ is the size of the edge set, thus
$$
|E|\geq \frac{1}{2} |V|
$$
Now, if $G$ does not contain any induced subgraph $H$ with three edges, that implies there is no 4-vertex or 5-vertex subset of $V(G)$ for which the induced subgraph under that subset contains three edges. Because $|E| \geq 3$ for $|V| \geq 5$ then $G$ must contain a three edge subgraph (and im stuck here)
Comment: $G$ is an induced subgraph of $G$, and has three edges.
Comment: The induced subgraph doesn't need to be proper
Comment: Oh, so this was an error of definition on my part. Thanks
Comment: @MichaelBurr What does proper mean?
Comment: A proper subset is a subset that isn't equal.  This is just a way of saying that the induced subgraph could be all of $G$.
Answer: Your Counter-Example almost contains the Proof !
When we have graph $G$ with $5$ or more vertices , then a sub-graph ( which might be $G$ itself ) will contain $5$ vertices , which will look like your Example.
Let all the vertices be $0$ Degree , unconnected to other vertices.
We want the Case where there are no $0$ Degree vertices , while we have $5$ such $0$ Degree vertices. Hence we can connect ( arbitrarily ) vertices $1$ & $2$ to get $(1,2)$.
We still have $3$ vertices with $0$ Degree , with $1$ Edge.
Adding a new Edge either will reduce that count by $1$ ( eg $(1,3)$ ) or will reduce that count by $2$ ( eg $(3,4)$ ) , leaving us with atleast $1$ vertex with $0$ Degree.
Adding a third Edge will give a subgraph with 3 Edges , while not adding a third Edge will give a graph with at least $1$ unwanted $0$ Degree vertex.
Either way , the Conclusion holds !
At the Point where we have 3 Edges , adding more Edges might eliminate all the $0$ Degree vertices , though it can not eliminate the currently existing subgraph having $3$ Edges.
Maximal Example : $E(G)=\{1,2,3,4\}$ with $V(G)=\{(1,2),(3,4)\}$
Comment: It's not obvious that we can't eliminate every existing $3$-edge subgraph after one appears. Consider that we can pull it off with $4$ vertices: if we have edges $\{(1,2), (2,3), (3,4), (1,4)\}$, that's also a maximal example.
Comment: But what if you then add a fourth edge? This argument is unfinished.
Comment: Nice Catch ! I have added the last 2 Sections , @MishaLavrov , to make it complete now.
Comment: Oh , you are right , @MishaLavrov , I will have to rethink that now !
Comment: Hint: first prove that the graph must have maximum degree 2 or less, then prove that it can have at most two connected components. Then analyzing the remaining possibilities becomes much easier.
Comment: "must have maximum degree 2 or less" as in the degree of any vertex in G is 2 or less? @MishaLavrov
Comment: @BryanBusby Yes, exactly. One of two things goes wrong if you have a vertex with $3$ neighbors...
Comment: I see that these two components are P_1 and P_2. Adding an edge strictly induces a 3-cycle or a 3 edge path. I just don't know how to prove that adding an arbitrary number of edges under an n vertex graph preserves the property in 1.1.9. @MishaLavrov
Comment: @BryanBusby You shouldn't try to reason through what happens if you add edges. Just reason about what the graph $G$ can and cannot have. (You're missing one component, though: $C_4$. And if you're following West, you should call the possible path components $P_2$ and $P_3$, by the number of vertices they have.)

Exercise 1.1.9 from West


How do I keep my E string from "squeaking"?

Question: Start out by saying that I play the violin.  It's a known phenomenon (at least to me :) ) that sometimes, when you are playing on the A and D strings and suddenly switch to an open E, the E string "squeaks" (plays a high harmonic instead of an open E).
Most of the time, I can counter this by going into positions or playing 4th finger on the A string, but I am currently playing a musical piece in which I have a series of double and triple stops which force me to play the E on the E string proper.
Is there a particular way of holding my bow or distributing the weight on the bow so as to prevent this "squeaking?"
Answer: The E string whistle may be caused by many things, usually a technique issue with the bow, but there are some strings that are more likely to whistle. I've found that the gold plated unwound E strings tend to whistle more. D'Addario sells a "non-whistling" aluminum wound string. I've never tried one, but I have found that the wound E strings tend to whistle less.
Here are some things to check that I've found when fixing the issue with students:
make sure your left hand isn't brushing up against the E string at the nut. Occasionally the soft flesh of the first finger can get close enough to the string to make it whistle.
On your bow arm, when you transition to the E string, make sure that the weight of your hand remains on the first finger on the bow, and that your pinky or any of the back fingers are not tense or pressing on the stick when you change.
Make sure the bow hair is perpendicular to the string / parallel to the bridge on the change over and not on a slight off angle.
Check the height of your elbow on the string change. A good starting point is when your bow is at the half way point on the string, your wrist and palm should be level or in-line. You want the stick over the hair on the change, too low of an angle can also cause the whistle.
Answer: Basically, yes.   Unless you've got a duff E string.   Or you might be using too much rosin.   But basically, bow straight, in the right place, with the right amount of pressure.  Your teacher will show you.


How to join parts of path in Python?

Question: Don't suggest os.path.join since it does something strange
import os.path
base = "api/v1"
tail = "/employees"
os.path.join(base, tail)
'/employees'

I need function that really joins the parts of the path.
Comment: Remove the `/` from `/employees`.  A leading `/` is treated as the root directory, so it started over from scratch.
Comment: It doesn't do "something strange", it does exactly what it is supposed to do. A path that says `/employees` means "no matter where you are at this point, ignore all of that, start over at the root of the file system, and go into the employees folder". If you just wanted "go into the employees folder from where you are now", that is written `employees`, without a `/` at the front.
Answer: You can basically use the plus sign and save the result into a variable:
base = "api/v1"
tail = "/employees"
path = base + tail

How to join parts of path in Python?


On the definition of ideal (is it a subring?)

Question: My book defines an ideal to be a subring of R such that $xr \in I$ and $rx \in I$, whenever $r \in R$ and $x \in I$.  However, by definition any subring of a ring with unity must contain unity.  So it follows that in any ring with unity, the only ideal is itself.
Surely my reasoning is incorrect, but I can't figure out where I'm going wrong.
Comment: It depends on definitions. If "ring" doesn't include unity, a subring of a ring with unity doesn't have to have a unity.
Comment: Are we sure the author requires rings to have unity in that book?
Comment: "A subring of a ring with unity is supposed to have a unity" (and, similarly, "a module over a ring with unity is supposed to have the unity act trivially on it") is an incantation used by some authors who are too lazy to make up their mind and follow a consistent choice of notations. I am not surprised that they don't always make good on the promise.
Comment: No, but a subring of a ring with unity must have unity, right?
Comment: I forgot that it is a convention among some authors to allow subrings to have a different multiplicative identity. This does not clear it up though.
Answer: If your book is defining an ideal to be a subring of $R$ with the multiplication property you described above, then it is almost certain that a subring of a ring with unity need not contain unity, because as you pointed out, this would imply that the only ideal of a unital ring is the entire ring. This definition would cause us a lot of trouble for many reasons: for example, the statement that every ideal is the kernel of some ring homomorphism and vice versa would fail massively. To resolve this dilemma, you could say that an ideal is simply an additive subgroup of the ring with the "absorption" multiplication property you described above, or you could allow unital rings to have nonunital subrings (e.g. $n\mathbb{Z}\subseteq\mathbb{Z}$ for $n\neq\pm 1$).
Answer: An ideal needn't contain the unit. Consider the ring $\mathbb{Z}$ (which has the unit $1$) and the set $2\mathbb{Z} = \{ 2z \in \mathbb{Z} : z \in \mathbb{Z}\}$. It is easy to check that $2\mathbb{Z}$ is a subring.
Then for all $z\in \mathbb{Z}$ and all $z' \in 2\mathbb{Z}$, we have that $zz' \in 2\mathbb{Z}$, as we wish.


getApplicationContext error

Question: I'm trying to store my device token from my android app programmatically to AWS SNS platform application.
I'm getting an error in getApplicationContext() method. Anyone with a solution for this error?
This is my code:
public class RegisterIdForAWS extends AsyncTask<String, Void, Void> {
    private Exception exception;

    @Override
    protected Void doInBackground(String... strings) {
        try {
            String pushNotificationRegId = FirebaseInstanceId.getInstance().getToken();

            if (pushNotificationRegId != null) {

                CognitoCachingCredentialsProvider provider = new CognitoCachingCredentialsProvider(
                       getApplicationContext(),
                        "us-west-2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                        Regions.US_WEST_2);
                String platformApplicationArn = "arn:aws:sns:us-west-2:11111111111:app/GCM/123";
                AmazonSNSClient pushClient = new AmazonSNSClient(provider);
                pushClient.setRegion(Region.getRegion(Regions.US_WEST_2));

                String customPushData = "";
                CreatePlatformEndpointRequest platformEndpointRequest = new CreatePlatformEndpointRequest();
                platformEndpointRequest.setCustomUserData(customPushData);
                platformEndpointRequest.setToken(pushNotificationRegId);
                platformEndpointRequest.setPlatformApplicationArn(platformApplicationArn);
                CreatePlatformEndpointResult result = pushClient.createPlatformEndpoint(platformEndpointRequest);
                Log.w(TAG, "Amazon Push reg result: " + result);
            }
        } catch (Exception e) {
            this.exception = e;
        }

        return null;
    }

    protected void onPostExecute(String text) {
        Log.w(TAG, "Amazon Push reg Finished");
    }

}

Comment: In which Activity you are using this AsyncTask and give proper flow with details so answer can  be deliverd properly. Otherwise answer below given by the @Andrea Ebano was correct.
Answer: In constructor of your async class, pass Context
private Context mContext;

public RegisterIdForAWS (Context context){
     mContext = context;
}

And instantiate class like this:
RegisterIdForAWS task = new RegisterIdForAWS (context);

Hope it helps.

getApplicationContext error


Restoring database through SQL Management studio

Question: I have a .bak file that I am restoring but SSMS gives an error that is
"System.Data.SqlClient.SqlError: The database was backed up on a server running version 10.50.1600. That version is incompatible with this server, which is running version 10.00.1600. Either restore the database on a server that supports the backup, or use a backup that is compatible with this server. (Microsoft.SqlServer.Smo)"
I have updated SSMS, now its version is 10.50.4000. But the problem is still the same.
Answer: You may not restore a backup of a higher version of SQL to a lower version of SQL.
Have a look at sql server builds.
10.50.1600 is SQL Server 2008 R2 while 10.00.1600 is SQL Server 2008.
Updating SSMS is not going to work, as it is only a Client Tool, and not the Server itself.
You need to upgrade the Server engine in order for the upgrade to work.
To see this is true, you may open your newly upgraded SSMS and login to the server where you want to restore your backup. In the tree you will see the Server's version in a parenthesis next to the Server's name. You will notice that though you upgrader SSMS, the Server's version remains the same.
Comment: well this answer is useful but i have also upgraded my SQL Server in all this mess. now my SQL server is SQL server 2008 R2, but as you said in tree server's version is same as before i.e. 10.0.1600. The backup problem i solved by getting script file of the DB. but i need to solve this problem also for future. After upgrading my SQL server i am updating SSMS but that gives an error and can't update SSMS.
Comment: How did you upgrade? Did you upgrade or do you have two SQL Servers running?
Comment: i upgraded.. got setup from my friend
Comment: Go to Start->Run and enter services.msc and hit enter. Then scroll down to SQL Server. There you will see entries like `SQL Serve(SQL2008R2)`. Can you please list here all those entries?
Comment: SQL Active Directory Helper Service, SQL Server (MSSQLSERVER), SQL Server (SQLEXPRESS), SQL Server Agent (MSSQLSERVER), SQL Server Agent (SQLEXPRESS), SQL Server Browser, SQL Server VSS Writer
Comment: This dictates that you have two instances of SQL. You have an SQL Express instance and a non Express one. It is probable that you are still connected to the old instance and not to the updated one.
Comment: so now whats the remedy to my problem? which SQL should i remove and how (causing no problems to other programs)
Comment: You may leave both SQL instances. What you need to do is find out how to connect to SQL2008R2 instance and restore your DB there.


Não consigo executar jar usando comando exec no php

Question: quando tento executar o sistema nao retorna nada, nao sei o que pode estar errado, tentei executar outro jar e funcionou, porem o msm n recebe nenhum parametro. o jar buscador funciona na linha de comando do linux normalmente
public function consulta(){
    $this->output->set_content_type('application/json');
    $query              = $this->uri->segment(3,0);

    exec("java -jar ../public_html/assets/apps/buscador.jar '$query'", $resposta);

    $html = "";
    $conta = 0;
    foreach ($resposta as $value) {
        if($conta < 10 && $conta > 1){
            $documento = split("\t", $value);
            $html .= "
".$documento[2]."
";
            $html .= "
".$documento[3]."

";
        }
        $conta++;
    }
    $this->output->set_output(json_encode(array('status' => 'success', 'consulta' => $html, 'resposta' => $resposta)));
}

Comment: Qual erro apresentado? Ou só não dá retorno?
Answer: Olá. Segue as minhas considerações, de caráter não absolutamente conclusivo.

A primeira averiguação a ser feita é executar manualmente o comando java. O problema pode ser o jar em si e não estar relacionado com o CodeIginiter/PHP. O usuário do Apache/PHP pode não ter o privilégio necesário para executar o comando.
A segunda, por se tratar de linha de comando, é colocar o parâmetro $query entre aspas. Espaços, barras, e outros caracteres especiais estragam a formatação do parâmetro. Depedendo de quais caracteres, isto é irretratável.
A terceira é sanitizar $this->uri->segment(3,0), pois o usuário vai digitar uma URI bem marota e começar a rodar comandos no seu servidor, mesmo que isto estragasse o retorno. Problema sério de segurança!

Esta forma de consulta por exec( ) me parece pouco profissional. O uso de exec( ) disputa contra as políticas de segurança do servidor. A função pode ser assícrona. Ela existe para quando realmente se precisa consultar artefados da máquina ou do sistema operacional do servidor. Isto não parece ser o seu caso, você deve estar tentando integrar dois sistemas, e dados da máquina que hospeda o sistema seriam irrelevantes.
Em se tratatando de Web, sistemas diferentes deveriam conversar por Webservice, ou numa solução bem mais simples, no mínimo por file_get_contents( ).


Slow sequential speeds on 9x7-drive raidz2 (ZFS ZoL 0.8.1)

Question: I'm running a large ZFS pool built for 256K+ request size sequential reads and writes via iSCSI (for backups) on Ubuntu 18.04. Given the need for high throughput and space efficiency, and less need for random small-block performance, I went with striped raidz2 over striped mirrors.
However, the 256K sequential read performance is far lower than I would have expected (100 - 200MBps, peaks up to 600MBps). When the zvols are hitting ~99% iowait in iostat, the backing devices typically run between 10 and 40% iowait, which suggests to me the bottleneck is something I'm missing in configuration, given it shouldn't be the backplane or CPUs in this system, and sequential workloads shouldn't work the ARC too hard.
I've played quite a bit with module parameters (current config below), read hundreds of articles, issues on OpenZFS github, etc. Tuning prefetch and aggregation got me to this performance level - by default, I was running at about ~50MBps on sequential reads as ZFS was sending TINY requests to the disks (~16K). With aggregation and prefetch working OK (I think), disk reads are much higher, around ~64K on average in iostat.
NICs are LIO iscsi target with cxgbit offload + Windows Chelsio iscsi initiator work well outside the ZFS zvols, with a optane directly mapped returning nearly full line-rate on the NICs (~3.5GBps read and write).
Am I expecting too much? I know ZFS prioritizes safety over performance, but I'd expect a 7x9 raidz2 to provide better sequential reads than a single 9-drive mdadm raid6.
System specs and logs / config files:
Chassis: Supermicro 6047R-E1R72L
HBAs: 3x 2308 IT mode (24x 6Gbps SAS channels to backplanes)
CPU: 2x E5-2667v2 (8 cores @ 3.3Ghz base each)
RAM: 128GB, 104GB dedicated to ARC
HDDs: 65x HGST 10TB HC510 SAS (9x 7-wide raidz2 + 2 spares)
SSDs: 2x Intel Optane 900P (partitioned for mirrored special and log vdevs)
NIC: Chelsio 40GBps (same as on initiator, both using hw offloaded iSCSI)
OS: Ubuntu 18.04 LTS (using latest non-HWE kernel that allows ZFS SIMD)
ZFS: 0.8.1 via PPA
Initiator: Chelsio iSCSI initiator on Windows Server 2019

Pool configuration:
ashift=12
recordsize=128K (blocks on zvols are 64K, below)
compression=lz4
xattr=sa
redundant_metadata=most
atime=off
primarycache=all

ZVol configuration:
sparse
volblocksize=64K (matches OS allocation unit on top of iSCSI)

Pool layout:
7x 9-wide raidz2
mirrored 200GB optane special vdev (SPA metadata allocation classes)
mirrored 50GB optane log vdev

/etc/modprobe.d/zfs.conf:
# 52 - 104GB ARC, this system does nothing else
options zfs zfs_arc_min=55834574848
options zfs zfs_arc_max=111669149696

# allow for more dirty async data
options zfs zfs_dirty_data_max_percent=25
options zfs zfs_dirty_data_max=34359738368

# txg timeout given we have plenty of Optane ZIL
options zfs zfs_txg_timeout=5

# tune prefetch (have played with this 1000x different ways, no major improvement except max_streams to 2048, which helped, I think)
options zfs zfs_prefetch_disable=0
options zfs zfetch_max_distance=134217728
options zfs zfetch_max_streams=2048
options zfs zfetch_min_sec_reap=3
options zfs zfs_arc_min_prefetch_ms=250
options zfs zfs_arc_min_prescient_prefetch_ms=250
options zfs zfetch_array_rd_sz=16777216

# tune coalescing (same-ish, increasing the read gap limit helped throughput in conjunction with low async read max_active, as it caused much bigger reads to be sent to the backing devices)
options zfs zfs_vdev_aggregation_limit=16777216
options zfs zfs_vdev_read_gap_limit=1048576
options zfs zfs_vdev_write_gap_limit=262144

# ZIO scheduler in priority order
options zfs zfs_vdev_sync_read_min_active=1
options zfs zfs_vdev_sync_read_max_active=10
options zfs zfs_vdev_sync_write_min_active=1
options zfs zfs_vdev_sync_write_max_active=10
options zfs zfs_vdev_async_read_min_active=1
options zfs zfs_vdev_async_read_max_active=2
options zfs zfs_vdev_async_write_min_active=1
options zfs zfs_vdev_async_write_max_active=4

# zvol threads
options zfs zvol_threads=32

I'm tearing my hair out on this. Pressure's on from users to go all-Windows with Storage Spaces, but I've used parity storage spaces (even with Storage Spaces Direct with mirrors on top), and it's not pretty either. I'm tempted to go straight mdadm raid60 under iSCSI, but would love it if someone could point out something boneheaded I'm missing that will unlock performance with the bitrot protection of ZFS :)
Comment: nice information about veeam and ReFS + synthetic Clones. I build a home system with Debian 10 openzfs and get slow read with NFS. My impression ist that openzfs is not for production enviroments. Maybe u can give a status of your present situation. I would advice you to use centos with the same setúp you already build. I follow your wish to use ReFS. Good luck!
Answer: Good question.

I think your sparse zvol block size should be 128k.
Your ZIO scheduler settings should all be higher, like minimum 10 and max 64.
zfs_txg_timeout should be much longer. I do 15 or 30s on my systems.
I think the multiple RAIDZ3's (or was that a typo) are overkill and play a big part in the performance. Can you benchmark with RAIDZ2?

Edit: Install Netdata on the system and monitor utilization and ZFS stats.
Edit2: This is for a Veeam repository. Veeam support Linux as a target, and works wonderfully with ZFS. Would you consider benchmarking that with your data? zvols aren't an ideal use case for what you're doing, unless the NIC's offload is a critical part of the solution.
Comment: MOST interesting feedback I have for you (I think) is for ZIO scheduler. When I move the needle on async mins and maxes, it _destroys_ io aggregation and the net result is quite bad. For reads, which is what I really care about here as writes are great, going to 10/64 makes average IOs to the disks ~16KB in iostat, and cuts the average read speed by 75% (~30 - 60MBps) given those disks' IOPS. I've also tweaked sync read #s and didn't see much affect, but I'll give that another shot regardless :)
Comment: Thanks! Point by point in follow-up comments, except Z3 which was indeed a typo :). On volblocksize, I've tested with both 128k and 64k, and the performance didn't change much for sequential reads. 128k would likely be a bit more space-efficient, but 64k matches the initiator client OS allocation unit size, and seems to do significantly better in random i/o scenarios (which are rare), while not mattering much in sequential i/o scenarios.
Comment: I'll test with txg_timeout higher - would that matter in the least for sequential reads? Given the low iowait on the backing disks, it didn't seem like write flushes were contending with / impacting average read speeds much.
Comment: zfs zfs_dirty_data_max_percent=25 - I'm usually 40% or greater there.
Comment: Oh, reads are a problem? What type of data is this? How full is the pool?
Comment: Yep, reads are the problem. Data was all written sequentially on the zvols, and this is a super fresh pool - about 35% full with very low fragmentation. It's a backing store for Veeam repository volumes, _huge_ files written sequentially on Windows.
Comment: I upped txg_timeout and the sync ZIO min and max read, didn't do much one way or the other.
Comment: So, I do run a large number of Veeam repositories based on ZFS. It's much cleaner to use native Linux versus iSCSI+zvols for this. Linux makes a great Veeam repository.
Comment: I'd typically go that route (and have a few mdadm+xfs older systems doing just that) - but for GFS copies, ReFS with synthetic fulls via fast clone is _phenomenal_ for space efficiency. From the space efficiency perspective, it's almost like inline dedupe (per chain) without the pain of inline dedupe :) Hence my want to use ZFS as a backing store (because Storage Spaces parity suuuuucks) and get decent sequential performance out of it :)
Comment: I'm suggesting to use ZFS filesystems for your setup, just not with zvols.
Comment: Sorry, I wasn't clear! I understand what you're suggesting. However, Veeam as of 9.x at some point added support for ReFS block cloning, which allows a repo to store a boatload of synthetic fulls and have them "share blocks". So, it removes the broken chain risk and most of the performance implications of using forever incremental or forever reverse incremental. ReFS with Veeam-usable block clone is only available on raw devices or storage spaces on Windows 2016+, meaning I'd have to use a zvol or a raw file on ZFS (both of which perform similarly) exported via iSCSI to make use of it.
Comment: @obrienmd Okay.


Exibir div em hover

Question: Como exibir uma div, que terá um resumo sobre o filme (texto), e um botão para (VER MAIS) ao passar o mouse sobre uma imagem.
Exemplo:
IMAGEM

Ao passar o mouse em cima desse link, aparecer uma div ao lado direito, com informações sobre esse filme.
Um exemplo do que estou falando, é o site da netflix ou telecine play.
Answer: Se você vai fazer este HTML o melhor é usar somente CSS.
Crie uma div para cada link e seu conteudo. Exemplo:

    Ver mais

Este filme é excelente! Recomendado a todas as idades

Aí você pode esconder a descrição com:
.descricao{
    display: none;
}

e depois pôr visivel quando o mouse fizer hover em .item:
.item:hover .descricao{
    display: block;
}

Exemplo
Se quiser fazer o efeito de aparece/desaparecer com animações pode usar CSS transitions.
Exemplo
Comment: Boa Sergio, assim não precisa usar Javascript :p
Comment: Acredito que com `visibility` ficaria mais elegante ;)
Comment: @Beterraba, é conforme o gosto :) Por isso adicionei o segundo exemplo ;)
Comment: Só é bom lembrar que isso não funciona em IE9 ou inferior. Pois ele não aceita pseudo-seletores quando não é o último seletor.
Comment: @GabrielGartz, verdade. Por curiosidade __[estive a ver estatisticas](http://gs.statcounter.com/#browser_version_partially_combined-ww-monthly-201101-201401)__ sobre IE9 e já só 3% parece usar.
Comment: @Sergio legal esse statcounter, eu não conhecia, é falei mais como fator informativo mesmo, não sei qual é o foco do site do usuário, mas na minha opinião pessoal deveriam abandonar a compatibilidade com browsers não modernos. Eu te dei +1 hehe, eu gostei da sua solução, só quis ajudar.
Comment: @GabrielGartz, sim, o seu comentário é acertado e bemvindo! Por isso também fiquei a pensar e fui procurar numeros frescos para mim próprio também :)
Answer: Algo como o .show e .hide do jQuery resolvem esse problema:
JS:
$("div.conteudo > img").hover(function() {
    $(this).next(".divDoLadoDireito").show(); //hover in
}, function() {
    $(this).next(".divDoLadoDireito").hide(); //hover out
});

HTML:

Comment: Na minha opnião, a melhor solucao foi a indicada pelo Sergio, podes obter o resultado desejado apenas com .css o jQuery e' sempre uma dependencia no teu codigo.

Exibir div em hover


Rails association works when it doesnt use an instance variable

Question: I'm getting the strangest error I've seen in Rails so far. In my view, I can print out the email associated with a painting if I find the record directly (e.g. Painting.find(15). But if I try to use an instance variable it errors (e.g @painting).
views/paintings/show.html.erb
<%= Painting.find(15).artist.user.email %>  # works
<%= @painting.artist.user.email %> # Error: "undefined method 'user' for nil:NilClass"

controllers/paintings_controller.rb
def show
  @painting = Painting.find(15)
end

Models: "users", "artists", "paintings".

A user can be an artist. So a user has_one artist.
An artist has_many paintings.
Comment: Does the problem only occur with associated objects? Have you verified, that the instance variable is correctly assigned in your view (e.g. `@painting.inspect`) is there any gem or other magic that might alter your instance variable (e.g. Draper)
Answer: I think you should add associations. This how they should look like:
class User < ActiveRecord::Base
  has_one :artist # it's ok
end

class Artist < ActiveRecord::Base
  belongs_to :user # add this
  has_many :paintings
end

class Painting < ActiveRecord::Base
  belongs_to :artist
end

For me both cases works with this associations.
Answer: Use
def show
  @painting = Painting.find(15).last
end

Currently the second one is returning a 1 element array, but in order to call a dependent method, you must specify 1 item.
Comment: Can you post your model associations? One of your associations might be off. If you use plural associations, with singular methods (or vice versa), it will change your expected results.


Doctrine 2 and MySQL: association mapping between a table and a view

Question: I'm trying to create an association between 2 entites. The left one is a table representation. The right is a view representation.
I just succeeded at making this relation work, but I have problem when creating the schema with php vendor/bin/doctrine orm:schema-tool:create.
Below is all the code needed to try it:
SQL
CREATE TABLE IF NOT EXISTS `demo` (
  `id` int(11) NOT NULL,
  `name` varchar(30) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO `demo` (`id`, `name`) VALUES
(1, 'demo 1'),
(2, 'demo 2'),
(3, 'demo 3'),
(4, 'demo 4');

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `demo_metadata` AS select `se`.`id` AS `demo_id`,12 AS `demo_count` from `demo` `se`;

Demo Table Entity
/**
 * @Entity
 * @Table(name="demo")
 */
class Demo {

    /**
     * @Id
     * @Column(type="integer")
     * @GeneratedValue
     */
    private $id;

    /**
     * @Column(type="string", length=30)
     */
    private $name;

    /**
     * @OneToOne(targetEntity="DemoMetadata")
     * @JoinColumn(name="id", referencedColumnName="demo_id")
     */
    private $metadata;

    public function getMetadata() {
        return $this->metadata;
    }
}

Demo View Entity
/**
 * @Entity
 * @Table(name="demo_metadata")
 */
class DemoMetadata {

    /**
     * @Id
     * @Column(type="integer")
     * @var int
     */
    private $demo_id;

    /**
     * @Column(type="integer")
     * @var int
     */
    private $demo_count;

    public function getDemoCount() {
        return $this->demo_count;
    }
}

Query and fetching data
$qb = $em->createQueryBuilder();
$qb
    ->select('d')
    ->from('Demo', 'd')
    ->leftJoin('d.metadata', 'dm')
    ->where('d.id = ?0')
    ->setParameter(0, 1);

$demo_object = $qb->getQuery()->getSingleResult();
var_dump($demo_object->getMetadata()->getDemoCount());

// display: int(12)

As we can see, the metadata property of the Demo Entity is populated with the data from the view. Everything works fine and as expected.
But with such a configuration, when running the cli command to drop the schema, and then recreate it, an error occurs because demo_metadata table already exist.
In the end, I'm not searching for a way to create automatically the view. I have SQL scripts that I can call to create the view. I'm wondering if there's a way to not trying to create the table for some entities?
[Doctrine\ORM\Tools\ToolsException]
Schema-Tool failed with Error 'An exception occurred while executing 'CREATE TABLE demo_metadata (demo_id INT NOT NULL, demo_count INT NOT NULL, PRIMARY KEY(demo_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8 _unicode_ci ENGINE = InnoDB':
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'demo_metadata' already exists' while executing DDL: CREATE TABLE demo_metadata (demo_id INT NOT NULL, demo_count INT NOT NULL, PRIMARY KEY(demo_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

It's just a matter of convenience, because the views already exist and are not dropped with the cli drop command.
Is it that the only way to manage this is to:

drop schema (doctrine cli)
remove demo_metadata view
create schema (doctrine cli)
remove demo_metadata table
create demo_metadata view

Thanks
Edit
In the end, I used this code to filter the entities I needed:
<?php

class UpdateSchema extends \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand {

    /**
     * {@inheritdoc}
     */
    protected function executeSchemaCommand(
        InputInterface $input,
        OutputInterface $output,
        SchemaTool $schemaTool,
        array $metadatas) : int
    {
        $entities = array_filter($metadatas, function ($m) {
            return !$m->isReadOnly;
        });
        return parent::executeSchemaCommand($input, $output, $schemaTool, $entities);
    }
}

Answer: In addition to create and drop commands, there is also an update command. That's the one you should be using if the database already exists
Wrong answer, see comments for correct
Comment: I tried with `update` as you proposed, but even if a view exists with the name `demo_metadata`, the update mechanism tries to create a new table `demo_metadata` and an error occurs. I'm forced to remove the view, make the update, remove the "wrong" table and recreate the view...
Comment: My bad, didn't read the question properly in hurry. This question is what you are asking about probably: http://stackoverflow.com/questions/12563005/ignore-a-doctrine2-entity-when-running-schema-manager-update
Comment: okay, thanks! I must admit I would have preferred a solution via annotations, like @Table(nogenerate=true), but the cli update override works perfectly! And it helps me to eventually ask my question from an better angle. Thanks


MinkContext not loaded and used

Question: When I run my behat session from behat/bin, it shows that only steps defined in the FeatureContext are used. When I try beta -dl, this is confirmed. My MinkContext apparently is not loaded and thus can not be used. These are my composer.json, behat.yml and FeatureContext files
Composer json
=================

{
    "require-dev": {
        "behat/behat": "~3.0.13",
        "behat/mink": "~1.6.0",
        "behat/mink-extension": "~2.0.0",
        "behat/mink-goutte-driver": "~1.1.0",
        "behat/mink-selenium2-driver": "*",
        "peridot-php/webdriver-manager": "dev-master",
        "bossa/phpspec2-expect": "1.*"
    },
    "config": {
        "bin-dir": "bin"

    }
}
behat.yml
=====================
    default:
    autoload: [ %paths.base%/contexts ]
    extensions:
        Behat\MinkExtension\Extension:
            base_url: http://www.google.com
            sessions:
                default:
                    selenium2: ~
        Sanpi\Behatch\Extension: ~
    suites:
        default:
            paths:    [ %paths.base%/features ]
            filters:
            contexts:
                - FeatureContext
                - Drupal\DrupalExtension\Context\DrupalContext
                - Drupal\DrupalExtension\Context\MinkContext
                - Drupal\DrupalExtension\Context\MessageContext
                - Drupal\DrupalExtension\Context\DrushContext
                - Behat\MinkExtension\Context\MinkContext

FeatureContext.php
====================
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
use Behat\MinkExtension\Context\RawMinkContext;

use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Mink\Mink,
Behat\Mink\Session,
Behat\Mink\Selenium2Driver;

/**
 * Defines application features from the specific context.
 */
class FeatureContext extends RawMinkContext implements SnippetAcceptingContext
{
    public $mink;
    public $driver;
    public $session;
    private $contactName;
    private $nodeId;

    /**
     * Initializes context.
     *
     * Every scenario gets its own context instance.
     * You can also pass arbitrary arguments to the
     * context constructor through behat.yml.
     */
    public function __construct()
    {
        // $this->driver = new \Behat\Mink\Driver\Selenium2Driver();
        // $this->getSession() = new \Behat\Mink\getSession()($this->driver);
        // $this->getSession()->start();
    }

        /**
         * Opens homepage.
         *
         * @Given /^(?:|I )am on (?:|the )homepage$/
         * @When /^(?:|I )go to (?:|the )homepage$/
         */
        public function iAmOnHomepage()
        {
            $this->visitPath('/');
        }
    /**
     * @param string $name
     *   An iframe name (null for switching back).
     *
     * @Given /^(?:|I )switch to an iframe "([^"]*)"$/
     * @Then /^(?:|I )switch back from an iframe$/
     */
    public function iSwitchToAnIframe($name = NULL)
    {
        $this->getSession()->switchToIFrame($name);
    }

    /**
     * @Given /^I set browser window size to "([^"]*)" x "([^"]*)"$/
     */
    public function iSetBrowserWindowSizeToX($width, $height)
    {
        $this->getSession()->resizeWindow((int)$width, (int)$height, 'current');
    }

    /**
     * @Given I click the element :arg1
     */
    public function iClickTheElement($selector)
    {
        $page = $this->getSession()->getPage();
        $element = $page->find('css', $selector);

        if (empty($element)) {
            throw new Exception("No html element found for the selector ('$selector')");
        }

        $element->click();
    }
    //
    /**
     * @When /^wait (\d+) seconds?$/
     */
    public function waitSeconds($seconds)
    {
        $this->getSession()->wait(1000 * $seconds);
    }

    /**
     * @Given /^I remember the name in "([^"]*)"$/
     */
    public function iRememberTheNameIn($selector)
    {
        $element = $this->assertgetSession()->elementExists('css', $selector);
        $this->contactName = $element->getText();
    }

    /**
     * @Then /^element "([^"]*)" should contain the name I remembered$/
     */
    public function elementShouldContainTheNameIRemembered($selector)
    {
        $element = $this->assertgetSession()->elementExists('css', $selector);
        $contactName = $element->getText();
        if ($contactName != $this->contactName) {
            throw new Exception("The contact name '$contactName' is not equal to the original name '$this->contactName'");
        }
    }

    /**
     * @Given /^I set the value "([^"]*)" for the cookie "([^"]*)"$/
     */
    public function iSetTheValueForTheCookie($value, $cookie)
    {
        $this->getSession()->setCookie($cookie, $value);
    }

    /**
     * @Given /^My "([^"]*)" content:$/
     */
    public function myContent($type, TableNode $nodesTable)
    {
        $saved = false;
        foreach ($nodesTable->getHash() as $nodeHash) {
            $node = (object)$nodeHash;
            $node->type = $type;
            $saved = $this->nodeCreate($node);
        }
        if ($saved) {
            $this->nodeId = $saved->nid;
        }
    }

    /**
     * @Given /^I fill in the input field "(?P<field>(?:[^"]|\\")*)" with the last nid$/
     */
    public function iFillInTheInputFieldWithTheLastNid($field)
    {
        $value = 'node/' . $this->nodeId;
        $field = $this->fixStepArgument($field);
        $value = $this->fixStepArgument($value);
        $this->getSession()->getPage()->fillField($field, $value);
    }

     /**
     * Returns fixed step argument (with \\" replaced back to ")
     *
     * @param string $argument
     *
     * @return string
     */
    protected function fixStepArgument($argument)
    {
      return str_replace('\\"', '"', $argument);
    }

    /**
     * @Given /^I place an image in my local file system$/
     */
    public function iPlaceAnImageInMyLocalFileSystem() {
      $url = 'https://www.portofrotterdam.com/sites/all/themes/custom/portofrotterdam/favicon-128.png';
      $img = '/tmp/testimage.png';
      file_put_contents($img, file_get_contents($url));
    }

    /**
     * @Given /^I cleanup database table entries for the subsite test$/
     * @Given /^I cleanup database table entries for the downloads test$/
     */
    public function iCleanupDatabaseTableEntriesForTheSubsiteTest() {
      db_query("DELETE FROM {filehash} WHERE md5 = 'bb7c2beef51b3be866a18292aa46a084'");
      db_query("DELETE FROM {file_managed} WHERE filename = 'testimage.png'");
    }

}

Answer: MinkExtension has changed its namespace. Instead of Behat\MinkExtension\Extension try to use Behat\MinkExtension
    default:
    autoload: [ %paths.base%/contexts ]
    extensions:
        Behat\MinkExtension:
            base_url: http://www.google.com
            sessions:
                default:
                selenium2: ~
        Sanpi\Behatch\Extension: ~

Comment: @Frank Bontes if this answer was usefull for you then you can upvote it.

MinkContext not loaded and used


interpreting within group correlation magnitude (Multilevel Modelling)

Question: I am trying to get a basic understanding of how to interpret the magnitude of within group correlations- and whether the general rule of weak (.2 to .4), moderate (.4 to .6), strong (.6 to .8) and very strong (.8 to 1) commonly used for between group correlations still applies.
For a bit of context: I am running correlations for Multilevel Modelling data (Experience Sampling Methods, variables are nested by persons, so within group refers to the variance of a specific variable for each individual). I have used the R psych package to run analyses.
Would anyone be able to either provide a general "rule of thumb" or point me to a reference paper. Thank you!
Answer: There is no right answer here. The only rule of thumb is that an intraclass correlation coefficient (ICC) > 0 is indication that you need to somehow account for the correlations of observations from the same individual or group. As an education researcher, I see ICCs ranging from .05 up to .50, depending on the outcome and whether I am modeling longitudinal or cross-sectional data. I would, in general, expect to see higher ICCs in longitudinal, repeated measures data than I would in cross-sectional data. However, there is no hard and fast rule about this.


What do the numerator and denominator of a chord name in roman numerals mean?

Question: I'm reading a paper on music theory and I keep coming across names of chords expressed as a fraction - I/I, I/V, ii/I, etc. Based on the use of these names in the paper, I'm reading this as:
I/I: A major chord with root as the first note of the Ionian mode of the diatonic major scale.
I/V: A major chord with root as the first note of the Mixolydian mode of the diatonic major scale.
ii/I: A minor chord with root as the second note of the Ionian mode of the diatonic major scale.
Is my understanding correct? Is there a more efficient/complete way to read this notation? In case I want to see more examples and explanation of this, what should I search for?
Thanks!
Answer: This notation is used for tonicizations and modulations. They mark the function of the chord in the target key.
So, for instance, V/V is the fifth of the fifth, that is, dominant of the dominant. This chord is commonly called the "double dominant". It can be used for a modulation into the dominant key or for temporary tonicization of the dominant.
It could also be notated as II, and sometimes it is. But the V/V notation makes its function more obvious.
Comment: If you are working in a Dorian #4 scale, then roman numerals are not really relevant, are they? They assume common practice tonality, where ii is minor, and V/V is major.
Comment: so would there be instances when 'II' and 'V/V' would appear in the same song? To show that it was just using the supertonic chord in isolation using II, but to show modulation as in V/V ?Seems somewhat over the top to me. The OP's concept of slash chords is incorrect, then?
Comment: I don't see why not. Don't we use these symbols for analysis? And analysis is often open to debate. I use II chords with no intention of tonicizing V, for example to harmonize a Dorian #4 scale (popular in Turkish music). I would argue that labeling this usage as V/V would be just wrong. Of course someone else could argue otherwise and we would have two different analyses :)


Relation between two variables

Question: I have approx 500 variable (each variable containing 80 data points). I need to find how each of the variable is related to other 499 variables - linear, log, exponential and so on. Is there a statistical test which could provide me with this information? I don't want to go through manual process of having trendline and finding the R-squared value.
Help much appreciated :)
Thank you!
Vinay
Answer: With 500 variables and all pairwise comparisons, that gives you 124,750 comparisons.  Doing one test on each pair at an alpha of 0.05 would generate over 6,000 false positives (assuming all nulls are true).  If you want to compare between multiple possible relationships that will inflate things even more.  Depending on the variability around the "True" relationship, 80 data points may not be enough to distinguish between the potential relationships (or at least subsets of them).
Also, what are your plans if the "Best" fits are contradictory?  e.g. variables 1 and 2 are linearly related, but 1 is exponential with 3 while 2 is log with 3 (if 1 and 2 are linear then they should have the exact same relationship with 3).  Any automatic method could give results like this even though it would contradict any underlying science.
So basically pulling 124,750 relationships out of a hat (or otherwise generating them randomly) will probably give you as much useful information (with less effort) than any automated method.
If you tell us more about why you think you want all those relationships, and how you plan to use them, basically what is your real and final question, then we may be able to give more useful advice.
Comment: I can increase the datapoints to more than 80. Basically i am trying to find the relationship between sensor data collected at location1...location500 and that's why i have 500 variables. Once i find the relationship, i would like to come up with multiple regression model like  TempAt1 = Log(TempAt2) + 0.4(TempAt3) - Exp(TempAt4). I am considering that i wouldnt have problems if "Best" fits among stations are contradictory. The whole idea would be to reduce the %error of dependent variable to least. Thank you :)
Comment: @VinayKumar, wouldn't it make more sense for all the relationships to be the same? similar?  why would the temperature at one site vary linearly with another site, but exponentially with a 3rd?  Also, the pairwise relationship does not necessarily match the "correct" or "best" relationship in a model with multiple predictors.
Comment: Yes i agree to this. But i thought to learn generic solution (not only temperature) when data is closely related as logarithmic or polynomial scale. Something like what Box-Cox transformation does!!
Comment: Essentially Pearson correlation would give higher value even if the variables are log, squared or squared-root of other variable.

Relation between two variables


Go vet warning about ignoring context cancel function

Question: I am passing a timeout context to Server.Shutdown (http package). I don't see that I would ever need to call the cancel function returned so I ignore it.  But when I run go vet it says the cancel function returned by context.WithTimeout should be called, not discarded, to avoid a context leak.
How do I fix the problem or avoid the go vet error message, if there is no problem?
    go signalShutdown(server, stopCh)

    if err := server.ListenAndServeTLS(cert, key); err != http.ErrServerClosed {
        log.Fatalf("ListenAndServeTLS() error: %v\n", err)
    }
    // Note: exit here does not terminate main()
}

// signalShutdown waits for a notification from the OS that the http server
// should be shutdown, then gracefully stops it.
func signalShutdown(server *http.Server, stopCh <-chan struct{}) {
    const ForceShutdownAfter = 10 // Shutdown context times out after this many seconds

    // Setup chan to receive notification of when server should shut down
    quitCh := make(chan os.Signal, 1)
    signal.Notify(quitCh, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)

    // Wait until we get a notification to stop the server
    select {
    case <-quitCh:
        log.Println("WEB : OS signal received on", server.Addr)
    case <-stopCh:
        log.Println("WEB : Shutdown message received on", server.Addr)
    }

    context, _ := context.WithTimeout(context.Background(), ForceShutdownAfter*time.Second)

    // Tell the server to shutdown but only after blocking new connections and waiting for the
    // existing connections to finish (OR if context expires - see ForceShutdownAfter above)
    if err := server.Shutdown(context); err != nil {
        log.Fatalf("Shutdown() error: %v", err)
    }

    os.Exit(0)
}

Answer:
... the cancel function returned by context.WithTimeout should be called, not discarded, to avoid a context leak.
How do I fix the problem or avoid the go vet error message, if there is no problem?

By calling, not discarding the cancel function, as documented:
context, cancel := context.WithTimeout(context.Background(), ForceShutdownAfter*time.Second)
defer cancel()


Appearance of the spinner

Question: i would like my spinner to be as in the picture.i can do it if i follow the android.developers example,but in my app,its necessary to get the spinner items from the java file and not from the strings.xml.this is my code(my code creates a spinner as in the photo but there is radiobutton when the spinner is closed,next to the first spinner item.i want this radio to disappear)
<code>array_spinner=new String[4];
array_spinner[0]="a";
array_spinner[1]="b";
array_spinner[2]="c";
array_spinner[3]="d";

Spinner s = (Spinner) findViewById(R.id.spinner);
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, array_spinner);
s.setAdapter(adapter);
</code>

WHEN THE SPINNER IS OPEN:
now:

I would like to be:
Answer: That one looks like an AlertDialog

Edit:
Okay, after a short research I found some spinner examples in the API examples. They look like this:

You can find the code here

Appearance of the spinner


NameError: name [nome] is not defined

Question: Preciso fazer uma programação em Python para saber a porcentagem CG numa cadeia de DNA...
maior = 0
dnaMaior = ""
while True:
     dna = input("Digite uma sequencia de DNA: ")
     if dna == "Z" or dna == "z":
      break
     else:
        tam = len(dna)
        indice = 0
        while indice < len(dna):
            if dna == "C" or dna == "G":
                C = C + 1
                G = G + 1
            indice = indice+1
        percCG = ((C+G)*100)/len(dna)
        maior = percCG
        dnaMaior = dna
        print(dnaMaior)

Pois ocorre um erro de sintaxe. Por que ocorre esse erro, e como corrigi-lo?

Digite uma sequencia de DNA: CCCCCCCGGGGGGGGAAAAAAAATTTT
Traceback (most recent call last):
  File "C:/Users/13104855/Downloads/exerc_02T2.py", line 18, in <module>
    percCG = ((C+G)*100)/len(dna)
NameError: name 'C' is not defined

Answer: Tem alguns problemas no seu código, mas este não é o foco da pergunta.
Este erro é por causa dessas linhas
C = C + 1
G = G + 1

Uma vez que C e G não foram declaradas, você não pode atribuir a elas o valor delas mesmas incrementadas de 1. Simplesmente declarar as variáveis antes de entrar no loop já resolve
maior = 0
dnaMaior = ""
while True:
     dna = raw_input("Digite uma sequencia de DNA: ")
     if dna == "Z" or dna == "z":
      break
     else:
        tam = len(dna)
        indice = 0
        C = 0
        G = 0
        while indice < len(dna):
            if dna == "C" or dna == "G":
                C = C + 1
                G = G + 1
            indice = indice+1
        percCG = ((C+G)*100)/len(dna)
        maior = percCG
        dnaMaior = dna
        print(dnaMaior)

NameError: name [nome] is not defined


Let $f:R\to R$ be a $C^1$

Question: If $f(0)=f'(0)=0$ and $|f(x)|\leq |x|^{1+a}$ then
$|f'(x)|\leq c|x|^a$.
I tried to use the mean value theorem and I am pretty sure it is a good way not to prove that.
Comment: who asked you to prove this?  It is false.  You know too little about the behavior of $f$ to conclude anything about its derivative for nonzero $x$.
Answer: Counterexample:
$f(x)=x^{1+a}\sin(x^{-a})$ for $x\neq0$ and $f(x)=0$ for $x\le 0$ and $a>0$.
Differentiability can be shown at $x=0$ using the difference quotient. However, the derivative does not tend to zero as $x\to0$.
Comment: Are you sure this is a proper counterexample? Could you provide a proof that it is continuously differentiable for all $a \ge 0$?
Comment: It is only continuous differentiable for a>0
Comment: however, you are right my counterexample is not completely correct. I will edit my answer.
Comment: The other counterexample was right.

Let $f:R\to R$ be a $C^1$


Derive a simpler expression for $\gcd(a+b,\text{lcm}(a,b))$?

Question: Let $a$ and $b$ be two positive integers, such that neither $a$ nor $b$ is divisible by a perfect square. Is there be a simplified formula for
$$\gcd(a+b,\text{lcm}(a,b)) ?$$ and is there a way to find if this result is divisible by a perfect square or not?
Answer: Let $a=\prod p_i\prod q_j$ and $b=\prod p_i\prod r_k$ where $p_i,q_j,r_k$ are distinct primes.
So, $lcm(a,b)=\prod p_i\prod q_j \prod r_k$ and $\gcd(a,b)=\prod p_i$
So, $\gcd(a+b, lcm(a,b))=\gcd(\prod p_i(\prod q_j+ \prod r_k),\prod p_i\prod q_j \prod r_k)$
$=\prod p_i\gcd(\prod q_j+ \prod r_k,\prod q_j \prod r_k)$
Now, $\gcd(\prod q_j+ \prod r_k,\prod q_j)=\gcd(\prod r_k,\prod q_j)=1$ as $q_j,r_k$ are distinct primes.
Similarly, $\gcd(\prod q_j+ \prod r_k,\prod r_k)=1$
Consequently, $\gcd(\prod q_j+ \prod r_k,\prod q_j \prod r_k)=1$
$\gcd(a+b, lcm(a,b))=\prod p_i=\gcd(a,b)$
Answer: Lemma: If $\gcd(x,y)=1$ then $z=\gcd(x+y, lcm(x,y))=1$. Proof: If $p$ divides $z$, then $p|x+y, lcm(x,y)$. Since $p|lcm(x,y)$ we have either $p|x$ or $p|y$. Together with $p|x+y$ we find that necessarily $p|x,y$, i.e. $p|\gcd(x,y)=1$. This establishes the lemma. $\blacksquare$
Let $g=\gcd(a,b)$. Now you can just write
$$\gcd(a+b, lcm(a,b)) = g\gcd(\frac{a}{g}+\frac{b}{g}, \frac{lcm(a,b)}{g}) = g\gcd(\frac{a}{g}+\frac{b}{g}, lcm(\frac{a}{g},\frac{b}{g}))$$
(we've used the fact that both $\gcd$ and $lcm$ are homogeneous: $\gcd(cx,cy)=c \cdot \gcd(x,y), lcm(cx,cy)=c \cdot lcm(x,y)$)
And, by the lemma, since $\frac{a}{g}, \frac{b}{g}$ are coprime by construction, we have that this expression equals $g\cdot 1=\gcd(a,b)$.
So if $a,b$ are both squarefree, so is $\gcd(a,b)$, which is the value in question.


Are CUDA_VERSION and CUDART_VERSION necessarily the same?

Question: The CUDA Driver API defines CUDA_VERSION (in cuda.h), and the CUDA Runtime API defines CUDART_VERSION (in cuda_runtime_api.h). However - CUDART_VERSION is not defined as CUDA_VERSION but directly as a number.
Are they always supposed to have the exact same value, or are there circumstances in which they might differ?
Answer: They will be the same observationally, but not linked.
As you already know at runtime, the CUDA version can be different than the CUDART version.  Therefore (or, insofar as that answer describes) there is no connection between the two.
However, both cuda.h and cuda_runtime_api.h will be installed by a CUDA installer.  So with respect to what that installer installs, they will match.  The installer installs both a driver and a development environment where the CUDA (driver API) version and CUDA runtime API version match.  But later on that can change (if you update the driver, for example.)  That is to say, the runtime versions can change depending on subsequent install activity. In any event, the cuda.h installed by the CUDA toolkit installer and the cuda_runtime_api.h installed by the CUDA toolkit installer will be as installed by the toolkit installer.
cuda_runtime_api.h does not depend on cuda.h. For that reason, one define is not simply a define of the other.  You can build CUDA runtime API applications that don't depend on cuda.h (the deviceQuery sample code is an example) and so there is no reason for cuda_runtime_api.h to build a define based on something in cuda.h - that would require you to always include cuda.h whenever you include cuda_runtime_api.h, and the CUDA designers had no intention of that.
Comment: `That is to say, the runtime versions can change depending on subsequent install activity.`
I feel this sentence is a little contradictory under the context.
1. If the `subsequent install activity` means installing the CUDA toolkit, it is contradictory to the next sentence,
`But the cuda.h installed by the CUDA toolkit installer and ... will remain what they were, ...`.
2. If the `subsequent install activity` means updating the GPU driver, it is contradictory to itself `the runtime versions can change` because updating driver doesn't change the CUDA Toolkit(including the CUDA Runtime).
Comment: I've made some wording changes.  The toolkit installer can/will install both header files.  For each install instance, the header files will be of a version that matches the installer version.
Comment: `the CUDA version` in your answer means the driver API version(installed by NVIDIA driver), `CUDA_VERSION` in the question is just a define in the `cuda.h` header file(installed by NVIDIA Cuda Toolkit).
`CUDA_VERSION` and `CUDART_VERSION` in the header files denote runtime API versions, independent of the driver API version.
Is it correct?


How to use barcode scanner sensor in Honeywell EDA70 Android PDA Device

Question: I am developing an app for PDA device (Honeywell EDA70) and i don't know how to access the physical Barcode scanner in it. Until now I only used barcode scanning using Camera not that physical sensor.
What i have tried:

Tried to search sample codes but didn't find any

What i want:

I'd like to know how to do barcode scanning with the physical sensor for that specific device, including any SDKs I need to download.
If possible, I'd like to have example code that implements scanning in such devices in general.
Comment: have you tried to contact the manufacturer ?
Comment: they didn't respond
Answer: I'am late, but atleast for someone else. Scanner should be like a keyboard - if you focus on any textfield and press scanning button, the barcode will appear.
Comment: dose it works like that? I didn't take the project because of the issue that I am facing
Comment: yes, it does. most of these hardware scanners are just external keyboards.
Comment: okay. thanks for your answer. this may be helpful for some other people as well.