How to override form element templates from custom module

Question: I have a custom field with some radio inputs and the following (widget-)output right now:

  <input />

For every radio single radio input(In my case 5 times - back 2 back). Can I remove the outer
 without actually touching any themes (neither the stable theme nor my custom theme) ?
Answer: Got it working. First you have to copy the default form element template into your module's /templates folder. For example:
$ mkdir -p modules/custom/MYMODULE/templates
$ cp core/themes/stable/templates/form/form-element.html.twig modules/custom/MYMODULE/templates/form-element.html.twig

Now rename it to something you want. For example:
$ mv modules/custom/MYMODULE/templates/form-element.html.twig modules/custom/MYMODULE/templates/form-element--foo.html.twig

Edit the file to match your needs. For example remove or change the

 tags. Finally in your module's MYMODULE.module file add the following two hooks.
/**
 * Implements hook_theme_suggestions_HOOK_alter().
 *
 * This hook adds a new theme suggestion for all radio form elements.
 */
function MYMODULE_theme_suggestions_form_element_alter(array &$suggestions, array $variables) {

  if ($variables['element']['#type'] == 'radio') {
    $suggestions[] = 'form_element__foo';
  }
}

/**
 * Implements hook_theme().
 *
 * This hook registers a new theme in your module. It will
 * automatically look for the template in your module's /templates folder.
 */
function MYMODULE_theme($existing, $type, $theme, $path) {

  return [
    'form_element__foo' => [
      // base_hook is important!
      // Otherwise your template won't know what to render.
      'base hook' => 'form_element',
    ],
  ];
}

Only thing left, I find, is to have the form ID added to the template suggestion as well, so that we could target only this one form's elements. As now this template will be taken into account for all radio form element wrappers. Independent from what form they are in. But unfortunately I couldn't find the form ID inside the form_element's $variables.

Hah, you simply could add a class to your radios and identify them by that later.
$form['radios'] = [
  '#type' => 'radios',
  // ...
  '#attributes' => ['class' => ['foo']],
];

And then the hook_theme_suggestions_HOOK_alter could look like that:
/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function MYMOUDLE_theme_suggestions_form_element_alter(array &$suggestions, array $variables) {

  if ($variables['element']['#type'] == 'radio' && in_array('foo', $variables['element']['#attributes']['class'])) {
    $suggestions[] = 'form_element__foo';
  }
}

Now the custom template would only be taken into account for your specific radios.
Comment: If a parent theme hooks the "theme_hook_original", this wont work because your suggestion defined in a module wont be prioritized. In order to make it work, you need to add the hook in your .theme file. Function will then follow the same logic : MYTHEME_theme_suggestions_form_element_alter()


Kahler form lies in $H^2(X,\mathbb Z)$?

Question: $X$ is a Kahler manifold. Then is it true that the class of Kahler form $[\omega]$ lies in $H^2(X,\mathbb Z)$?
In fact I am not sure I understand $H^2(X,\mathbb Z)$ correctly. Why can we talk about $H^2_{dR}(X,\mathbb Z)$? Because I don't think "forms with integer coefficients" is well-defined.

Edit
I didn't make question clear. As Tsemo Aristide's answer suggests, if $\omega$ is a kahler form, then so is $c \omega$. So I really want to ask is: can we always find a $c$ such that $c\omega$ lies in $H^2(X,\mathbb Z)$?
Comment: No, it is a $2$-form. Elements of $H^n (X , \mathbb{Z})$ are classes of $n$-forms (assuming $n \neq 2$).
Comment: Not in general. When it does it is sometimes called a Hodge Manifold. It is an important special case because of the Kodaira embedding theorem.
Comment: @UserX Yes. One way to get an idea of how they are related is to consider the exponential sequence $0 \to \mathbb{Z} \to {\mathcal{O}_X}\mathop  \to \limits^{\exp } {\mathcal{O}_X}^ \times  \to 0$. Taking the LES of sheaf cohomology, and using the identification ${H^1}\left( {X,{\mathcal{O}_X}^ \times } \right) \cong Pic\left( X \right)$, we get a map $Pic\left( X \right)\mathop  \to \limits^{{c_1}} {H^2}\left( {X,\mathbb{Z}} \right)$. The image of that positive line bundle under this map should be the same as the cohomology class of the Kahler form.
Comment: TypIcally these types of questions really mean: 1. Show that $\omega$ is closed and 2 Show that $[\omega] \neq 0$. The Kahler form is closed (it is symplectic), and if you look at the class of the top wedge power of $\omega$ this must be nonzero. Thus $[\omega] \neq 0$.
Comment: @Rellek But does it lie in $H^n(X,\mathbb Z)$?
Comment: @Rellek Yes but I mean $n=2$.
Comment: @Jake Thanks! One more question: I saw two "Kodaira embedding theorem". One is as you stated and another is with the condition that there exists a positive line bundle. Are they the same?
Comment: @Jake Very helpful. Thank you!
Answer: Sorry for my late reply ,there is a more general theorem to describe this fact,by Huybrechts'Complex Geometry 5.3 Kodaira Embedding theorem Corollary 5.3.3,we have
A compact Kähler manifold $X$ is projective if and only if $\mathcal K_X\cap H^2(X,\mathbb Z)\not=\emptyset .$
Here $\mathcal K_X$ denotes the Kähler cone,so we can find counterexample from non-projective manifolds,such as some complex torus,neither Kähler class associated to any Kähler structure lies in $H^2(X,\mathbb Z)$.
Answer: Consider the $2$-torus endowed with its standard Kahler form $\omega $. Let $i$ be any irrational number $i\omega$ is also a Kahler for the same complex structure but is not in $H^2(\mathbb{T}^2,\mathbb{Z})$.
Comment: Thanks for your answer!  But can we find a $c$ such that $c \omega$ lies in $H^2(X,\mathbb Z)$? (I edited the question)

Kahler form lies in $H^2(X,\mathbb Z)$?


Is inversion of an irrep equivalent to inversion of the corresponding group element?

Question: If $g\in G$ and $R:G\rightarrow GL\left(V\right)$ is the matrix form of an irreducible representation of $G$ then is the following statement true?
$R^{-1}\left(g\right)=R\left(g^{-1}\right)$
Where the left hand side corresponds to matrix inversion of the irrep of $g$ and the right hand side corresponds to the irrep of the inverse of $g$.
Comment: I'm fairly new to group theory and representation theory, but as I understand the definition it simply states that the relationship between group elements is preserved, i.e. $R\left(g_1 g_2\right)=R\left(g_1\right)R\left(g_2\right)$. Does this imply something about the operation of inversion?
Answer: I assume that you want to consider $R(g)$ as a matrix in $GL_n(F)$. So you are really saying that $R: G \to GL_n(F)$. The question now is whether $R(g^{-1}) = R(g)^{-1}$. Here $g^{-1}$ is the inverse in the group $G$ and $R(g)^{-1}$ is the inverse as a matrix (so the inverse in the group $GL_n(F)$.
Remember that $R$ is a group homomorphism by definition. So you indeed have $$R(g^{-1}) = R(g)^{-1}.$$


ARIMA Model Changing With New Data

Question: I developed an ARIMA model with errors (https://robjhyndman.com/hyndsight/arimax/) to forecast the GDP growth of a small region. The issue is that the GDP values of past quarters and years change according to the corrections of the official statistical authority of the country, causing the model to change as well (e.g. the first model with the lowest AIC used to be an ARIMA(0,1,3), now with the new data it is an ARIMA(4,1,1)). My question now is how should I keep going? Should I stuck to the initial model or adapt the forecasts according to the new suggested model?
Thank you for any suggestion
Answer: The updated data is presumably more correct, so it appears like a model fitted to the updated data is likely closer to the true data generating process, as well. So I would use the new model.
Then again, large changes in the forecast (note that different models may give forecasts that are not very different, at least at short horizons) would be a cause for concern. So I would at least take a look at the differences in the forecasts from the two models.
If two (or more) models are so equally reasonable that small changes in the data may make auto.arima() jump from one model to the other, it may also be worthwhile to use both models, by averaging the forecasts. As long as the order of integration is the same, you can also compare AICs and potentially use the AICs in a weighting scheme (e.g., Kolassa, 2011, IJF - sorry for the self-promotion). Note, however, that investing a lot of time in finding "optimal" weights may not help a lot (Claeskens et al., 2016, IJF).
Finally, if you have the time, you could also disable some of the computational shortcuts that auto.arima() takes, which may give you yet other models to play with, by setting stepwise=FALSE and/or approximation=FALSE.

ARIMA Model Changing With New Data


problem grabbing input value and putting it into span

Question: I know there are already some discussions about this topic, but I can't find the right solution.In all the approaches you just grab your span and your inputfield, then call a new variable input value and then ,using text content = value it should work, but in my case it doesn't.Probably I'm missing something.This is my html

Clock settings

                Time(in minutes)

                        Pomodoro
                        <input  id="time-study-input "type="number" min="0"step="1" value="40">

                        Short Break
                        <input id="short-break-input "type="number" min="0" step="1" value="5">

                        Long Break
                        <input id="long-break-input "type="number" min="0" step="1" value="15">

                <button id="save-changes" onclick="savechanges()">Save changes</button>

        <button id="settings-button">Settings</button>

this is script.js(probably you don't need css)
const settings_panel = document.getElementById("settings-panel");
const settings_button= document.querySelector("#settings-button");
const wrapper = document.getElementById("wrapper");
const close_button = document.getElementById("close-button");
const body = document.querySelector("body");
const big_wrapper = document.getElementById("big-wrapper");
var time_study_input = document.getElementById("time-study-input");
var short_break_input = document.getElementById("short-break-input");
var  long_break_input = document.getElementById("long -break-input");
var  countdown_timer_study= document.getElementById("countdown-timer-study");

settings_button.addEventListener("click", ()=>{
    settings_panel.style.display="block";
    wrapper.style.backgroundColor ="rgba(0,0,0,0.3)";
})

close_button.addEventListener("click", () => {
    settings_panel.style.display = "none";
    wrapper.style.backgroundColor = "rgba(221, 217, 217, 0)";
})

function savechanges(){
    var time_study_value = time_study_input.value;
    countdown_timer_study.textContent =time_study_value;
    settings_panel.style.display = "none";
    wrapper.style.backgroundColor = "rgba(221, 217, 217, 0)";
}

as you can see I am trying to build a pomodoro app so when the user wants to customize the timer I can grab the input value and insert it into the span that is going to represent the time limit(as you can see I also setup a default value of 40, is this the right way to do it?).I am trying to improve my front-end skills which are definitely terrible, so any tip about code simplification (pointing out which parts are redundant or inefficient) is very welcome.
Comment: In each of the id's of the input tag there is a subtle space in the end, that's not matching the getElementById in javascript. Just remove the spaces and they should work just fine
Comment: Using your browser's dev tools inspect facility can pick this sort of thing up. Looking at the console log should show an error.
Answer: Your problem is extremely subtle. You have an extra space at the end of the id time-study-input. Try this:

    Pomodoro
    <input id="time-study-input" type="number" min="0"step="1" value="40">


Dynamic sortBy with Slick 3

Question: I'm attempting to dynamically include a sortBy to my query which sorts based on its string name from a query parameter. In Slick 3 this has proven to be quite tricky. Currently my setup is:
trait Model {
    type ATable <: AbstractTable[_]

    def tableQuery: TableQuery[ATable]

    def sortMap: Map[String, Rep[_]]

    private def sortKey[T](e: ATable, sort: (String, SortOrder)): ColumnOrdered[_] = sort match {
       case (field, SortOrder.Asc) => ColumnOrdered(sortMap.getOrElse(field, throw new ClientException(s"Can't sort by $field")), Ordering(Ordering.Asc))
       case (field, SortOrder.Desc) => ColumnOrdered(sortMap.getOrElse(field, throw new ClientException(s"Can't sort by $field")), Ordering(Ordering.Desc))
    }
    def all(sort: (String, SortOrder)) = tableQuery.sortBy(sortKey(_, sort)).result
}

object User extends Model {
    type ATable = Tables.User
    val tableQuery = Tables.User

    val sortMap = Map( "id" -> tableQuery.id )
}

But running db.run(User.all(("id", SortOrder.Asc)) throws the following error:
slick.SlickException: No type for symbol name found in Vector[t2<@t3<UnassignedType>>]

Does anyone know of a better solution or where I'm going wrong?
Answer: The way I solved this was to change my sortMap to contain the table type with column type implicit (from Map[String, Rep[_]] to Map[String, ATable => Rep[_]]):
trait Model {
    type ATable <: AbstractTable[_]

    def tableQuery: TableQuery[ATable]

    def sortMap: Map[String, ATable => Rep[_]]

    private def sortKey(baseQ: Query[ATable, ATable#TableElementType, Seq], sort: (String, SortOrder)) = {
       val rep = sortMap.getOrElse(sort._1, throw new ClientException(s"Can't sort by ${sort._1}"))
       val orderedRep = sort._2 match {
          case SortOrder.Asc => (t: ATable) => ColumnOrdered(rep(t), slick.ast.Ordering(slick.ast.Ordering.Asc))
          case SortOrder.Desc => (t: ATable) => ColumnOrdered(rep(t), slick.ast.Ordering(slick.ast.Ordering.Desc))
       }
       q.sortBy(orderedRep)
   }

   def all(sort: (String, SortOrder)) = sortKey(tableQuery, sort).result
}

object User extends Model {
    type ATable = Tables.User
    val tableQuery = Tables.User

    val sortMap = Map( "id" -> { (t: ATable) => t.id } )
}

The only suboptimal aspect of this solution is that if a new column is added to the database it has to be manually added to the sortKey. I'm looking into including these maps in the table code generation scripts.
Answer: You just need to include in generation something like
val columns =  Map( "id" -> { (t: User) => t.id } )

and use it like so:
class UserDAO{
//...
baseQuery = filterContext.sort.foldLeft[Query[User, UserRow, Seq]](User) ((_, s) => UserColumnFilter.getSort(s,User.baseTableRow.columns));
//...
}

case class Sort(columnName:String,value: String) {}

case class FilterContext(filters:List[Filter],page:Int,pageSize:Int,sort:List[Sort])
    object UserColumnSort extends ColumnSort[User,UserRow](User)
    class ColumnSort[T<:Table[C],C](query:TableQuery[T])
    {

      def getSort(s:Sort,columns:Map[String, T => Rep[_]]):Query[T, C, Seq] =  {
        val aux = columns.getOrElse(s.columnName, throw new Exception(s"Can't sort by ${s.columnName}"));
          val orderedRep = s.value match {
              case "asc" => (t: T) => ColumnOrdered(aux(t), slick.ast.Ordering(slick.ast.Ordering.Asc))
              case _ => (t: T) => ColumnOrdered(aux(t), slick.ast.Ordering(slick.ast.Ordering.Desc))
           }
           return query.sortBy(orderedRep);

      }
    }

Dynamic sortBy with Slick 3


Plotting the results of GLM in R

Question: I have this data plotted as a scatter plot in Excel:

I had done a regression in Excel, and the p value was 2.14E-05 while the R- value was 0.32. I was told the R value was too low compared to the significance of the p value, and was told to control for the dispersion of the data by running it through R with GLM with quasipoisson error.
This gave me
glm(formula = encno ~ temp, family = quasipoisson(link = log),
    data = encnotemp)

Deviance Residuals:
   Min      1Q  Median      3Q     Max
-6.008  -2.431  -1.021   1.353   9.441

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.005807   0.174628  11.486  < 2e-16 ***
temp        0.029065   0.006528   4.453 1.53e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for quasipoisson family taken to be 10.19898)

    Null deviance: 1807.4  on 171  degrees of freedom
Residual deviance: 1620.1  on 170  degrees of freedom
AIC: NA

Number of Fisher Scoring iterations: 5

How do I analyse this output?
The problem is that the scatterplot data is too dispersed, and I would like to make a scatterplot from the quasipoisson GLM output that shows less dispersed (more fitted) data points. Will this be possible?
Comment: .Do you have exact zeros?
Comment: Simulation from the fitted glm indicates that the quasi model doesn't describe the spread of the data well; the variance function doesn't increase quickly enough.
Answer: "I was told the R value was too low compared to the significance of the p value" -- sounds like nonsense to me.
On the other hand, some form of glm may be a good idea (but it looks to me like the spread may be increasing more than you might expect with a quasipoisson).
Note that nothing about the glm changes the spread of the data -- it only models changing spread (in a particular way). The data are still the data and if you plot them will still look as they do.
You can change the appearance of the data via a transformation. One that approximately stabilizes variance when the Poisson parameter is not very small is $\sqrt{y}$. If the Poisson parameter can take small values, you may like to try $\sqrt{y+\frac{3}{8}}$ or $\sqrt{y}+\sqrt{y+1}$ instead (it looks to me like that might well be the case that you have small values).
On the other hand, one that would linearize your fitted model would be a log (but that's only suitable if you don't have exact zeros).
--
Although it won't be satisfying to you, you can plot the fitted curve via
plot(temp,encno,xlim=c(0,60))
newdat <- data.frame(temp=seq(9,48,.5))
encnoglm1 <- glm(formula = encno ~ temp, family = quasipoisson(link = log),
                     data = encnotemp)
fit <- predict(encnoglm1,newdata=newdat,type="response")
lines(fit~temp,data=newdat,type="l",col=4)

Or if you want to look at what would be a nearly constant variance if the quasipoisson were suitable:
 plot(temp,sqrt(encno+3/8),xlim=c(0,60))
 lines(sqrt(fit+3/8)~temp,data=newdat,type="l",col=2)

Comment: It would be useful if whoever thinks my answer is wrong could post a comment so that I can see about improving it.
Comment: A low $R^2$ -- even a *zero* $R^2$ doesn't indicate a bad model. You can get zero $R^2$ with the exact model that generated the data. Conversely a very high $R^2$ doesn't indicate that the model is suitable. Actually Cosma Shalizi (among others, including many people who answer here) says pretty much the same stuff I tell people -- take a read from p17 [here](http://www.stat.cmu.edu/~cshalizi/mreg/15/lectures/10/lecture-10.pdf)
Comment: It doesn't matter whether you're talking about the correlation between data and fit or its square, since the same arguments apply. But the slope of the line is not the same as the correlation (at least not unless you standardize your variables).
Comment: Great thank you for your reply :)
I think the r value being too low was meaning that the r value (slope of the trendline) was not significant enough (apparently anything under or around 0.3 is very weak correlation) even though the p value is high. So I am not really sure what is going on here.
I have tried plotting a log transformed data in R but still got a plot showing weak trend and data points that were highly spread out everywhere, but then there are a few exact zeros in the dependent variable data which I should probably fix before trying to log transform again.
Comment: If you have exact zeros I'd avoid the log. If you want to fix the spread in the plot one of the square root ones should work fairly well, and you can still plot the fitted curve from the glm on it.
Comment: Oh I should clarify that the r value Im talking about is the correlation coefficient r, not the r squared value. I think the correlation coefficient is how much the data relate to one another, so pretty much the slope of the trendline?
Great thank you I will try the square root transform :)

Plotting the results of GLM in R


Question on equivalence of definitions regarding convergence with respect to a measure

Question: I have been asked a question about the convergence with respect to measures,and the definition they used was the following: $f_n$ converges to $f$ w.r.t. $\mu$ exactly when $\mu \{x \in X: f_n(x)$ does not converge to $f(x)$ $\}$ $= 0$. The definition I have however is $\mu \{x \in X: |f_n(x)-f(x)|\geq \epsilon\}$ $= 0$. Assuming these are equivalent, I tried to see how they are. I clearly am getting something wrong here, but I started this way: Remembering the definition of convergence of sequences: for every $\epsilon$ $>0$ there exists an $N_{\epsilon}$ $\in \mathbb{N}$ with $|a_n-a|<\epsilon$ for all $n \geq N_{\epsilon}$. This should then mean that "non convergence" means: There exists an $\epsilon > 0 $ with $|a_n-a| \geq \epsilon$ for all $n \in \mathbb{N}$. This then leads to (regarding the first definition) $\mu \{x \in X: |f_n(x)-f(x)| \geq \epsilon$ for one $\epsilon >0$ for all $n \in \mathbb {N}$}$= 0$. This should be the same as saying there exists an $\epsilon > 0$ with $\mu (\cap$ over all $n\in \mathbb{N}\{x \in X: |f_n(x)-f(x)| \geq \epsilon$}$)= 0$. If I knew that $\mu$ would be finite for all of those sets and the sequence of the sets is decreasing, I could simply rewrite this with the limit and almost reach the form of the 2nd definition, the difference being that I wrote "there exists one(!) epsilon, not for all epsilon (...). Did I do something wrong, or is the other defintion just more strict in a way? Furthermore, if I am correct, in order to write it in the form I mentioned, why would $\mu$ be finite for all the sets and why would the series of the sets be decreasing in general? I appreciate any help. Thank you in advance!
Answer: The first one is called almost everywhere convergence and the second one is called convergence in measure. They are not equivalent even if $\mu$ is a finite measure.
Arrange the intervals $[\frac {i-1} {2^{n}}, \frac i {2^{n}})$ in sequence. On $[0,1)$ with Lebesgue measure this gives an example of sequence which converges in measure but not almost surely.
Comment: I see, thank you very much!


Como apontar todas as páginas do site para uma página só?

Question: Estou precisando de uma solução em htaccess que aponte todas as páginas do site para uma página específica do tipo:
http://meusite.com.br/pagina1.html -> http://meusite.com.br/index.php
http://meusite.com.br/pagina2.html -> http://meusite.com.br/index.php
http://meusite.com.br/pagina3.html -> http://meusite.com.br/index.php
http://meusite.com.br/pagina4.html -> http://meusite.com.br/index.php
http://meusite.com.br/pagina5.html -> http://meusite.com.br/index.php

Gostaria de apontar todas as páginas para a home porque todo o site é em html e o único lugar que eu consegui um .php para redirecionar para outro site foi na home.
Answer: Você pode usar:
RewriteEngine on

RewriteRule ^(.*)$ /index.php [R=permanent,L]

Fonte
Answer: Recomendo criar um sistema de rotas, como mostrado aqui:
http://rberaldo.com.br/urls-amigaveis-sem-htaccess-usando-slim/
Seu .htaccess terá só isto:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

O resto será programado na index.php, que tomará conta de redirecionar para o local correto


Which kind of bow fits my needs

Question: I'm an archery beginner and I'm a bit overstrained by the massive supply of different bows.
I'm 1,94m tall, want to use "intuitive shooting" (I hope this is the right term) and intermediated sporty.
Okay, what I've found out so far is, that a "recursive bow" is the most modern bow for this discipline. However, I'm a little bit afraid that this bow is already too modern for me. I really want to have a pretty basic experience. Is this possible with this kind of bow?
Example for this kind:

Size: 70"
Pull weight: 32 lbs

Another example is such a "Manaubow" which raises the impression of being more traditional.

Okay, here are my questions. Which size and pull weight should a bow have for me? Are the 70" and 32 lbs ok? Is a "recursive bow" able to provide a basic traditional experience or would something like a "Manaubow" be the better choice?
Thank you so much!
Answer: I would recommend going to an achey club and asking to try some of their bows. At the very least, go to an archery shop to try before you buy.
Type: a recurve bow, also known as Olympic, is probably a bit more beginner friendly. It has a rest for the arrow to sit on; with a longbow the arrow rests on the bow hand and often the fletches hit the hand on the way past, sometimes injuring the hand. A recurve has more choice for expansion with the addition of a sight, a long rod and a clicker, but you can also shoot "barebow" without these gadgets, at which point the experience is much closer to longbow.
Size: depends on your height and draw length. I can't advise this over the Internet. Go to a club or shop and ask them for advice.
Draw Weight: this depends on your strength. You will need to try shooting with a variety of weights to see what is comfortable. If you're learning, you're likely to improve quite quickly and progress from a lighter draw weight to a heavier one over the first few months. This is why it can be useful to shoot with a club where you can borrow a range of bows while you're learning.
Answer: The answer above is perfect but I just want to add something for the additional information.
As far as I concern, "intuitive shooting" also means "Instinctive Archery"
Just like football, the player kicks the ball to pass to another player. Actually, the player doesn't need to have a proper mechanism to aim to another player, but based on his experience the way he kicks actually goes to exactly as he intends to do.
In this case, you can use whatever bow including the modern compound bow (of course you need to take out the sight tool) BUT the best of course whether the longbow or recurve bow. Before the modern era, every archer did the instinctive archery.
For a taller person like you, based on what I talked with some senior archers, draw length is the real problem that you need to take into account. This is because sometimes we heard people said that arm span is the same as the height. Then some people can buy the bow via online based on the bow specs. But actually that is not true, you can read this scientific research here.
All in all, the ultimate solution, you need to try yourself at the archery shop/club and get the best timing for yourself in term of draw length and also draw weight. You can read here to understand the basic thing about recurve bow and determine the length of the bow that suits you.

Which kind of bow fits my needs


How is `exact` lookup different from `equal` lookup in Django

Question: How is exact lookup diffferent from equal lookup in Django
I have two queries
Blog.objects.get(title=title)

Blog.objects.get(title__exact=title)

What is the difference between these two?
Comment: Possible duplicate of [In Django filter statement what's the difference between \_\_exact and equal sign (=)?](http://stackoverflow.com/questions/9963200/in-django-filter-statement-whats-the-difference-between-exact-and-equal-sign)
Answer: There is no difference, the first one is the exactly same as second one.
Look at documentation:
Blog.objects.get(id__exact=14)  # Explicit form
Blog.objects.get(id=14)         # __exact is implied

Answer: exact is the default.
Check the django documentation:

If you don't provide a lookup type – that is, if your keyword argument doesn't contain a double underscore – the lookup type is assumed to be exact.


strange workflow in ado.net with vb.net

Question: i had assigned a job for insert,update, delete operation in a table for my student. he had done this assignment fine. but his code is made me crazy that he wrote update code like below
Working sample:
Public Function Toeditdetails(ByVal item As Boolean)

        If item = True Then

            Dim con As SqlConnection
            'Dim retval As Integer

            con = New SqlConnection(conn)
            con.Open()
            Dim cmd As SqlCommand
            cmd = New SqlCommand("updatelogin", con)
            cmd.CommandType = CommandType.StoredProcedure

            cmd.Parameters.Add(New SqlParameter("@username", SqlDbType.VarChar, 100)).Value() = TextBox1.Text.Trim()
            cmd.Parameters.Add(New SqlParameter("@user_password", SqlDbType.VarChar, 30)).Value() = TextBox2.Text.Trim()
            cmd.Parameters.Add(New SqlParameter("@nameofuser", SqlDbType.VarChar, 100)).Value() = TextBox3.Text.Trim()
            cmd.Parameters.Add(New SqlParameter("@contact_no", SqlDbType.VarChar, 10)).Value() = TextBox4.Text.Trim()
            cmd.Parameters.Add(New SqlParameter("@email", SqlDbType.VarChar, 100)).Value() = TextBox5.Text.Trim()
            cmd.Parameters.Add(New SqlParameter("@joiningdate", SqlDbType.Date)).Value() = DateTimePicker1.Value
            cmd.Parameters.Add(New SqlParameter("@usergroup_id", SqlDbType.Int)).Value() = SelectedID(ComboBox1.Text)

            If item = True Then
                cmd.Parameters.Add(New SqlParameter("@id", SqlDbType.Int)).Value() = Label9.Text.Trim()
            End If

            Dim da As SqlDataAdapter
            da = New SqlDataAdapter(cmd)
            Dim dst As New DataSet
            da.Fill(dst)

            If dst.Tables.Count > 0 Then
                DataGridView1.DataSource = dst.Tables(0)
            End If

            If Not cmd Is Nothing Then
                cmd.Dispose()
            End If
        End If

End Function

Note there is no ExecuteNonQuery() method for his SqlCommand object and he didn't call this method in entire project. when i call function result still updating... how its happen? anyone genius can you explain whats going on above statement? any help would be appreciated
Regards and thanks
Sarva
Comment: It's a stored procedure
Comment: yes  OneFineDay. please read my comment in first answer
Answer: when you call Toeditdetails method it will execute stored procedure called updatelogin
check the stored procedure and you may able to find why you receive updated result. Stored procedure several statements like below
update table1 set username ='test1' where uid =@uid;
select * from table1;

when you call stored procedure with above code you will get the table1 data but update statement will update data before you receive it.
Comment: when you call `da.Fill(dst)` that Stored procedure will execute and fetch the data, no need to call `ExecuteNonQuery`
Comment: i agree with you Damith . but he didn't call there cmd.ExecuteNonQuery(). so only im confused. it should not affect until call this cmd.ExecuteNonQuery() statement. but it works . how?
Comment: thanks for your reply and i didn't noticed that sorry

strange workflow in ado.net with vb.net


CXF-Jetty error: java.lang.IllegalStateException: No SessionManager

Question: JUnit test case for CXF JAXRS rest service giving below error (found couple of solutions for programmatic configuration but looking solution for spring xml configuration)-
Caused by: java.lang.IllegalStateException: No SessionManager
at org.eclipse.jetty.server.Request.getSession(Request.java:1402)

Junit annotations-
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:test-spring-context.xml"})

spring configuration for jaxrs server-
<jaxrs:server id="testServer" address="http://localhost:9191/$$$/service">
    <jaxrs:inInterceptors>
        <ref bean="cxfRestInInterceptor" />
    </jaxrs:inInterceptors>
    <jaxrs:outInterceptors>
        <ref bean="cxfRestOutInterceptor" />
    </jaxrs:outInterceptors>
    <jaxrs:serviceBeans>
        <bean class="$$$" />

    </jaxrs:serviceBeans>
     <jaxrs:features>
        <ref bean="swagger2Feature" />
    </jaxrs:features>
    <jaxrs:providers>
        <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
        <bean class="$$$" />
        <bean class="$$$">
            <property name="authenticationProvider" ref="authenticationProvider"/>
        </bean>
        <bean class="$$$"></bean>
        <bean class="$$$"/>
    </jaxrs:providers>
    <jaxrs:extensionMappings>
        <entry key="json" value="application/json" />
    </jaxrs:extensionMappings>
</jaxrs:server>

Answer: Below configuration solved the issue http://cxf.apache.org/docs/jetty-configuration.html-
    <httpj:engine-factory bus="cxf" id="port9191">
    <httpj:engine port="9191">
        <httpj:threadingParameters minThreads="5"
            maxThreads="15" />
        <httpj:handlers>
            <bean class="org.eclipse.jetty.server.handler.DefaultHandler" />
        </httpj:handlers>
        <httpj:sessionSupport>true</httpj:sessionSupport>
    </httpj:engine>
</httpj:engine-factory>


The set of functions from a set to a set is finite if given sets are finite?

Question: Let $A,B$ be finite sets, Can we conclude that $B^A $( the set of all functions from $A$ to $B$ ) is finite ?
if we assume $|A| = m $ and $|B| = n $, then we are being asked number of functions from $A$ to $B$ which is $(n+1)^m $ and so $B^A$ is finite. is this correct?
Comment: @Regret happens even to the best of us!
Answer: $B^A$ is finite it's a correct answer its cardinal is exactly $|B|^{|A|}$ and so the first part is not correct.

Let $A=\{x_1,\cdots,x_m\}$ and define $\phi:B^A\to B^m$ , $$\phi(f)=(f(x_1),\cdots,f(x_m))$$
  claim: $\phi$ is bijective.

Proof :

$\phi$ is one to one, suppose that $\phi(f)=\phi(g)$ then the equality between the tuples gives us $f(x_i)=g(x_i)$ for all $i\in [1,m]$ so $\forall a\in A\ \  f(a)=g(a)$ which gives us the equality of functions hence $f=g$.
$\phi$ is onto given a tuple $b=(b_1,\cdots,b_m)\in B^m$ let's consider $f_b$ defined form $A$ to $B$ by $f(x_i)=b_i$ for every $i$ hence $\phi(f_b)=b$. so $\phi$ is onto.

As  a consequence of this claim we have $|B^A|=|B^m|=|B|^m$.
I assumed that you already proved in course that $B^m$ is finite and you know its cardianl, this can be done by induction using the basic relation $|A\times B|=|A|\times |B|$


What method to test if the mean is constant?

Question: I have a time series with prices (around 800 prices). I need to test if the mean is constant during all the series.
I think I should subdivide the series in groups, but what method do I have to use to check if the mean is constant if the distribution is not normal?
Comment: I think you need to clarify what you mean by the *mean is constant*. Presumably there is a model that you have in mind in the background and it sounds roughly like it involves a function $\mu(t)$ that defines a systematic change as a function of time, and presumably, also an error term $\varepsilon(t)$ encapsulating the fluctuations around the local mean. Then your question would seem to be: Is $\mu(t) \equiv \mu$? As currently stated, I fear your question is not quite well-posed.
Comment: @Cardinal: Perhaps Dail can clarify, but I took it to mean he wanted to test the mean requirement of weak stationarity, which claims that if $X(t)$ is our time series, then $E(X(t)) = \mu, \forall t$. Undergraduate courses typically test this condition by fitting a linear regression through the series and testing if the slope is zero, but this approach is not valid if the data are not normal. Could you clarify that if this is the case, Dail?
Comment: Yes exactly Christopher.
Answer: You may want to look at a nonparametric approach to this problem, since you cannot rely on normality. Break your sample into two groups, $x_1, \dots, x_{400}$ and $x_{401}, \dots, x_{800}$ and compare them in pairs ($x_1, x_{401}$), $\dots$, ($x_{400}, x_{800}$).
You now have the framework of a two-sample test of equal means/medians. Under the null hypothesis of a constant mean, we should expect the mean/median of these two groups to be the same.
Since we expect the medians to be the same, some NP tests will assert that in the pair $(x_i, x_{i+400})$, the chance that $x_i$ is bigger is a random variable, Bernoulli distributed with probability $\frac{1}{2}$. Two hypothesis tests proceed from this. Tests to look into would be: Wilcoxon Signed Rank Test and the Signed Test.
Comment: I think there is a typo in the indices at the end of the first paragraph.
Comment: @Cardinal. You were correct. Pairings should be $(x_i, x_{i+400})$, $i=1, 2, \dots, 400$.


Find object inside collection of List

Question: I have five strong-typed List objects. Every object inside every List have property Rating and Vote.
How can I select only 10 top rated  object from all List's objects? if Rating equal then need use Vote
Example(select 2 top rated):
List<Film>:

0 element: rating = 1, vote = 2;
1 element: rating = 4, vote = 5;

List<Clubs>:

0 element: rating  = 5, vote = 3;
1 element: rating = 4, vote = 3;

Result: 0 element from Clubs and 1 element from Film
Comment: Are `Rating` and `Vote` properties of an interface that `Film` and `Club` share? If not, you're stuck with reflection or (with C# 4.0 onwards) `dynamic`.
Comment: How do you define the "rating" in terms of `Rating` and `Vote` properties? In other words, what's the *ordering* of items by these two criteria?
Comment: first by Rating, if Rating is equal then compare Vote
Answer: Try something like below
var topTen = yourList.OrderBy(x => x.Rating).ThenBy(z => z.Vote).Take(10)
Comment: Linq is the way to go :) and if list is big or time consuming you can do that in parallel as well :)
Comment: it's only for one collection. Need take from 5.
Answer: You can start with something like:
  var res = l1.Concat(l2).Concat(l3).Concat(l4).Concat(l5)
                    .OrderByDescending(k => k.Rating)
                    .ThenBy(k=>k.Vote)
                    .Take(10).ToList();

where l1...l5 are your lists
Answer: If there is no common sub-class among these element types, you can use LINQ to project the lists using a generic Tuple<int, int, object> (i.e. rating, vote, and the original element instance) containing the two properties you are interested in.  Then you can do a simple query to pick the top 10 elements:
List ax = /* ... */;
List bx = /* ... */;
List<C> cx = /* ... */;
/* ... */

IEnumerable<Tuple<int, int, object>> ratingsAndVotes =
    ax.Select((a) => Tuple.Create(a.Rating, a.Vote, a)).Concat(
    bx.Select((b) => Tuple.Create(b.Rating, b.Vote, b)).Concat(
    cx.Select((c) => Tuple.Create(c.Rating, c.Vote, c)) /* ... */;
Tuple<int, int, object>[] topTenItems =
    ratingsAndVotes.OrderByDescending((i) => i.Item1).ThenByDescending((i) => i.Item2).Take(10).ToArray();
// topTenItems now contains the top 10 items out of all the lists;
// for each tuple element, Item1 = rating, Item2 = vote,
// Item3 = original list item (as object)

Answer: You can use OrderBy and ThenBy to order by two (or more) fields and then use Take to get the top 10:
var myList = new List<Film>();
// ... populate list with some stuff
var top10 = myList.OrderBy(f => f.Rating).ThenBy(f => f.Vote).Take(10);

Hope that helps :)

Find object inside collection of List


Vmware/Linux 64 vs 32 bit

Question: I have some old supermicro servers with over 16GB of ram in them which are still running 32bit version of linux with 2.6.x kernels and vmware on top of it.
I wonder if there is any advantage of upgrading the distro/kernel to a 64-bit Debian.
The only problem is that right now I cannot create 64 bit guest vms in vmware.
I would also like to know that, upgrading this system to 64bit have any performance advantage or maybe the more appropriate question would be that would it have any disadvantage?

Yes indeed it was a VS question and the only reason why I want to have 64 bit guests is btrfs, nothing else. I don't really have database, memcache or other vms which would take advantage of the 64 bit, also none of the VMs have more than 4 gigs of memory. The most I think has is around 2GB.
"32bit only rules in the 4GB or less RAM space" so many of my guests are just fine with being 32bit guests but my host OS which have 24GB ram and runs a 32bit kernel does some PAE tricks to access the memory over the 4GB.
So let me put it this way. If my main goal here is to have faster (or at least not slower) vms, would it be an advantage for the HOST os to be 64 bit? Would it access the memory area faster over 4GB than it does it right now?
Comment: Yes. The PAE addressing is quite slow whenever it happens so the host will benefit from being 64bit.  Also, seeing as you are already on VMware, you should consider switching to ESXi 5.5 free version _if_ your hardware can run it. You can run VMware ESXi off of a 4G USB stick so it's normally an easy test to see if it actually can run and access your disks.
Comment: On a side-note, having a 64b system requires to have some 32bits libraries for compatibility, and thus uses more disk capacity.
Comment: @IanMacintosh Do not run a standalone ESXi host off of a [USB key/SD card](http://serverfault.com/questions/549253/what-happens-when-the-usb-key-or-sd-card-ive-installed-vmware-esxi-on-fails) (*without shared storage*). It's bad advice.
Comment: @ewwhite - to test to see if it actually can run and access your disks (if your hardware is old and doesn't appear on the supported HW list). This leaves your existing system and data intact on a working server - no point in breaking what's working unless you know the replacement will run.
Answer: If you're installing any OS in 2014 on modern hardware without 64-bit capabilities, you're making a bad design decision.
Even with the hardware RAM/CPU footprint you're describing for your VMware Workstation setup, it makes sense to utilize 64-bit versions of your operating system for forward compatibility, future-proofing and the very clear requirement you have for BtrFS 64-bit libraries.
Answer: 64bit is slower and takes more RAM than 32 bit.
64bit addresses larger than 4GB RAM faster than 32bit can address it (and more smoothly). Individual programs can address more RAM natively on a 64bit system. As you already know you can't run a 64bit guest on a 32bit system.
Updated for your comment below:
My answer above was giving a 'vs' answer because you had a 'vs' question. But don't forget that 32bit is limited to 4GB RAM.  That's fine when you have less than 4GB (the bios and memory mapped devices nick some of the 4GB address space).
But when you have more than 4GB RAM then a 32bit system has to resort to 'paging' tricks to address the extra RAM. Your underlying system has more than 4GB of RAM so it will normally go faster because of that.
64bit is slower (and bigger) than 32bit because all the pointers are bigger, take twice the space in memory of the smaller and therefor faster 32bit pointers.
But offset against the slowness when you address the full RAM via paging, you probably find that 64bit is faster for that case.
32bit only rules in the 4GB or less RAM space regardless of whether it is a program or an operating system.
Don't upgrade your guests though unless you have a clear advantage or a need for 64bit in your guests.

I see from downvotes that more people disagree than agree with my statements above. I just happened to be on a site researching an unrelated topic (Linux CC & ITSEC Certification) and noticed this interesting paragraph on the subject:

Going back years we have run 32-bit vs. 64-bit Linux benchmarks. While
  the results seldom change, we keep running them as the question of
  choosing between a 32-bit and 64-bit Linux distribution image is still
  a popular question… These tests drive in a surprising amount of
  traffic and I continue to be flabbergasted by the number of people
  still asking this question when nearly all modern x86 Intel/AMD
  hardware fully supports x86_64 and it generally means much better
  performance. Usually the only caveat in not using a 64-bit Linux
  image is if running a system with less than 2GB of RAM.
  (italics added - see original article)

Seems I'm not the only one doing some actual real world work finding that 64bit isn't always the answer.
Comment: When I found the _actual_ article that provided the quote in your answer, and read it fully, I noticed that it showed equal or higher performance for 64-bit Linux for nearly all benchmarks. And even for less than 2GB, the hassle isn't worth it. I always install 64-bit, everywhere.
Comment: Hello, I guess then you answered my question that this upgrade doesn't worth it in my case. All the VMs would just become slower. I was about to install new vms with btrfs which needs 64bit support, but I wouldn't like to experience that after the upgrade all my vms are slow so I rather won't do it.
Comment: If you are comparing AMD64 to IA32, then you have to take account for the fact that AMD64 having twice as many general purpose registers as IA32 allows for better optimized code. Also having 64 bit instructions means twice as much data can be processed per instruction, which gives a performance benefit for some operations. It is true that 64 bit pointers take up twice as much space, so if the code is heavy on pointers, that can be an issue, and memory bandwidth can become a bottleneck. I think the advantages outweigh the disadvantages.
Comment: Sometimes it does and sometimes it doesn't from my experience. Almost exclusively when accessing less than 2G RAM in a program I found 32bit to have an edge over 64bit. As the compilers improve I suspect that will become less and less true. See [this test](http://stackoverflow.com/questions/2378399/are-64-bit-programs-bigger-and-faster-than-32-bit-versions) where a 32bit program ran in 17s vs 24s for 64bit. And then check all the varying results that others report. I suppose YMMV but in the 2G program area I've not seen 64bit benefit me at all - just my personal experience.

Vmware/Linux 64 vs 32 bit


How can I make an instance of a block of Blockly with Javascript?

Question: I have done the following block with Blockly in a customBlocks.js file:
Blockly.Blocks['move_right'] = {
  init: function() {
    this.appendValueInput("PIXELS")
        .setCheck("Number")
        .appendField("move to right");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(290);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};

Blockly.JavaScript['move_right'] = function(block) {
  var value_pixels = Blockly.JavaScript.valueToCode(block, 'PIXELS', Blockly.JavaScript.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  var codeMoveRight = "$(\"#moveDiv\").animate({\n " +
                        "left: \"+=" + value_pixels + "px\"\n" +
                      "},1000);\n";
  return codeMoveRight;
};

that moves a div to the right depending of how much pixels you set on it. You will have to put a math_number block inside move_right block to put the amount of pixels you want to move it.
I have on my html file a workspace variable that injects the Blockly workspace:
var workspace = Blockly.inject('blocklyDiv',
              {toolbox: document.getElementById('toolbox')});

What I want to do
It is to retrieve from JavaScript this amount of pixels one time the block have been displayed on the workspace of Blockly, not before.
What I have tried

I directly tried to access to the workspace variable from the console of my broser (Google Chrome) and could get the "child blocks" but not the value of them. As follows:
console.log(workspace.topBlocks_[0].childBlocks_);

I also tried to translate the workspace to dom and then to text:
var xml = Blockly.Xml.workspaceToDom(workspace);
var xml_text = Blockly.Xml.domToText(xml);
console.log(xml_text);

and here I can see that the value of the "child Block", I mean, the math_number block, it is stored on the text but I do not know how can I get it.

Why I want to achieve that?
Because what I want it is to check if the user has moved 300 pixels to the right. If so, then I will show a message in which I will put "You get it!".
My question
Is there a posibility to make an instance of that Block that I have put on the workspace and then get access to its pixels value with that instance?
EDIT:
I also could get the left value as @Oriol said doing:
$('#moveDiv').css('left');

but I did not put it here because it is using a property of Jquery (It does not matter at all, because it is a good option too, but not as intended). My intention it is to get an instance of a Block after put it on the Blockly workspace to operate later with it at any time.
Comment: Something like `$('#moveDiv').css('left')`?
Comment: @Oriol Yes, it was the final conclusion I had (I forgot to update the question, I am going to do it now) but I would like to have an instance of a `Block` to operate with it later. Anyway, thank you for your input :)
Answer: There is a method setWarningText to show this kind of warnings. You could modify yor generator as follows:
Blockly.JavaScript['move_right'] = function(block) {
    var value_pixels = Blockly.JavaScript.valueToCode(block, 'PIXELS', Blockly.JavaScript.ORDER_ATOMIC);
    // TODO: Assemble JavaScript into code variable.
    var codeMoveRight = "$(\"#moveDiv\").animate({\n " +
                    "left: \"+=" + value_pixels + "px\"\n" +
                  "},1000);\n";

    // You can show a blockly warning
    if( value_pixels >= 300 ) block.setWarningText("You get it!");

    // Or you can store its value elsewere...
    // myExternalVar = value_pixels;

    return codeMoveRight;
};

This will appear as a warning icon in the block itselfs.
In any case, if you want to "remember" this value_pixels variable, I believe the more easy way is to do it in the generator, as shown above. You can always store it in an external var accessible from your custom functions.
EDIT:
If you need to traverse the block structure for some other purpose, you may use:

Blockly.mainWorkspace.getTopBlocks(true); // To get the top-level blocks
An iteration over the top-level block list
block = block.nextConnection && block.nextConnection.targetBlock(); // To "descend" into the sub-blocks of a block, then iterate over them
if(block.type=="move_right") ... // To check for a particular block type

I hope this will give a start point, but the best way to learn about these "tricks" is reading the Blockly source code. Even as the code is generally well commented, AFAIK there is no way to autogenerate a document, and it is not available on the web neither.
Comment: Yes, what I want to achieve it is to store the value to use it later. I like your option without need to use `Jquery`. Also I like your `setWarningText` if I need in the future to not to store the value but I wanted to know if it is something similar to get an instance of the Blocks displayed on the workspace. Anyway +1 for both points. If anyone answer, the points will also be for you. Thanks!
Comment: I don't undestand completely if you want a reference to this block (you may use the same trick: store it in an external variable) or a list of all the blocks in the workspace...
Comment: I tried to get the list of all the blocks in a first instance because I guess than then I could retrieve an instance of the block or something similar. I expect now it will be more clear.
Comment: As by the moment it seems that this way it is the only one to get the blocks, I give to you the bounty and I accept your answer until a new better solution will be available. Thank you!
Answer: I know this question is somewhat old, but if you still desire  more granular access, you should work with blocks IDs (each block has a unique ID).
And, to get block elements, don't forget to define its inputs and fields names so you can refere to them:
example block:
Blockly.Blocks['my_block_unique_name'] = {
    init: function() {
    this.appendDummyInput("this_input_unique_name_for_this_block")
        .appendField("this block do:")
        .appendField(new Blockly.SomeField(...), "this_field_unique_name_for_this_block");
        this.setColour(60);
        this.setTooltip('this block do something');
    }
    //an crude example, be aware that blocks on fyout list will trigger it, if you did not use the block this block is disposed.
    console.log(this.id);
};

You can use an event to get its ID, store the IDs with some useful info on another place, etc...
And so you can do things like:
mainworkspace = Blockly.mainWorkspace
block = mainworkspace.getBlockById(id);
input = block.getInput("imageInput");
// You can use `setField(newValue,name)` too in a more clean way.
input.removeField("FieldImageButton");
input.appendField(new Blockly.SomeField(...), "this_field_unique_name_for_this_block")

And so you can analise the block isInFlyout to see if it is or not used (if it is a block from the openned category or a block dragged out of it, in use), I hope it help you and others.


Calculating primary groups

Question: I am preparing to analyze some data and I have a question about how to go about it. It is a 39 question survey with 5-item Likert scale responses. I will be using the responses to separate the participants into the category that they score highest in for further analysis. The problem is that Category A corresponds to 14 questions, Category B has 11 questions, and Category C has 14 questions. What is the best way to go about determining which one the participant scores highest in, since the # of questions is not equal? Will it work to take their total possible points in each category and divide it by the number of points possible, then compare their percentages across the three categories to see which is the highest?
Answer: I suppose your suggestion would be OK, but if all questions have 5 point response scales, why not just average the responses for each person over all the questions in each category?  I wonder if you might be concerned about using the mean with ordinal data?  That's a common concern, but I think it's generally overblown.  With multiple questions, the subscale scores should be sufficiently equal-interval for your purposes.  This topic has been discussed several times on CV; you might be interested in reading this question and especially the answer by @JeromyAnglim.
We can push past this strategy, however.  I'm not sure you need to categorize your participants as being in either A, or B, or C.  I'm typically against categorizing in this manner (for more on that, you might want to read this question and my answer there).  They each certainly have some level of membership in each, and categorizing them amounts to throwing that information away.  Moreover, even for those participants who are all more in A than elsewhere (for example), their level of A-ness will vary from participant to participant.  Thus, simply calling each of them an 'A' throws away the information about their within-category variability.  Why not keep those 3 scores for each participant, and use them as 3 covariates in a multiple regression model when it comes time to do your final analysis?
Comment: Hi, thanks for the feedback.  I was under the imrpession that calculating the means would not yield a result as precise as percentages, but I won't pretend to be good at statistics, so this information could be wrong :) As far as the categories,I will be conducting a 3-Way Anova using the primary motivation as one of the variables. So, its just one piece of the overall puzzle.
Comment: @LadyM, I would say means are *better* than percentages in that sense. Also, what I'm suggesting is that you *don't* do a standard ANOVA, but use a multiple regression model instead (although ANOVA actually is an MR); it will be more appropriate given what you have & ultimately more informative. On a different note, if you find this answer helpful, you might consider upvoting by clicking the upward normal dist to the left of it, & if you think it answers your question, you could further accept it by clicking the check mark. No pressure, I just see you're new, & you might be unfamiliar w/ this.
Comment: Thank you, yes I am new to this site, but I was certainly glad to find it. It has been several years since I have taken statistics and I will say that I struggled with it when I did. So any help is appreciated. I did click to vote for the post, but I received a message stating that I need 15 reputation first. I am going to go read about multiple regression ANOVAs now, thanks for the tip!
Comment: @LadyM, sorry, I guess I forgot about the rep requirement; it's been a long time since I was <15. My answer in the question I link to in the 2nd paragraph has a little info about regression & ANOVA. There's probably more info somewhere. If you can't find enough for it to be clear to you, you can always ask another question on CV, just be sure to say what you've got so far & where you're still confused. (People here respond poorly to questions like 'What's the deal w/ regression & ANOVA?') However, the topic is to big for me to try to explain in comments. Good luck w/ your project.
Comment: Thank you! I am sure that I will be posting here again, I am just getting started on the data analysis. I have been reading your post about regression and ANOVA. I am also reading about regression in my old stats books as well. If I understand it correctly, regression will capture interactions, right? That is what I am looking for. I have a 2X3X2 design and I am looking at the interactions between these IVs (male/female, motivation (3 types), and introvert/extrovert on the DV of specified time.I have a lot of other descriptive data as well.
Comment: @LadyM, no problem. Yes you can do interactions w/ multiple regression.
Comment: Ok, I if I were to run a linear regression in SPSS, I would put in all of the motivation questions/answers from the survey as IVs instead of using a primary category, correct?
Comment: Oops, nevermind. I just re-read your initial message about using the total score as a covariate, not each and every question.
Comment: @LadyM, I would use the 3 averages from the 3 different subscales as 3 covariates. You *could* even do interactions amongst the 3 subscale scores if that had seemed meaningful w/i your theory (which I gather isn't the case, however).
Comment: Ok, thank you. I will look into this further. I have pulled some information on linear regression vs. three way factorial ANOVA and am attempting to sift through it now. One big concern that I have about changing to regression at this point is that my proposal has already been approved (with data analysis procedures) and I have the data collected.

Calculating primary groups


Proving an inequality of random variables

Question: I am currently reading a paper that claims the following fact:

Let $X$, $Y$ be $L^2$ random variables on some probability space. The $L^2$ norm is denoted by $\| \cdot \|_{2}$. Then there exists $C>0$ such that
  \begin{eqnarray}
&& \mathbb{E} \bigg[ \mathbf{1}_{\{ |Y| \geq \|Y\|^{1/2}_2 \}} (1+ |X| + |Y|)|Y| \bigg] \\
& \leq & C \|Y\|_2 \bigg( \|Y\|_2 + \sqrt{\|Y\|_2} + \sup_{A: \mathbb{P}(A) \leq \|Y\|_2} \mathbb{E}[|X|^2 \mathbf{1}_A]^{1/2} \bigg).
\end{eqnarray}

It seems to involve the Cauchy-Schwarz inequality, applying to the terms $ \mathbf{1}_{\{|Y| \geq \|Y\|^{1/2}_2\}}(1+|X|+|Y|)$ and $|Y|$. But I don't see how the $L^2$ norm of the first term can be bounded.
Answer: We can estimate each term separately. Observe the following:
$$
\Bbb E\left[1_{\{ |Y| \geq \|Y\|^{1/2}_2 \}}|Y|\right]\le \Bbb E\left[1_{\{ |Y| \geq \|Y\|^{1/2}_2 \}}\frac{|Y|^2}{\|Y\|_2^{1/2}}\right]\le\|Y\|_2^{3/2},
$$
$$
\Bbb E\left[1_{\{ |Y| \geq \|Y\|^{1/2}_2 \}}|Y|^2\right]\le \|Y\|_2^2,
$$
$$
\Bbb P(|Y| \geq \|Y\|^{1/2}_2)=\Bbb P(|Y|^2 \geq \|Y\|_2)\le \frac{\Bbb E|Y|^2}{\|Y\|_2}=\|Y\|_2,
$$ and
$$\begin{eqnarray}
\Bbb E\left[1_{\{ |Y| \geq \|Y\|^{1/2}_2 \}}|X||Y|\right]^2&\le& \Bbb E\left[1_{\{ |Y| \geq \|Y\|^{1/2}_2 \}}|X|^2\right]\Bbb E\left[1_{\{ |Y| \geq \|Y\|^{1/2}_2 \}}|Y|^2\right]\\
&\le&\sup_{A:\Bbb P(A)\le \|Y\|_2}\Bbb E[X^2 1_A]\cdot \|Y\|^2_2
\end{eqnarray}$$ by Cauchy-Schwarz. This gives
$$
\begin{eqnarray}
\mathbb{E} \left[ 1_{\{ |Y| \geq \|Y\|^{1/2}_2 \}} (1+ |X| + |Y|)|Y| \right] \le \|Y\|_2\left(\|Y\|_2+\|Y\|_2^{1/2}+\left(\sup_{A:\Bbb P(A)\le \|Y\|_2}\Bbb E[X^2 1_A]\right)^{1/2}\right)
\end{eqnarray}
$$ as desired.


how to make the newsletter checkbox checked by default in prestashop 1.7 in checkout process?

Question: How to make the newsletter checkbox checked by default in prestashop 1.7 in checkout process?

Update:
I found the file where the form is rendrered:
\modules\ps_emailsubscription\ps_emailsubscription.php
But amazing enough there are are no function defined to change attributes.
public function hookAdditionalCustomerFormFields($params)
{
    $label = $this->trans(
        'Sign up for our newsletter[1][2]%conditions%[/2]',
        array(
            '[1]' => '
',
            '[2]' => '',
            '%conditions%' => Configuration::get('NW_CONDITIONS', $this->context->language->id),
            '[/2]' => '',
        ),
        'Modules.Emailsubscription.Shop'
    );

    return array(
        (new FormField())
            ->setName('newsletter')
            ->setType('checkbox')
            ->setLabel($label));
}

Answer: The correct file that is rendering the form is:
/themes/[your-activated-theme]/templates/customer/_partials/customer_form.tpl
In the line 32 you can see this code that is the responsable to render the input fields of the form:
{block "form_fields"}
  {foreach from=$formFields item="field"}
    {block "form_field"}
      {form_field field=$field}
    {/block}
  {/foreach}
  {$hook_create_account_form nofilter}
{/block}

The new way to create form  fields is calling the smarty function "{form_field}", like the line 35.
This funciton is calling this file to create the different input's:
/themes/[your-activated-theme]/templates/_partials/form-fields.tpl
So, my faster solution (I think that not is the best, but works) is to change directly in this file to say that make checked the checkbox input when it's the newsletter and optin input and it's in the authentication page:
Change this on line 91 in form-fileds.tpl file:
{if $field.value)}

To:
{if $field.value || ($field.name == "newsletter" && $page.page_name == 'authentication') || ($field.name == "optin" && $page.page_name == 'authentication')}

Hope it helps you.
Answer: Hello the correct answer is not to forget "checkout too" to make all works well
Here the good code complete
{if $field.value || ($field.name == "newsletter" && $page.page_name == 'authentication') || ($field.name == "optin" && $page.page_name == 'authentication') || ($field.name == "newsletter" && $page.page_name == 'checkout') || ($field.name == "optin" && $page.page_name == 'checkout') }checked="checked"{/if}

Answer: for me the previous answer didn't work, so I just changed the:

{if $field.value}checked="checked"{/if}

to:

checked="checked"

Regards, B


Show $\limsup_{n\rightarrow \infty }(-a_{n}) = -\liminf_{n\rightarrow \infty }(a_{n})$

Question: Show $\limsup_{n\rightarrow \infty }(-a_{n}) = -\liminf_{n\rightarrow \infty }(a_{n})$ for a sequence $(a_{n})\subset\mathbb{R}$
Attempt:
$\limsup_{n\rightarrow \infty }(-a_{n}) = \inf_{n\geq1 }(\sup\begin{Bmatrix}
-a_{n},-(a_{n+1}),...
\end{Bmatrix} )$
Now using the fact $-\sup(-A) = \inf(A)$ where $A\subset\mathbb{R}$
$= \inf_{n\geq1 }(-\inf\begin{Bmatrix}
a_{n},a_{n+1},...
\end{Bmatrix} )$
$= -\inf_{n\geq1 }(\inf\begin{Bmatrix}
a_{n},a_{n+1},...
\end{Bmatrix} )$
I would like to show $-\inf_{n\geq1 }(\inf\begin{Bmatrix}
a_{n},a_{n+1},...
\end{Bmatrix} )= -\sup_{n\geq1 }(\inf\begin{Bmatrix}
a_{n},a_{n+1},...
\end{Bmatrix} ) = -\liminf_{n\rightarrow \infty }(a_{n})$
but im not sure the previous inf(-inf) = -inf(inf) step is even correct.
Still trying to wrap my head around this concept!
Comment: It's useful to write down the sets as precise as possible (instead of implicitly). Sometimes it's unclear (at least for me) what your given set look like.
Answer: We can rewrite $\limsup$ as
\begin{align*}
\limsup_{n \to \infty} (-a_n) &= \lim_{n \to \infty} \sup_{k > n} (-a_k) \\
&\stackrel{(*)}{=} \lim_{n \to \infty} -\inf_{k > n} (a_k) \\
&= -\lim_{n \to \infty} \inf_{k > n} (a_k) \\
&= -\liminf_{n \to \infty} (a_n) \\
\end{align*}
where $(*)$ follows from the fact that $\sup (-A) = -\inf (A)$, as you've stated.
Comment: Thank you, I was overthinking this one.


2-ways anova for non-normal data

Question: Our group took samples of contamination in sediments from around 20 non-related rivers, during 4 months.
I want to know if contaminant (micrograms per liter) is related to river and/or time, thus my first option would be 2-ways ANOVA. The factors are "river" (values 1 to 20) and "month" (values 1-4), and the response variable is contaminant content.
The problem is I have checked that the contaminant variable is non-normal and I didn't find a useful data transformation to avoid this.
So, which would be the best choice in this case? I have read that Kruskal-Wallis can be used with one factor and another one as blocking, but I'm not sure if it's my case (maybe because I don't fully understand factor blocking, my bad).
Any other non parametric 2-factos test I can use in this case?
Thanks a lot
Comment: related: https://stats.stackexchange.com/questions/41199/non-parametric-for-two-way-anova-3x3
Answer:
You have to check normality of the response variable in each combination of factors; in your case 20 rivers x 4 months = 80 combinations. You cannot just look at a distribution of the reponse variable overall accross all treatments and expect it to be normal (it is not clear from your question if you did that).
You don't have to have very nicely normal distributions in each combination. If you don't, you could still proceed with an ANOVA at your discretion, as it is robust to some deviations from normality.
The best way to check for normality is to inspect distributions visually by eye. It is more reliable and recommended over formal tests.
A non-parametric alternative to 2-way ANOVA exists and is called the Scheirer–Ray–Hare test. It was developed in 1970s, but has since been strongly criticized (sorry, I don't remember a reference for this).
If the sample size is balanced across the 4 months, then you could omit month as a factor and analyse the data with river as the sole factor using either 1-way ANOVA or Kruskall-Wallis test.
Comment: With respect to item 1, one might go further and look at normality of _residuals_ around cell means combined over _all_ the 80 cells in the design, pooling the information, rather than looking in each of the 80 cells. That provides a nice pooling of information among samples and might point to particular outliers in terms of rivers/months. If there's only one measurement per cell, however, neither your nor my suggestion can be carried out. A log transformation often helps with these types of data, too, if measurement errors are proportional to the value of the contaminant being measured.
Answer: While regular permutation tests cannot be extended beyond one factor, there are so-called "synchronized permutation" tests. Here' a reference for them in the 2-way setting:

Basso D., Pesarin F., Salmaso L., Solari A. (2009) Synchronized Permutation Tests in Two-way ANOVA. In: Permutation Tests for Stochastic Ordering and ANOVA. Lecture Notes in Statistics, vol 194. Springer, New York, NY.
link

You have to check whether their assumptions are fulfilled in your case.

2-ways anova for non-normal data


Programatically load title of a views page by its machine name

Question: I would like to use the current title of a very specific views page in another template. Instead of just manually copying it and in order to stay flexible and always up to date, I would like to programatically load and insert it.
If my views page has machine name views_page, how do I programatically load its current title into a string?
Comment: what do you mean "another template"?
Answer: Any of these should work:
Load the View and get the display title:
$view = views_get_view('views_page');
print $view->display['page_1']->display_options['title'];

Note: Change 'page_1' to the name of your display.

You can also get the page title from the path:
$item = menu_get_item(drupal_get_normal_path('path/to/page'));
print $item['title'];


How to differentiate $x^TWLW^Tx$ w.r.t $W$?

Question: Suppose $x \in \mathbb R^d$, $W \in \mathbb R^{d\times c}$, and $L \in \mathbb R^{c \times c}$ is diagonal.
How do I differentiate $x^TWLW^Tx$ with respect to $W$?
Comment: As usual: compute $f(W+tH)$ and check the limit of $(f(W+tH)-f(W))/t$ when $t\to0$.
Answer: Let $f : \mathbb R^{m \times n} \to \mathbb R$ be defined by
$$f (\mathrm X) := \mathrm a^\top \mathrm X \mathrm B \mathrm X^\top \mathrm a$$
where $\mathrm a \in \mathbb R^m$ and $n \times n$ symmetric matrix $\mathrm B$ are given. Taking the differential,
$$\begin{array}{rl} \mathrm d f &= \mathrm a^\top (\mathrm d \mathrm X) \mathrm B \mathrm X^\top \mathrm a + \mathrm a^\top \mathrm X \mathrm B (\mathrm d \mathrm X)^\top \mathrm a\\ &= \mbox{tr} ( \mathrm a^\top (\mathrm d \mathrm X) \mathrm B \mathrm X^\top \mathrm a) + \mbox{tr} ( \mathrm a^\top \mathrm X \mathrm B (\mathrm d \mathrm X)^\top \mathrm a)\\ &= \mbox{tr} ( \mathrm B \mathrm X^\top \mathrm a\mathrm a^\top (\mathrm d \mathrm X) ) + \mbox{tr} ( (\mathrm d \mathrm X)^\top \mathrm a \mathrm a^\top \mathrm X \mathrm B)\\ &= \langle \mathrm a \mathrm a^\top \mathrm X \mathrm B^\top, \mathrm d \mathrm X \rangle + \langle \mathrm d \mathrm X, \mathrm a \mathrm a^\top \mathrm X \mathrm B \rangle\\ &= \langle \mathrm d \mathrm X, \mathrm a \mathrm a^\top \mathrm X (\mathrm B + \mathrm B^\top) \rangle\\ &= \langle \mathrm d \mathrm X, \color{blue}{2 \mathrm a \mathrm a^\top \mathrm X \mathrm B} \rangle\end{array}$$
and, thus, the gradient of $f$ is
$$\nabla f (\mathrm X) = 2 \mathrm a \mathrm a^\top \mathrm X \mathrm B$$

matrix-calculus scalar-fields gradient
Answer: using $\frac{\partial }{\partial X} trace(A X B X^T C)= BX^T CA + B^TX^TA^TC^T$ then $$\frac{\partial }{\partial W} x^T WLW^T x = \frac{\partial }{\partial W} trace(x^T WLW^T x) = LW^Txx^T + L^TW^Txx^T$$
Comment: thank you, I didn't know this rule :)


Cast str[str.size()-1] as interger in c++?

Question: I have no idea how to cast str[str.size()-2] and str[str.size()-1] as integers. I need to return answers as integers.
int main()
{
    cin>>D;
    int k;
    int z;
    int*tab=new int [D];
    for (int i=0;i<D;i++)
    {
        cin>>tab[i];
    }

    for (int i=0;i<D;i++)
    {
        z=silnia(tab[i]);
        string str = to_string(z);
        if (str.size()>1)
            cout<<str[str.size()-2]<<" "<<str[str.size()-1];
        else
            cout<<"0 "<<str[0];
        cout<<endl;
        suma=1;
    }

    return 0;
}

Comment: Printing the string `"10"` is no different from printing the integer `10`. There is no difference in the output. Try doing e.g. `cout << 10 << "10"` and see the non-difference yourself.
Comment: What do you mean by "convert `str[str.size()-2]` and `str[str.size()-1]` to `int`"? They are already characters representing digits and should be printed as digits.
Comment: When you say "return answers as number", what do you mean by *return*? Just to print? Because that's what you're already doing.
Comment: once you print on the screen there is no difference between `1` and `'1'`
Comment: please include input, output and expected output in the question. currently it is not clear what the problem with your code is
Comment: I need to print numbers of tens and singular numbers of some number. With this solution judge in spol don't accept string as answer.
Comment: #include

using namespace std;
int suma=1;
int D;
int silnia(int n)
{
    while(n>1)
    {

        suma=suma*n*(n-1);
        n=(n-2);
    }

};
Answer: I think you can use substr and atoi.

string std::string::substr (size_t pos = 0, size_t len = npos) const;
Generate substring
Returns a newly constructed string object with its value initialized to a copy of a substring of this object. The substring is the portion of the object that starts at character position pos and spans len characters (or until the end of the string, whichever comes first).
http://www.cplusplus.com/reference/string/string/substr/

int atoi (const char * str);
Convert string to integer
Parses the C-string str interpreting its content as an integral number, which is returned as a value of type int.
http://www.cplusplus.com/reference/cstdlib/atoi/
Answer: you can include sstream library then simply do the following:
stringstream a(str[str.size()-2]);
int x;
a >> x;

now x has the value of whatever ur string was and you can freely return x


How does class balancing via reweighting affect logistic regression?

Question: When developing machine learning classifiers, some people upsample or upweight the minority class to achieve a 50-50 balance, claiming that this improves performance. Some statisticians have questioned this practice, but there do seem to be some potential benefits, such as covariate shift adaptation. The practice is very widespread, generating so many questions on this site that CV Meta has raised concerns about consolidating the influx. There also seems to be a popular belief that class imbalance is a "problem" that data scientists must "fix" or address whenever it presents itself in the data.
Some data scientists apply class reweighting to logistic regression. This is especially surprising to me because it's such a simple traditional model and, pre-ML era, there was no tradition of boosting performance with reweighting (to the best of my knowledge). It is also puzzling because geometrically, it seems like it wouldn't affect the decision boundary between positive and negative samples, only the overall intercept of the model. If only the intercept changes, the rank order of predicted probabilities does not change, and popular evaluation metrics like AUROC and AUPRC which depend only on this rank order are also unchanged. But I have colleagues who tell me that they routinely increase the AUC of logistic regression models by upweighting the minority class. For them, the value of this practice is settled and uncontroversial.
Questions

Can class reweighting affect more than the intercept of an unregularized logistic regression model?
What initution or analysis can be used to predict the impacts? Are there good toy examples?
Do the answers to these questions shed any light on when and why class balancing is "actually good"?
Answer: Towards answering my three questions I offer a perspective based on analysis of a toy problem. While it is meant to illuminate a topic I find to be widely discussed but poorly understood, I do not claim my perspective provides uniformly comprehensive, authoritative conclusions. And the answer is geared towards traditional, simple logistic regression models. It should be less relevant to highly flexible ML models where misspecification is less of an issue.
Class reweighting can affect the decision boundary of logistic regression, especially when the model is misspecified (the data doesn't follow the pattern specified by the model). Upweighting one class pushes the model to align its decision boundary with the pattern of that class rather than the other class. As a result, class reweighting can be a good idea if you can't see how to fix the model misspecification and you need high recall on one class. However, the best weighting is use case-dependent, and is sometimes demonstrably not 50-50.
In applications, it's very common that a classifier's purpose is to predict rare but important events. Upweighting the minority class can make the model more fit-to-purpose if accuracy in the high-recall regime is the goal. Upweighting the minority class has the side effect of pushing the weighted class balance towards 50-50. It often increases AUC as well, since AUC is optimized at a 50-50 training balance in some models. (This has been proven for linear discriminant analysis in the infinite sample limit, and LDA is very similar to logistic regression.) However, neither class balance nor maximal AUC necessarily provide the best model for a given use case.
While the weighting that yields best performance is use case-dependent, and the optimal class balance is not necessarily 50-50, balancing might be a decent rule of thumb, especially when the model's desired operating characteristics are not known in advance. In this case, good average performance over a range of thresholds could be desirable, AUC is a metric for exactly this, and 50-50 balance often seems to provide better AUC, both theoretically and empirically.
That said, there is no general guarantee that class balancing maximizes AUC, and definitely no guarantee that it produces the best model for a given use case. Therefore, framing class imbalance as a "problem" that should be "fixed" is misleading and can lead to suboptimal modeling choices.
Class reweighting affects the decision boundary
Let's fire up R and fit a very simple misspecified model. Our data will have two classes, A and B. Class A will be on the x-axis and B on the y-axis.

It's possible to separate these data perfectly (except at the origin), but let's say we don't know that, and we only fit the most obvious logistic regression model with untransformed x and y as predictors. The decision boundary of this model is

Now, let's upweight one class by 10x. This time, the decision boundary aligns more closely with the data on the y-axis.

What's going on here?
From the perspective of the model, the data contains two conflicting patterns. With class A on the x-axis and class B on the y-axis, the classes are not cleanly separated by a single line, as the logistic regression model assumes. In other words, the model is misspecified. The fit must decide how to split the difference.
When class A and B have equal weights, the decision boundary is set halfway between the A pattern and the B pattern. When B is upweighted, it's pushed towards the B pattern. Weighting does not just change the intercept, but also aligns the decision boundary more with the distribution of class B.
In retrospect, this makes sense. When errors on one class become much more costly, the model fitting process will prefer a model which is highly accurate on that class by keeping it to one side of the decision boundary as much as possible. Changing the slope of the boundary accomplishes this more effectively than just changing the intercept. Similar phenomena should also occur in more complex problems with more predictors and nonlinear decision boundaries.
What does this suggest about class balancing?
Models are often misspecified in real-world applications, especially when linear-decision-boundary models are used, because the data rarely conform to simple linear formulas. However, misspecified models can still be useful, and we can use weighting to make the model more fit for purpose. In this case, if the purpose of the model is to find all possible elements of class B, and some false positives from class A are tolerable, the model weighted 10x towards class B is probably preferable. It has the same recall, and better precision, than simply shifting the threshold of the unweighted model. (This can be seen by thinking geometrically: if you move the y=x line down until all of B is on one side, more A points are on the wrong side than in the weighted model.) This is essentially importance weighting, as explained here.
This means 50-50 weighting is not ideal in this use case. And it doesn't matter if it maximizes AUC. It may, but that would just illustrate how maximizing AUC doesn't always get us what we really want.
Reweighting for class balance: a satisficing choice?
While reweighting for class balance doesn't always get the best result, it could perhaps be "good enough" in many applications. Very commonly, classifiers are designed to pick out a rare but important event. Upweighting the rare event may improve the fitness of the model for this purpose, and balancing classes can improve AUC, which can be a decent rough proxy for what is really desired.
In particular, when the desired operating characteristics of the model are not known in advance, maximizing AUC is arguably a good satisficing choice, because AUC represents average performance over a range of thresholds, and good average performance makes better performance around the operating threshold somewhat more likely.
On the other hand, a bit of thought about the use case often reveals a lot about the desired performance characteristics, and could yield better final results than spending 100% of effort towards maximizing AUC.
R Code
<code>library(tidyverse)
ggplot2::theme_set(theme_minimal())
vals <- seq(-1, 3, by = 1/10)
n <- length(vals)
ones <- 1 + numeric(n)
df <- tibble(
      x = c(1 * vals, 0 * vals),
      y = c(0 * vals, 1 * vals),
  class = c(0 * ones, 1 * ones)) %>%
  mutate(class = factor(class, c(0, 1), labels = c('A', 'B')))

# plot data
df %>%
  ggplot(aes(x = x, y = y, group = class, color = class)) +
  geom_point(size = 3) +
  ggtitle('Training data')

# Model 1: equal weights on classes ---------------

model <- glm(class ~ x + y, family = 'binomial', data = df)
beta_0 <- coef(model)['(Intercept)']
beta_x <- coef(model)['x']
beta_y <- coef(model)['y']

# plot data + decision boundary
# 0 = beta_0 + beta_x * x + beta_y * y
# y = (-beta_x / beta_y) * x + (-beta_0 / beta_y)
df %>%
  ggplot(aes(x = x, y = y, group = class, color = class)) +
  geom_point(size = 3) +
  geom_abline(slope = -beta_x/beta_y,
              intercept = -beta_0/beta_y,
              color = 'black', linetype = 'dashed') +
  ggtitle('Unweighted model')

# Model 2: upweight class B by 10x -----------------

df <- df %>% mutate(w = if_else(class == 'B', 10, 1))
model <- glm(class ~ x + y, family = 'binomial', data = df, weights = w)
beta_0 <- coef(model)['(Intercept)']
beta_x <- coef(model)['x']
beta_y <- coef(model)['y']

# plot data + decision boundary
df %>%
  ggplot(aes(x = x, y = y, group = class, color = class)) +
  geom_point(size = 3) +
  geom_abline(slope = -beta_x/beta_y,
              intercept = -beta_0/beta_y,
              color = 'black', linetype = 'dashed') +
  ggtitle('Fit with 10x weight on class B')
</code>
Comment: from the paper on lda you quote: "Our theoretical results are asymptotic, and show that, for all sufficiently large but finite datasets, there is a strict improvement in
AUC resulting from rebalancing the training data. Nevertheless,
when the sample size is small, these improvements cannot be
guaranteed theoretically. In fact, for a small sample, empirically
there is also no guarantee of improvement in AUC resulting from
rebalancing." So it's not proven - except in the limit of infinite sample sizes
Comment: @ Paul: great answer! How did you make these graphs? They look so beautiful!
Comment: Your problem can be separated by x^2-y^2. So just adding quadratic functions will allow logistic regression to give a perfect separation apart from at the origin
Comment: Ok, true. So would adding indicators for x=0 and y=0. But that's not the point. The point is that, if you don't know how to specify the model, the model has to follow the pattern of class A or class B. It can't follow both perfectly.
Comment: I myself have been asking similar questions. E.g.
Comment: https://stats.stackexchange.com/questions/596783/logistic-regression-with-imbalanced-data
Comment: https://stats.stackexchange.com/questions/596796/zero-inflated-logistic-regression-does-this-exist
Comment: @stats_noob I just added the R code at the bottom :)
Comment: I don't see any of these "facts" as facts. eg why can't you use a non linear decision boundary.
Comment: Some fair points, I will address with some small tweaks. Feel free to try and get different results on my toy problem with a nonlinear decision boundary, but I don't see how you will be able to do so.
Comment: Unless you use a highly flexible model like Gaussian kernel SVM or tree ensembles. I'll update to reflect that.
Comment: Or if you look at your data and hack your model formula to perfectly separate the classes, i.e. manually eliminate the misspecification. But the point of ML is it's not always possible to do that.


How to customize welcome email

Question: Could anyone show me how to customize welcome email in Drupal 8, as I spend a lot of time trying to get it done.
I've already tried in Back Office but Drupal seems to ignore it totally.
Comment: Brows to /admin/config/people/accounts
Comment: Single or Multi-lingual? If you have multiple languagest then there might be translations of it that you need to alter using configuration translation
Comment: Yes it is a Multi-lingual site (English/French), and I have already change the equivalent French mail body in `/admin/config/regional/translate?langcode=fr`. And instead of using the French mail template I just entered, Drupal always translate the default built-in welcome email into French and send it to new user.
Answer: Navigate to /admin/config/people/accounts and scroll to the bottom.
Answer: Go to admin/config/people/accounts and scroll to the bottom:
Comment: Thanks for your answer, but when I try to change the email template in "Welcome (no approval required)" tab, the mail received by the user upon registration remains the same. I've already saved my change.
Comment: Did you try to clear your cache? Then send the mail again for a new user.
Comment: Yes I've already cleared cache and resend another email for a new user but no luck...
Comment: Just for testing, I put "Registration at [site:name]" as the mail body, but it still the same
Comment: And you're certain you edited the correct textfield, and created the corresponding account? For example if you create the user using `admin/people/create` then you need to configure "Welcome (new user created by administrator)".
Comment: I created the user trough the front page where there is a registration form . The user get created correctly, but the mail sent is the Drupal standard email body: "Thank you for registering at Drupal. You may now log in by clicking this link or copying and pasting...." even our sitename is not Drupal anymore
Comment: @James perhaps your site name it is still "Drupal"? Copy the body message and paste it in a text file so you don't lose it. Then re-write the e-mail body to `testing 12345` and see if you get that.
Comment: I've just check the site name and it is still Drupal, even I've already changed it for something else (saved the change, cleared cache,,,). I am wondering if the mail body loaded in `/admin/config/people/accounts` is from database or from a file...
Answer: we had a simliar issue with Drupal showing always default email. Despite the fact we overrided the Welcome (no approval required) input field.
After a lot of research, we found out we had a database issue, there was an additional collection (language.fr) when actually France was the default language (then there is no sense language.fr collection to be there, as default language doesn't have collection data)
Our solution, was to remove french language (was our default language) and add it back again (please do a backup first).
Comment: Have to mention we didn't loose any data on this process of remove and add default languge.

How to customize welcome email


Não consigo usar a var global $_SERVER['PATH_INFO']

Question: Estava tentando fazer redirecionamento, pegando o caminho da url usando var global $_SERVER['PATH_INFO'], mas sem sucesso.
Ao dar print_r($_SERVER);, vi que o  PATH_INFO não era mais listada.
ex.:

127.0.0.1:8080/edsa-Site/index.php

No caso queria pegar a parte "/index.php". Como poderei fazer isso, e se possível pegar somente "index" ?
Answer: A variavel PATH_INFO é até comum em Apache, mas nem todo servidor vai possuir ela, pois ela nem sempre é configurado (dependendo de cada servidor), basicamente tem que configura-la manualmente, no seu caso provavelmente você esta usando php-built-in-server, sendo o caso ou não para obter o caminho pode usar o $_SERVER['REQUEST_URI']
O "problema" do $_SERVER['REQUEST_URI'] é que ele retorna a querystring também, por exemplo se a URL for assim:
http://127.0.0.1:8080/edsa-Site/index.php?foo=bar

Vai retornar isto:
/index.php?foo=bar

E claro, isto é bem mais que o caminho, para resolver isto pode usar explode, preg_replace, substr+strpos, mas minha sugestão é usar algo mais simples, o strtok, ficando algo como:
$requri = strtok($_SERVER['REQUEST_URI'], '?');

var_dump($requri);

Comment: Fiz o teste no servidor embutido do php, e deu certo, agora usando o Devserver 17 já não consigo usar o PATH_INFO. Existe algum meio de configurar o mesmo para poder usar?Quero poder fazer uns testes, mas preciso usar um banco de dados, e com o servidor embutido no php não consigo fazer o uso de uma database até onde sei.
Comment: @Medivh devserver17 nem é um servidor, é um pacote de programas recomendo que leia https://pt.stackoverflow.com/a/115690/3635 ... não precisa usar PATH_INFO, usa o código que esta na resposta.


Is there a way to stop clang-format from putting space after return?

Question: If I have something like this:
bool someFunction()
{
    return(true);
}

and pass it through clang-format, it always adds a space between the return and opening ( like this:
bool someFunction()
{
    return (true);
}

I've got SpaceBeforeParens set to Never yet it still adds this space. Does anybody know of a way to control this?
Comment: unrelated advice: stop using parenthesis around return values ,because when you start using auto as deduced return values this will return a reference instead of the value you probably want.
Comment: Remove the parentheses.
Answer: stop using parenthesis around return values ,because when you start using auto as deduced return values this will return a reference to the value (most likely not what you want) instead of the value you probably want.
And your issue immediately disappears.
Comment: Funny how 2 people up-voted an answer that does not address the actual question. I have the same problem I want to resolve but in my case I'm trying to not add an extra space to a code like `if(condition){foo();}` - how does your "solution" help me? :(
Comment: Most companies have a coding standard that requires the parentheses to avoid ambiguity. It is best to be explicit in what you want returned, especially in C
Comment: @Nfettinger: about C ,well the question is flagged C++ so C is not considered especially since I mentioned "deduced" (does C have type deducing?).
Comment: @Nfettinger: standards and guidelines are a good thing ,but when they're changing the meaning of code then they must not become dogmatic.


Within individual independence testing

Question: I have a group of individuals that is independent and identical distributed. Within each individual $i$, one may observe $N_i$ observations. The task is to test whether the within-individual observations are independent or not.
Currently I am considering runs test or rank von Neumann ratio, but I am not confident whether I should use them.
Answer: Can you explain a little more about what is being observed for each individual? It's difficult to say how this should be treated. Suppose that each individual has a set of characteristics. If each individual is randomly selected then one's attributes should not be related to another's other than by chance. The attributes of the individual, however, are most likely correlated (demographics, test scores, etc.)
Comment: The observations could be, say, duration of absences from work within a year, scores of a series of exams etc.
Comment: Suppose one flips a coin in Europe and another person flips a coin in America. After this, both individuals win the lottery. If these individuals were chosen randomly, then both winning the lottery cannot be anything but chance. Conversely, one winning the lottery because the other didn't would not be because of chance, thus making these two individuals not randomly chosen since there was a variable they shared that was not observed. (Ex:if two individuals have traits, say test scores, that are related, perhaps these folks came from the same area of the world but this wasn't originally known.)
Comment: For each individual person, their test scores may be related to their absence at work, but probably not correlated to winning the lottery unless it was rigged (something we have to make an assumption about.)

Within individual independence testing


Multivariate model in lme() with independent random effect, similar to MCMCglmm

Question: I would like to specify a multivariate model with lme with a random effect for group which is independent across variables. I found this post,
which explains that the model specified as:
fit.multilevel <- lme( y ~ var -1,  dd,
                    random = ~ var -1| school,
                    correlation =  corSymm( form = ~ v |school/id),
                    weights = varIdent(form = ~ 1 | v))

is equivalent to (using MCMCglmm):
fit.w.null <- MCMCglmm( cbind(mathach, ses) ~ trait -1 ,
        random = ~us(trait):school,
        rcov = ~us(trait):units,
        data = hs,
        family = c("gaussian","gaussian"))

However the model I would really like has independent random effects for school across the variables:
fit.w.null <- MCMCglmm( cbind(mathach, ses) ~ trait -1 ,
        random = ~idh(trait):school,
        rcov = ~us(trait):units,
        data = hs,
        family = c("gaussian","gaussian"))

(the random effect is specified with idh()). I cannot find a way to specify this in lme.
Here is some code to generate example data and run the analysis:
gr=rep(c("A","B","C"),each=100)
grp.mean=rep(rnorm(3,5,1),each=100)
var1=rnorm(300,rep(rnorm(3,5,1),each=100),1)
var2=0.8*var1+3*rnorm(300,rep(rnorm(3,5,1),each=100),2)
dat.mcmc=data.frame(var1=var1,var2=var2,group=gr)
dat.lme=data.frame(y=c(var1,var2),var=rep(c("1","2"),each=length(gr)),
             group=rep(gr,2),id=rep(1:length(gr),2))
dat.lme$v=as.integer(dat.lme$var)

Currently this is the best I can do:
fit.multilevel <- lme( y ~ var -1,  dat.lme,
                       random = ~ var -1| group,
                       correlation =  corSymm( form = ~ v |group/id),
                       weights = varIdent(form = ~ 1 | v))

This is (I believe) equivalent to:
fit.w.null <- MCMCglmm( cbind(var1, var2) ~ trait -1 ,
                        random = ~us(trait):group,
                        rcov = ~us(trait):units,
                        data = dat.mcmc,
                        family = c("gaussian","gaussian"))

However, I would like an lme command equivalent to:
fit.w.null <- MCMCglmm( cbind(var1, var2) ~ trait -1 ,
                        random = ~idh(trait):group,
                        rcov = ~us(trait):units,
                        data = hs,
                        family = c("gaussian","gaussian"))

Any help you can give me will be much appreciated.
Answer: I believe the answer is to use ?pdClasses as explained here.
fit.multilevel <- lme( y ~ var -1,  dat.lme,
                   random = list(group= pdDiag(~ var-1)),
                   correlation =  corSymm( form = ~ v |group/id),
                   weights = varIdent(form = ~ 1 | v))


Override Commerce Kickstart Features ( and Features Override module error)

Question: I have the Drupal Commerce Kickstart bundle in my project. This bundle contains a bunch of Features. Most of them are overridden now. It's not good to have most of setting inside the DB instead of features, so I want to save my changes inside my features.
As far as I know, it's not a good idea to modify the Kickstart Features, so I tried to use the Features Override module.
But, unfortunately, got "white screen of death" on Feautures Override Tab. Also, it broke all of my Kickstart Features.
The only "evidence" is the message:

Notice: Array to string conversion in
  features_override_features_export_render_addition()

PHP: 5.4.9
Commerce Kickstart: 7.x-2.9
Features Override: 7.x-2.0-rc1
Do you have any ideas how to fix this problem with Featuers Override, or just how can I move my settings from DB to code in my situation?
Answer: I've found that Features Override works nicely in simple scenarios, but I've been unable to get it working in more complex scenarios, such as modifying Drupal Commerce.
One alternative — instead of modifying the Features Components provided by Drupal Commerce — is to clone them, make your changes to the cloned components, and then featurize the cloned components.