What is the definition of belonging in axiomatic set theory?

Question: In Hungerford's Algebra it says that

Intuitively we consider a class to be a collection $A$ of objects such that given any object $x$ it is possible to determine whether or not $x$ is a member (or element) of $A$

In Thomas Jech's Set theory it states the extensionality without defining what is belonging.
I just learn that in set theory everything existing is just set. But it doesn't state that set is a collection of something so the natural membership definition of belonging may not exist. For example, red may be a set but nothing is a member of it in a real-life widely-admitted sense.
Then what is belonging, i.e. $\in$ defined?
You can see also my another question
Comment: It is primitive, not defined. The axioms govern its behavior. (Also,I assume you mean Thomas Jech?)
Comment: Red is totally a set: it's one of the equivalence classes of the relation "is the same color as".
Answer: In axiomatic set (or class/class-set) theory, the membership relation is a primitive relation. It is not defined, but other things are defined from it. The axioms tell us how it behaves.
We can compare to the situation of asking how the successor operation is defined in an axiomatic treatment of arithmetic. You might say $S(0)=1$ and $S(1)=2,$ etc, but that's no definition at all. In fact, the right way to think of it is that $1$ is an abbreviation for $S(0)$ and $2$ is an abbreviation for $S(S(0)),$ etc. In other words, the successor operation is a basic notion with no definition. The axioms tell us its basic properties, like if $S(x) = S(y)$ then $x=y,$ and that there is no $x$ such that $S(x)=0,$ but if $y\ne 0$ then there is an $x$ such that $S(x)=y.$ Oh and how do we define $0$? Well, if we want, we can take it as an axiom that there is a unique object with no predecessor and define $0$ as that object. But it's really all the same and saves a little ink to take $0$ as primitive, so that's what's usually done.
In set theory, $\in$ is the only primitive relation other than equality (although we can even define equality in terms of $\in,$ but this is a little troublesome and not typically done). Other basic notions like the empty set, the subset relation, the union operation, etc, are defined in terms of $\in$ and $=$ (where in the case of constants and operations, we also must use the axioms to establish existence/uniqueness/well-definedness). It may be convenient in certain modifications to take some of these as primative (e.g. the empty set), but it's customary in a standard treatment of ZF to have them defined.
I think you are reading the phrase "everything existing is a set" a bit too literally. What we mean is that every object in the domain of discourse of our theory is a set. This really has no content: we are just saying that the objects referred to by variables in our theory are called sets. We are certainly not making a sweeping metaphysical statement that every concept in the world (e.g. "red") is somehow a set.
Finally, a word on classes. In set theory, a class $C$ is just an informal notion of a collection of sets satisfying some formula $\phi_C$. So $x\in C$ is just an abbreviation for $\phi_C(x)$. In class theory the membership relation for classes is a primitive relation again. There are a number of ways of slicing and dicing, but one way is to just let all objects be classes, and let sets be a special kind of class. We can define the predicate $Set(x)$ as $\exists z (x\in z),$ i.e. a set is a class that is an element of some class.
Comment: For the proposer: A class in the language of ZFC can be considered as a modification to the language to allow some  abbreviations.  E.g. the formula $\phi$ in one free  variable that defines Godel's constructible class is very long so we write $x\in L$ rather than writing out  $\phi(x)$ in full. This does NOT assert that there exists a set $L=\{x: \phi(x)\}.$ And in this case, since there does exist some $x$ such that $x\in L$ but there does not exist a set $\{x:x\in L\}$  we call $L$ a proper class. (An improper class, which is a term you will never see, would be a set.)............+1
Answer: In axiomatic set theory, $\in$ is a primitive relation - in fact, the only such in the theory in usual formulations, while the only primitive objects are sets. Primitives are not formally defined: if you want to think of them as having a definition, that definition is not part of the formal system (the system of logical axioms that set theory is, written in symbolic notation) and, instead, must belong to external, natural language. You can think of the formal system then as being something which tells these things how to behave, and in which we conduct arguments and proofs. We should think of these natural-language understandings (i.e. "a set is a collection") as a way to make sense of the formal axioms through intuition, so as to not look arbitrarily-chosen, random rules (as they aren't), and the formal axioms in turn, in a way, as "feeding back" on that in that they help to sharpen this intuition.
Insofar as the idea that "red" is a set, this is not correct. The statement "everything existing is a set" doesn't mean "everything existing in real life", rather it means "everything existing in the world of set theory". The world of set theory, at least Zermelo-Fraenkel set theory, only has sets as primitive objects.


An exercise on calculus

Question:
Let $\mathbb{R}_+$ denote the set of positive real numbers
(a) Show that the continous function $f: \mathbb{R}_+\to\mathbb{R}$ given by $f = 1/(x+1)$ is bounded but doesn't achieve a max or min
(b) Repeat (a), but let $f = \sin(1/x)$ and show that it is not uniformly continuous on $\mathbb{R}_+$

(a) I have two methods, I already know the second method is wrong, but would like a harsh criticism why.
(i) Okay first of all, since $f$ is continuous on $\mathbb{R}_+$, that is for some $a \in \mathbb{R}_+$, we can verify that it is continuous at $a$. So it is trivially bounded. I probably shouldn't just state this because it doesn't seem like the problem wants this kind of solution (my gut feeling, but would like an expert to tell me why I can't do this). So instead I show its sup and inf
Let $A = \{ x \in\mathbb{R}_+:  f = 1/(x+1)\}$, then $\sup_{x}_{x \in\mathbb{R}_+} A = 1$ and $\inf_{x}_{x \in\mathbb{R}_+} A = 0$. So it is bounded, but since neither $0$ nor $\infty$ belongs to $\mathbb{R}_+$, max and min doesn't exist. I know infinity is not a quantity, but you can follow my logic. Would be great if someone could clean it up
(ii) Okay the second method was induction. I tried using the same technique for sequences on functions. I assume there is some positive $M$ such that
$f(x) \leq M$, then I show $f(x + 1) \leq M$. Now the algebra works out great, and my inductive step was easily done using $1/(x + 1 + 1) < 1/(x + 1) < M$. But obviously something was missing.
(b) Same idea, $x \to 0^+$, $f \to +\infty$, so $\sup_{x \in\mathbb{R}_+}= DNE$ and $\inf_{x}_{x \in\mathbb{R}_+}  = 0$ as $x \to \infty$
Since neither 0 or infinity belong to the domain, it can't have a max or min. However since it has a sup and inf, it is bounded. Is stating $\mathbb{R}_+$ not compact which implies non-uniform continuity good enough?
Note that this was a problem in Munkres in which neither the Mean Value Theorem or Derivatives were introduced yet, so I can't take derivatives and set it to $0$ (you get the drill)
Comment: I don't understand what your set $A$ is. Did you mean $A = \{ f(x): x\in \mathbb{R}_+\}$?
Comment: Continuous implies bounded? I don't think so --- is $f(x)=x$ bounded?
Comment: Also, you need a base case for induction. If you're trying to do induction on the reals, the base case is all $x$ with $0\lt x\le1$.
Comment: @GerryMyerson, I meant to say continuous at a point and within a neighbourhood of $a$, $f$ is bounded. Probably irrelevant point. I'll fix
Answer:
Okay first of all, since $f$ is continuous on $\Bbb R_+$, that is for some $a\in\Bbb R_+$, we can verify that it is continuous at $a$. So it is trivially bounded.

This makes no sense, I'm afraid. Consider the function $g(x)=x$ on $\Bbb R$; it's continuous, but it's certainly not bounded on $\Bbb R$. Continuity of $f$ at $a$ shows that there is some interval around $a$ on which $f$ is bounded, but it says nothing about what happens elsewhere.
In order to show that $f(x)=\frac1{x+1}$ is bounded on $\Bbb R_+$ you must show that there are real numbers $m$ and $M$ such that $m\le f(x)\le M$ for all $x\in\Bbb R_+$. You actually did this in the next paragraph, when you pointed out that $\sup_{x\in\Bbb R_+}f(x)=1$ and $\inf_{x\in\Bbb R_+}f(x)=0$.
Induction (in the form in which you're familiar with it) is a way to prove statements about integers. Specifically, if $P(n)$ is some assertion about the integer $n$, induction says that if you can prove $P(n_0)$ for some integer $n_0$, and you can prove that $P(n)$ implies $P(n+1)$ whenever $n\ge n_0$, then $P(n)$ is true for all integers $n\ge n_0$. In this problem you need to prove that something is true for all real numbers greater than $0$, which is another kettle of fish altogether.

In (b) you're not paying attention: the function is $f(x)=\sin\frac1x$, not $f(x)=\frac1x$. This is certainly bounded, since $-1\le\sin u\le 1$ for all $u\in\Bbb R$. Look at the graph of $y=\sin\frac1x$: it oscillates between $-1$ and $1$, and it does so faster and faster as $x\to 0^+$. Suppose that $n$ is a large positive integer, and $x_n=\frac1{n\pi}$. Then $f(x_n)=\sin\pi n=0$, but if $n$ is large, the graph is very steep at that point. Suppose that you want to find a $\delta>0$ such that $|f(x)|<\frac12$ whenever $|x-x_n|<\delta$; show that $\delta$ will have to be smaller than $\frac1{n\pi}-\frac1{(n+1)\pi}$. Then use this to show that no matter how small you take $\delta>0$, you can find integers $n$ so large that $\delta$ doesn't work at $x_n$: there is an $x$ such that $|x-x_n|<\delta$, but $|f(x)|\ge\frac12$. This will show that $f$ is not uniformly continuous.
Comment: @sizz: What I wrote starting with 'Suppose that $n$ is a large positive integer' is a fairly big hint for (b).
Comment: Perhaps, we may also note that every continuous function from a compact space into $\mathbb{R}$ is bounded (In order not to completely discourage the continuous->bounded implication.).
Comment: @sizz: (1) A spoiler for what? (2) Using $P(x+h)$ doesn't help: you're still dealing only with a discrete set of points, $x,x+h,x+2h,\dots$. Induction simply isn't an appropriate tool here.
Comment: A spoiler over (b). Since I completely computed sup and inf for the wrong function
Comment: @BrianM.Scott $m\le g(x)\le M$, I think you mean $f$ instead of $g$.
Comment: @GitGud: I certainly do; thanks for catching it.
Comment: @sizz: You shouldn't be trying to work with an object $\infty$ in the first place: there is no such real number. All you have to say is that for all $x>0$, $x+1>0$, and therefore $\frac1{x+1}>0$. On the other hand, you can get $\frac1{x+1}$ arbitrarily close to $0$ by taking $x$ large enough. (E.g., to get $\frac1{x+1}<\frac1n$, just take $x=n$.) It follows immediately that $\inf_{x>0}\frac1{x+1}=0$.
Comment: @sizz: Let $A=\operatorname{ran}f$. Suppose that $A$ has a minimum element; call it $u$. We know that $a>0$ for each $a\in A$, so $0\notin A$, and therefore $u\ne 0$, and clearly $u$ isn't a negative number. We also know that for each $\epsilon>0$ there is an $a\in A$ such that $a<\epsilon$, so $u$ cannot be any positive number. Since $u$ is neither positive, negative, nor $0$, $u$ does not exist. Of course since $A$ is bounded below, $\inf A$ does exist; indeed, what I've written is enough to prove that $\inf A=0$.
Comment: @BrianM.Scott, can I do this? Let $\epsilon = 1$, then choose a sequence of $x_n = 1/n\pi$ and show that $|x_{n+1} - x_{n}| = |1/(\pi k(k+1) ) \to 0 $, but $|f(x_{k+1}) - f(x_k)| = |\sin(k \pi) - \sin(k \pi + \pi)| = |0 + 0| \geq 1$, a contradiction
Comment: @sizz: $|0+0|\ge 1$? Are you sure? :-) You could do something similar, though, if you took $x_n=\frac2{n\pi}$ instead, so that $|f(x_n)|$ is alternately $1$ and $0$.
Comment: @sizz: $\sin k\pi$ and $\sin(k+1)\pi$? Yes, they do. But $0$ is not greater than or equal to $1$.
Comment: @sizz: It doesn't contradict anything. What do you think that it contradicts?
Comment: Assume on the contrary that it does converge. Let $\epsilon = 1$. Choosen $x_n = 1/(2\pi n + \pi/2)$ and $y_n = 1/(2\pi n - \pi/2)$. So $|x - y| \to 0$, yet $|f(x_n) - f(y_n)| = 2 < 1$, a contradiction
Comment: @sizz: That's basically correct. However, you mean that $|x_n-y_n|\to 0$ and that $|f(x_n)-f(y_n)|=2>\epsilon$ for all $n$; that's the contradiction.
Comment: @sizz: Not quite. You need the subscripts in $|x_n-y_n|\to 0$, your last inequality goes the wrong way, and it's important that that inequality holds for all $n$. (Actually, it need only hold for infinitely many $n$, but this is crucial and has to be said; and since it does hold for all $n$, it's simpler just to say that.)
Comment: What if I say replace it with $\nless$? Can I ask what your answer (in your initial suggestion) was implying then?
Comment: @sizz: Sure, $\nless$ is fine. In my original answer I suggested that you prove directly that $f$ is not uniformly continuous by showing that there is no $\delta>0$ such that $|f(x)-f(y)|<\frac12$ whenever $|x-y|<\delta$.
Comment: Sorry I should be more specific, what $x$ and $y$ values were you thinking of?
Comment: Would it also be possible to have chosen (for my example) just one $x$ and $y$ value? Say I choose $x = \pi/2$ and $y = 3\pi/2$ and the algebra still would have worked. Of course this choice wouldn't be as general
Comment: @sizz: I gave the $x$ values: they're my $x_n$'s. For the $x$ such that $|x-x_n|<\delta$ but $|f(x)-f(x_n)|>\frac12$ the most obvious choices are $$\frac1{\left(n\pm\frac12\right)\pi}\;.$$ No, one value can't possibly tell you anything. Think about what uniform continuity means: it's not a statement about what happens at one or two points.

An exercise on calculus


Strange decrease in Reputation Score

Question: I am pretty sure my reputation score yesterday was 2095. It was 2080 prior & +15 was added by acceptance of an answer. But when I logged in today it is showing as 2087. I tried looking at https://magento.stackexchange.com/reputation but didn't found any decrease in score infact the whole calculation is showing that my score yesterday was 2072 and +15 was added making it to 2087(which is not correct).
This is not the first time I see my score getting decreased by strange reason, it had happened previously as well but I had not kept note of score so I did not posted a question.
Is there a way where I can get why my score was decreased ? I know it can happen when someone deletes the question for which I earned reputation by making edits/answer. But can I see it in log ?
Thanks
Answer:
I know it can happen when someone deletes the question for which I earned reputation by making edits/answer.

Yes, that's the most likely scenario. It's a difference of 8; that could be an answer with 1 upvote and 1 downvote, or 4 suggested edits. It usually happens automatically on old posts with low scores.
This SEDE query, which looks at a snapshot from the Magento.SE database from last Sunday, tells me you have approved suggested edits on the following questions, all posted about a year ago, which have now been deleted:

https://magento.stackexchange.com/questions/283337/magento-2-search-pages-not-showing-filter-selected-option
https://magento.stackexchange.com/questions/283258/display-b2b-feature-company-structure-in-magento-admin-panel
https://magento.stackexchange.com/questions/283210/email-not-being-translated-viewed-correctly-what-is-causing-the-issue-and-how-c
https://magento.stackexchange.com/questions/283178/magento-1-9-order-total-as-zero-in-sales-orders-reports

Is it fair to lose those points? That's a tough question, but at the very least it's an incentive not to spend too much time on low quality questions.
(I've saved a copy of the query in the Wayback Machine, because tomorrow those records will be deleted from SEDE; almost all information about deleted posts is removed from SEDE.)
Comment: Thanks for given such a detailed info. Just a quick question, So next time whenever I get such behavior I can debug through the query you provided ?
Comment: Yes, if you do it before Sunday morning. Look for questions which are just over a year old (or 30 days / 9 days, see https://magento.stackexchange.com/help/roomba).

Strange decrease in Reputation Score


Does thetaf() in the forecast package in R detect seasonality?

Question: I had a question on the theta method in the forecast package in R. I tried using the AirPassenger example with thetaf(), but it just provided a trend line without seasonality in the forecast. Does thetaf() detect and forecast seasonality?
This is the R code that I used:
library(forecast)
x.fit4 <- thetaf(AirPassengers, h=24)
plot(x.fit4)

Comment: This question was answered by Prof Hyndman.                    Theta method does not handle seasonality.
Comment: Welcome to the site, @forecaster. This question seems to be *only* about how R deals w/ this. As such, it would be off-topic for CV (see our [help page](http://stats.stackexchange.com/help)), but on-topic on [Stack Overflow](http://stackoverflow.com/). If you have a question about the statistical issues w/ this, please edit to clarify; if not, flag your Q & we'll migrate it for you (*please don't cross-post, though*).
Answer: The theta method does not handle seasonality. If you read the help file for thetaf you will see that it says

The theta method of Assimakopoulos and Nikolopoulos (2000) is
  equivalent to simple exponential smoothing with drift.

If you want a method that detects trend and seasonality, use either ets or auto.arima.
Answer: The theta model does not handle seasonality by itself, but the thetaf function in the forecast package does. If you read the help file for thetaf, you will see the following:

The theta method of Assimakopoulos and Nikolopoulos (2000) is equivalent to simple exponential smoothing with drift. This is demonstrated in Hyndman and Billah (2003).
The series is tested for seasonality using the test outlined in A&N. If deemed seasonal, the series is seasonally adjusted using a classical multiplicative decomposition before applying the theta method. The resulting forecasts are then reseasonalized.

(Source.)
If you read the theta model paper, they describe the seasonality test in more detail on page 524.


Running SequentialFeatureSelector with tree base model seems to be wrong

Question: I'm little bit confused about the integration of using feature selection (SequentialFeatureSelector with k_features="best") with RandomForest or XGboost models

When using tree base algorithms like random-forest or xgboost the models are making their own feature selection algorithm (they don't use the whole set of features).

When using feature selection approach with wrapper method, the running model use the X features at each step and run algorithm to tests its score (the score of the algorithm when using X features).

But if we are using SequentialFeatureSelector with RandomForest or XGboost models, the SFS algorithm runs the model on each step with X features (but behind the scene the model gives the score with less (maybe random set of features)).

For example: We can get 10 best features with SFS & XGboost, but after doing some hyper-parameters for xgboost with the dataset of the selected 10 features, we can get winning tree with 6 features.

So is it right using feature selection approach with wrapper method of random forest or xgboost ?
Answer: Random Forest and XGBoost don't select features. They inherently subsample the features at each tree/boosting iteration, which is part of their procedure to fight with overfitting. So, XGBoost doesn't produce a winning three with, say, 6 features.
The feature selector algorithm can use any estimator, and it selects the features greedily (either forward or backward) based on the scoring function.


How to calculate a changing probability situation based on possible improvement? Can this problem not be solved precisely, just estimated?

Question: A guy wants to win a stuffed animal bear for his girlfriend at a local carnival.  To get one requires winning a bean bag toss game where you try to toss it into a small hole. The guy goes to the local carnival a day early to practice solo.  He only practices $15$ tosses which is $3$ complete games of $5$ tosses each.  During the 1st, 2nd, and 3rd games he gets in $0$, $1$, and $2$ respectively.  He feels confident that he is improving so he stops.
The next day he goes to the carnival with his girlfriend and he must make any $3$ in out of $5$ in a single game to get the medium prize which is the bear she wants.  He feels that since he improved consistently during practice that he can make $3$ out of $5$.  He is nervous and misses the first shot but then makes the next $2$ shots so he only needs $1$ more out of $2$ shots to win the bear.
Question is what is the probability that he will actually make $3$ out of $5$ in this current unfinished game?  Do we base it on his lifetime of $5$ out of $18$ ($27.8$%) or do we somehow have to factor in that he has improved from $0$% the first game, to $20$% the 2nd game, to $40$% the 3rd game, to $66.7$% and still going in the 4th game? That is, should we account for the idea that he may be improving based on skill/practice and consider that in our model?  If so, what is the probability he will make $1$ of the last $2$ shots to win the bear and how do we compute that?  Assume that if he makes the 4th shot he will intentionally miss the 5th shot so he is assured of getting the bear and not a bigger prize.
Is there an exact answer to this question or would it be just an estimate?  For example, could we average his lifetime % of $27.8$% with his current "streak" of $66.7$% and come up with $47.25$% he will make shot # $4$?  If we do that, we didn't fully consider his consistent improvement during practice.
Many probability questions have fixed % outcomes such as a card draw or a coin toss but this one has changing probability so it is different.  I am curious how mathematics can handle a problem like this.
Comment: this question can't really be answered rigorously without making additional assumptions
Comment: Too much text. Can you be more precise?
Comment: More precise about what?  I am asking what is the probability he will make 1 of the last 2 shots based on the history I gave in the body of the question.
Comment: @mm-aops:  Well go ahead and make the assumptions but just state what they are in your answer(s).
Comment: Assuming each toss is independent of each other (which may not be true since if misses maybe he is more likely to miss on next shot) and each toss has same probabiltiy to be made (identically distrbuted bernoulli trials essentially) law of large numbers would say that 5/18 would be good estimate.
Comment: The thing is each toss is NOT independent of each other because he is improving.  Imagine something fairly easy but that you never did before.  You might do awful the first few tries but will likely quickly get better.  This problem is similar.  So how does Math handle this type of changing probability situation?  I suspect it has to be approximated and that there is not hard and fast rule(s) for it.  Is my answer to my own question reasonable or is there some better way to predict the outcome of this scenario?
Comment: Changing probabilities isnt managed as a beta distribution?
Answer: First, the problem as stated needs additional assumptions to have a clear-cut solution. Make sure you understand why, as it's quite key to understanding how to properly model a real-life problem with probability theory.
My personal take would be to see this as a latent variable / Hidden Markov Model (HMM) situation. General intro on HMM here : http://en.wikipedia.org/wiki/Hidden_Markov_model.
You could introduce a variable $Y_n$ corresponding to the $n$-th shot's outcome, and a hidden variable (or latent state) $X_n$ corresponding to the player's skill at time $n$. Assuming the player's success at time $n$ only depends on $X_n$ and not on $Y_{< n}$ (e.g. our guy does not stress out if he missed...), and $X_n$ only depends on $X_{n-1}$, our situation is perfectly described by the HMM below (illustration source here) :
Now you still need to make a handful of modeling assumptions, namely :

a value range for $X_n$ (for instance $\{u^1, u^2, u^3\}$ = $\{$bad, average, good$\}$)
a transition probability function : $P(X_n | X_{n-1})$ (for instance $P(u^i | u^i) = \alpha = 2/3$ and $P(u^{i+1} | u^i) = 1-\alpha$ if we assume the player can only get better with time)
an output probability function : $P(Y_n | X_n)$ (i.e. in above's notations $P(\text{success} | u^i)$ for all $i$'s).

Once you've done all this, your problem is one of inference, namely calculating $P(Y_n | y_1, ..., y_{n-1})$ (where we use the common convention: $Y$ is the random variable and $y$ is a realisation of $Y$). The method for resolving this is way beyond this site's scope of course ...
PS : That's just a very simple approach of HMM described in layman's terms. The roughest assumption made here is guessing/fixing the model's parameters once and for all. The bayesian way would be to leave all parameters (i.e. the $a_{m,k} = P(X_n = u^m | X_{n-1} = u^k)$ and $b_k = P(Y_n = \text{success} | X_n = u^k)$) open and then to calculate $P(Y_n | y_1, ..., y_{n-1})$ by averaging over the model's parameter space (given $y_1, ..., y_{n-1})$). This paper http://mlg.eng.cam.ac.uk/zoubin/papers/ijprai.pdf mentions this technique, look for the words "predictive distribution".
PPS : Another approach could be to see the situation as a mixture model (MM) problem. Wikipedia link : http://en.wikipedia.org/wiki/Mixture_model. It's far less appropriate than HMMs but you may find it easier to understand.
In a nutshell, the typical MM example is one of a bag of $K$ indistinguishable coins which are of two types, each type in an unknown proportion $a_1 K$ and $a_2 K$ and having a given unknown flip bias, say $b_1$ and $b_2$. You start to pick one coin at random, and you flip it $m$ times. Then you put the coin back in the bag and you start again, $n$ times. The goal is to determine best estimates of $\theta = (a_1, a_2 = 1-a_1, b_1, b_2)$ from the outcome of the experiment. Then, with your parameters estimated, it's easy to evaluate the distribution of your next marginal draw. The common technique to estimate $\theta$ is called Expectation maximization (EM) and is described quickly in the wikipedia link above. Intuitively, if you see in your data that in 20% (resp. 80%) of the draws, the proportion of faces is between 10% and 30% with an average of 22% (resp. between 55% and 70% with an average of 63%), you're tempted to conclude that $a_1 = 20\%$, $a_2 = 80\%$, $b_1 = 22\%$ and $b_2 = 63\%$. Also, if a draw has a majority of faces, it's highly probable that the coin in that draw was of type 2. EM formalizes that and does a bit more...
Now, you could say that in your problem the player is, for each game $n$, either Type 1 (good) or Type 2 (bad) (MM works with more than 2 categories but let's keep it at two), with the probability $p$ of him being good unknown to you, and that in each state his probability of success is $b_1$ and $b_2$. Run EM (or any other method), it will give you best estimates for $p$ and $b_i$. It will also give you, for each game $n$, the probability that the player was good in this particular game, say $q_n$. Here comes the fiddling : then plot $n \mapsto q_n$, hopefully it should be roughly increasing and come up with an extrapolation/approximation that will give you a guess (let's not call it an estimate) for $q_{n+1}$. A best guess for your probability of success in the future game $n+1$ is now $P(\text{success}_{n+1}) = q_{n+1} \hat b_1 + (1-q_{n+1}) \hat b_2$. Heck, it's really dirty, as some assumptions here are self-contradictory, but it's a start and my old physics teacher would have been satisfied with it.
Comment: Have you read the answer and the links ? You can also check this one  about latent variables in general to see how/why your concept of "player's skill" can/should be modeled with a latent variable. Not knowing *ex ante* what your math level is, it was hard to provide the answer you expected. But any *proper* answer would have to be undergrad level imho.
Comment: My profile states I am not a math major but I am college educated in Computer Science so I only have very basic math skills but I can do simple probability problems.  I like to try to keep math solutions as simple as possible.  I don't yet see how any modelling solution can "beat" my simple solution because my weighted solution accounts for his improving ability.  I guess I could have added more info such as an "elite" level bean bag tosser (such as the attendant) "maxes" out at about 75% make rate so we can assume the guy trying to win the bear will never do better than that.
Comment: Let's not fight over who should have done what. You asked what "the field of mathematics" (so mathematicians ?) has to say about your problem, I made an attempt at answering that in simple terms, try to see through it. Worst case you will get a sense that probability theory is hard...
Answer: If I had to answer this question myself, I would say that I see a pattern of consistent improvement so I would assign "weights" to each game.  For example, his first game he got $0$ in so that would be assigned a weight of $0.1$.  His 2nd game he got $1$ in and that has a weight of $0.2$.  His 3rd game he got $2$ in so that has a weight of $0.3$.  His 4th partial game he got $2$ of $3$ in so that has a weight of $0.4$.  The higher valued weights mean that run is more significant because it is more recent and better reflects his improvement and current skill level.
So here is the math.
Game $1$:    $\ \   0$%    weighted $0.1$.
Game $2$:   $20$% weighted $0.2$.
Game $3$:   $40$% weighted $0.3$.
Game $4$: $66.7$% weighted $0.4$.
Adding up the weighted percentages we get $0$% + $4$% + $12$% + $26.67$% = $42.67$%.
One thing to consider is game $4$ has not been completed so it is debatable whether it should have a $0.4$ weighting or not.
I don't know how accurate this is but it seems reasonable. This would be the estimated probability he will make the 4th shot, however, it doesn't answer the original question fully.  For example, he may miss the 4th shot and not yet win the game.  Then we would have to compute the probability of him making the 5th shot.   If he makes the 4th shot or the 5th shot he will win so that is the probability I am looking for.
So let's try to get a final probability.  If he misses the 4th shot, he must then make the 5th shot to get the intended prize.  Well at that point he will be $2$ out of $4$ in game $4$ and the pressure is on cuz it is a "must make" shot.  We have no data for "pressure" shots so I would have to say his chance of making the final (5th) shot is maybe $1$ in $3$.  So then the chances of him missing both the 4th and 5ths shots would be ($1 - 42.67$%) * ($1 - 33.33$%) = $38.22$% which means there is a $61.78$% chance he will win the bear prize.
Comment: Is there any theoretical tool you're thinking of when doing your weighted average sums?
Comment: I am not sure what you mean by theoretical tool.  To me it seems that his more recent shots are more significant than "old" shots but they all count since they are all part of his history for the game.  The purpose of this type of word problem is to get a general idea how to model a situation where the probability is changing (the person is getting better at the game).  This is unlike random die tosses and random card draws where the probability is "constant".
Comment: My point was just to draw your attention on the fact that probability theory is quite a demanding (easily misleading) tool and you should in general stick to implementing tools/lines of reasoning found in classes and books. See my proposed answer for an example of theoretical framework. Note that your answer is equivalent to assuming that Game $i$ was repeated $i$ times and all *pseudo-games* are i i d.
Comment: I took the "simple mans" approach to coming up with a model to predict his more recent shot probabilities based on his improving history.  I don't remember ever seeing a problem like this in my college discrete math class so I was curious about it.  So many probability word problems I see make the assumption that the probability of some trial such as making a basketball free throw shot stays constant during some event such as shooting 10 free throw shots but in reality, the shooter could be improving in that time, thus changing his individual trial probability. This question addresses that.
Comment: I doubt any serious solution would be sub-undergraduate level, but let's see what other people come up with
Comment: I think my weighted solution is not bad and is simple to understand. I don't think there is any exact answer to this question since we don't know if the person is improving at a steady repeatable rate and we don't know what other factors are involved such as the "choke" factor when he only needs $1$ more make to win the prize. However, I suspect my extremely simple model is a reasonable approximation to the real probability of him making the next shot. So to calculate if he will make $1$ of his last $2$ shots in game $4$, it should be a straightforward calculation.
Comment: You probably just accessed the site from a non-logged-in browser session


PrimeReact menu not compiling

Question: I'm trying to have a PrimeReact popup menu working following the documention.
I created a new project with tsx.
I tried
import 'primereact/resources/themes/saga-blue/theme.css'
import 'primereact/resources/primereact.min.css'
import 'primeicons/primeicons.css'
import {Menu} from "primereact/menu";
import {useRef} from "react";

const Header = () => {
    let menu = useRef(null);
    let items = [
        {icon: 'pi pi-cog', label: 'Configuration'},
        {icon: 'pi pi-info-circle', label: 'About'}
    ];
    return(

Test

            <Menu model={items} popup ref={menu} id="popup_menu" />

 menu.current.toggle(event)} aria-controls="popup_menu" aria-haspopup/>

    );
}

export default Header

When compiling it gives me
Object is possibly 'null'.  TS2531

    19 |
Test

    20 |             <Menu model={items} popup ref={menu} id="popup_menu" />
  > 21 |
 menu.current.toggle(event)} aria-controls="popup_menu" aria-haspopup/>

       |                                                                      ^
    22 |

    23 |     );
    24 | }

What am I missing ?
I also tried creating a new project with jsx instead of tsx.
And it is working.  So the problem is coming from tsx.
But why ?  And how to solve it ?
I eventually found a solution
use
let menu = useRef`<Menu>`(null);

and
onClick={(event) => menu?.current?.toggle(event)}

Comment: can you add a ! at the end of the onClick function and see if it works? something like: `(event) => menu.current.toggle(event)!`
Comment: I tried but still the same problem.
Comment: So basically it is trying to warn you saying there is a chance that the value could be `null`. Adding `!` should have told it that you are confident that the value will not be `null`. Try optional chaning `(event) => menu?.current?.toggle(event)`. If it still errors out I'm gonna double thing my carrier choices
Comment: I'm sorry to tell you ... it is also not working :-)  But the problem is elsewhere.  See my edited question.  Thanks anyway.
Comment: With menu?.current?.toggle(event), it now tells me Property 'toggle' does not exist on type 'never'
Comment: I eventually found a solution.  Don't know if it is THE solution or if it is only a trick.
Answer: I was having this issue today. The solution from OP confused me a lot. I copy pasted exactly what OP posted which is:
let menu = useRef`<Menu>`(null);

and that does not work. I'm not entirely sure if this worked for OP or what, but the solution for me is to use the following:
let menu = useRef<Menu>(null);

My menu component looks like this:
<Menu model={menuItems} popup ref={menu} aria-controls="popup_menu" aria-haspopup />

And my button to show the menu looks like this:
<Button icon="pi pi-bars" onClick={(event) => menu.current?.toggle(event)}/>

If anyone is copy-pasting this to test, i used the following for menuItems:
const menuItems = [
    {label: 'New', icon: 'pi pi-fw pi-plus'},
    {label: 'Delete', icon: 'pi pi-fw pi-trash'}
];

PrimeReact menu not compiling


How can I make db_query SELECT LIKE case insensitive?

Question: I'm querying for an email address where I can't force the case of the search term or the data in the table. It's an API thing.
How can I convert this query to be case insensitive?
<code>$results = db_query(
 'SELECT email_address
  FROM email_address_table
  WHERE (email_address LIKE :mail)',
  array(':mail' => '%' . db_like($mail) . '%')
)->fetchAll();
</code>
Answer: The typical way to accomplish this is to compare a lower-case version of you search string against a the lower-cased variant in the table. See below for an example using strtolower() and LOWER():
<code>$mail = strtolower($mail);

$results = db_query(
 'SELECT email_address
  FROM email_address_table
  WHERE (LOWER(email_address) LIKE :mail)',
  array(':mail' => '%' . db_like($mail) . '%')
)->fetchAll();
</code>
Comment: Points! One corollary bit of info that came up. When doing a string comparison on a blob explicitly convert it to a string ala LOWER(CONVERT( @string_variable USING latin1)). Or whichever charset works for you.


Change of variable in an integral that contain a gradient

Question: Let $\Omega\subset{\mathbb{R}^3}$ be a bounded lipschitz domain and $D$ be a $3\times 3$ real invertible matrix.
For a fixed $x\in\Omega$, consider the following integral, defined in the principal value sense
$$
A(x):=\int_{\Omega}\nabla_yg(x-y)\cdot u(u)\;d(y)
$$
where $\displaystyle g(x-y)=\frac{1}{|x-y|}$ and $u\in (L^2(\Omega))^3$ (the space of square integrable functions).
Then, if we do the change of variable $y=Dz$, how the last integral become?
Answer: Notice that $\nabla_y= D\nabla_z$, so (if I did the change of variables right!) your integral becomes
$$
A(x)= \int_{D^{-1}\Omega} D^{-t}\nabla_z g(x-Dz)\cdot u(Dz) |\det(D)|\, dz.
$$
Comment: thank you. But I did not understand how to prove that $\nabla_y=D\nabla_z$. Could you please clarify it to me ?
Comment: @SAKLY: I made a mistake; it should be $\nabla_y = D^{-1}\nabla_z$ (for instance the chain rule would give $$\dfrac{\partial g}{\partial y_i} =\sum_j \dfrac{\partial g}{\partial z_j}\dfrac{\partial z_j}{\partial y_i},$$ and the partials of $z$ with respect to $y$ involve $D^{-1}$.


ARIMA quantile regression in R

Question: I would like to perform a quantile regression of a autoregressive integrated moving average (ARIMA) model (p,0,q) of a stock return in R. My question is: how can I include the moving average process in the regression? I read I need to use rq (which is available in "quantreg" package) but I cannot follow the procedure for an ARIMA case. Can anybody help me pls?
packages used and code until now:
library(quantmod) #to get the stock prices
library(quantreg) #to get the function for quantile regression
ticker <- c("AAPL")
myenv <- new.env()
symnames <- getSymbols(ticker, env=myenv)
ts <- do.call(merge, eapply(myenv, Ad)[symnames])
rt <- diff(log(ts), lag = 1)
rt_final <- rt[-1:-1,]
fit_rt<-auto.arima(rt_final); summary(fit_rt)
x <- fitted(fit_rt)
y <- cbind(x, lx = lag(x),llx=lag(lag(x))) #include two for now
qregr <- rq(x ~ lx + llx, data = y) #this is where I need to include the MA(2) process, right?
qregr <- rq(x ~ lx + llx, tau = seq(0.05, 0.95, by = 0.05), data = y); summary(qregr)
plot(qregr)

thanks,
Comment: What is the rq function, and where did you read about it?
Answer: From the comments in Generating quantile forecasts in R:
Larry Pohlman: For the quantile forecast question you can use the R "quantile" function or the quantile regression function "rq"
Rob J Hyndman: You can only use the quantile function if you can simulate future sample paths of the time series (unless you want to assume iid data). I'm not sure how you would use "rq()" without assuming a linear regression model which is usually too restrictive for forecasting.
Larry Pohlman: strictly speaking quantile regressions are only linear if the residuals are homoscedastic.Otherwise the quantitle regression generates a family of linear functions for every quantile. Check Roger Koenker's papers / book
Rob J Hyndman: I've read Koenker, and I've used rq. Homoscedasticity will give you parallel lines. I don't want parallel lines, and I don't even want linear functions, or a family of linear functions. Forecast quantiles are almost never linear.

ARIMA quantile regression in R


Extract email addresses from composite field type using Computed Twig

Question: I am using a custom composite field type to gather multiple pieces of data from a user. This custom composite field type contains a field which gathers the email addresses entered.
What I am trying to do is use a Computed Twig field to extract the email addresses entered within the custom composite field type and use an email handler to send a confirmation email to all those email addresses, however, I am having real trouble trying to reference a field inside a composite field type. I have used multiple pieces of twig code, but all I seem to be able to reference is the values from all the fields in the custom composite and not a specific field.
I am really new to twig, so do not understand the full capabilities yet, but does anyone know how to reference a field value inside a composite field type, using twig?
Comment: A twig template is probably not the best place for this type of logic. Are you wanting to send emails each time the entity is viewed, on cron run or something else? Then you can use the relevant hook or event to trigger the sending of emails. I can be more specific if you can provide some more details. Twig should mainly be used for presentation.
Comment: Thanks for the tip!

Essentially, the custom composite field allows a user to enter multiple entries of data, in this case, an email address. When the user submits the form, the email addresses entered would need to be compiled into an email handler, so an email can be sent to each email address entered.

Are those details more helpful to narrow down a method to achieve this? I am not familiar with hooks to be honest.
Comment: What kind of form is it? Are you creating a node/entity or submitting a webform or is it a custom form? If it's your own custom form, the submit handler for the form could be used to send the emails.
Comment: @imclean It is just a standard form using the webform module. Usually, in the webform module, you can just insert the machine_name of the field into the email handlers 'To' field, however, because the field 'email address' is contained within a custom composite field, you cannot seem to reference the field value.

What would be required to create a submit handler?
Comment: You could use hook_form_alter() to add your own submit handler, but webform provides a pluggable handler system so it's best to use that: https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-programmatically-add-a-handler-to-a-new-webform
Comment: See also: https://www.drupal.org/docs/8/modules/webform/webform-cookbook
Comment: Sorry, that first link wouldn't be very helpful but see the second. Here's an example: https://git.drupalcode.org/project/webform/tree/8.x-5.x/modules/webform_example_handler
Answer: I'll provide 2 links as an answer, but it has really been answered by others.

Write custom webform handler:

How to create a custom Webform handler to submit to a SOAP API

Use hook_form_alter() to add a custom submit handler.

Add a custom submission handler to a form
Drupal 8 version of hook_form_alter(): https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21form.api.php/function/hook_form_alter/8.8.x


"Syntax error" while writing OCaml function?

Question: I am writing a function in OCaml to raise x to the power of y.
My code is:
#let rec pow x y =
if y == 0 then 1 else
if (y mod 2 = 0) then pow x y/2 * pow x y/2 else
x * pow x y/2 * pow x y/2;;

When I try to execute it, I get an error for syntax in line one, but it doesn't tell me what it is.
Answer: When you wrote the code, did you type the #? The # is just a character that the OCaml REPL outputs to prompt for input; it is not part of the code. You should not type it.
Here are some other errors that you should fix:

== is physical equality in OCaml. = is structural equality. Although both work the same for unboxed types (such as int), it's better practice to do y = 0. Note that you use =, the recommended equality, in the expression y mod 2 = 0.
You need parentheses around y/2. pow x y/2 parses as (pow x y) / 2, but you want pow x (y / 2).


Is there a solution for $y\sqrt{y^2 + 1} + \sinh^{-1}(y) = x$?

Question: Is there a closed form solution for $y\sqrt{y^2 + 1} + \sinh^{-1}(y) = x$?
I would like to invert the arc length of a parabola so I can parameterize it with a constant speed.
Comment: I don't think I've ever seen anybody construct a natural parametrization of the parabola, or even an intrinsic equation.
Answer: Hint: inverse hyperbolic functions can be expressed in terms of logarithms:
$$y+\sqrt{y^2 + 1} + \sinh^{-1}(y) = y+\sqrt{y^2 + 1} + \log(y + \sqrt{y^2+1})= z + log(z) = x$$
where $z = y + \sqrt{y^2+1}$
The last equation can be expressed in a closed form only by using the Lambert W function
Edited: Sorry, I misread the first term (are you sure you got it right?). This turns the equation almost hopeless to find a closed form solution.
Comment: Yes, it's a simplified version of $\int \sqrt{4x^2 + 1}\ dx$. ([W|A](http://www.wolframalpha.com/input/?i=integral+sqrt%284y%5E2+%2B+1%29))


Which Powerlifting federations and hence competitions comply with WADA's anti-doping policies?

Question: Rumoured that not all Powerlifting federations are under WADA that means that they do not comply with anti-doping policies. So some competitions allow the usage of dopings while others not. So
Which powerlifiting competions comply with WADA's anti-doping policies?
Answer: The wordrecord news meantions that IPF to be the only Powerlifting federation that complies with WADA's anti-doping policies:

"When a National Federation has received an Adverse Analytical Finding on one of its Athletes it shall report the following information to the IPF and WADA within fourteen (14) days of the process described in Article 7.1: the Athlete's name, country, sport and discipline within the sport, whether the test was In-Competition or Out-of- Competition, the date of Sample collection and the analytical result reported by the laboratory." Their anti-doping site.

and IPF website is in International Powerlifting Federation and the Prohibited List.
IPF and Exemptions forms in the case of needed medications
Please note that if you are asthmatic, you need to file TUA 30 days before the competition by this

"Wherean athlete needs to use beta 2 agonists as a treatment for asthma he/she needs a   TUE in advance (TUE application should be submitted no later than 30 days before the Athlete needs the   approval, for instance an Event)"

and medications such as Glucocorticosteroids are prohibited so

Therapeutic Use Exemption (TUE application)
International Standard for
Therapeutic Use Exemptions (ISTUE)
Declaration of Use (DOU application)

Supplements contaminated with steroids
Notice that many commercially available supplements nowadays can be contaminated with prohibited steroids and may not manufactured in clean environments

"From the anti-doping perspective, the danger with many commercial supplements is that they may be tainted with prohibited substances.  Alarmingly high rates of such contamination have been documented in independent analyses of supplements purchased over the counter in health food shops or the like." Q8

IPF Competitions and Testing In Competitions and Outside Competitions
There are rules governing things such as comebacks and stopping competitions because the OCT (Out of Competition Testing) random tests are going all the time. The athletes need to report locations with a software every day so that they are available for tests. ICT (In-Competition Testing) does not require this but to stop OCT, the athlete must do a report.

"If a retired athlete wishes to come back to competition he or she must give written notice of that to the IPF.  From the date that notification is received, the athlete must wait 6 months before they can again compete and in that time they are subject to OCT."


Find all roots of the equation $2x^3+x^2+75x-81=0$

Question: Find all roots of the equation
$$2x^3+x^2+75x-81=0$$
Please check my work,
Let $P(x)$ : $2x^3+x^2+75x-81=0$
$ 2\left(x-\frac{1}{6}\right)^3 + \left(x-\frac{1}{6}\right)^2 + 75\left(x-\frac{1}{6}\right)-81 = 0$
$2x^3 + \frac{1}{6}x - \frac{1}{3}x +75x-\frac{1}{108}+\frac{1}{36}- \frac{75}{6}-81 = 0$
$2x^3 + 74\frac{5}{6}x - 93\frac{13}{27}=0$
$x^3 + 37\frac{5}{12}x - 46\frac{20}{27}=x^3+px+q = 0$
Let $u, v \in \mathbb{R}$ and $u+v$ be the real root of the equation.
By Cardano method,
$u^3v^3 = \frac{-\left(37\frac{5}{12}\right)^3}{27} = -\frac{p^3}{27}u^3+v^3 = 46\frac{20}{27} = -q$
$p=37\frac{5}{12}, q= -46\frac{20}{27}$
$\{u^3, v^3\}= \left\{\frac{-q}{2}-\frac{1}{2}\sqrt{q^2+\frac{4p^3}{27}}, \frac{-q}{2}+\frac{1}{2}\sqrt{q^2+\frac{4p^3}{27}}\right\}$
choose $u, v$ for which $uv = -\frac{p}{3}$
$\{u, v\}= \left\{\sqrt[3]{\frac{-q}{2}-\frac{1}{2}\sqrt{q^2+\frac{4p^3}{27}}}, \sqrt[3]{\frac{-q}{2}+\frac{1}{2}\sqrt[3]{q^2+\frac{4p^3}{27}}}\right\}$
Thus, roots of the equation are
$u+v-\frac{1}{6}, u\omega^2+v\omega-\frac{1}{6},u\omega+v\omega^2-\frac{1}{6} $ , where $\omega = cis\frac{2\pi}{3}$
Comment: I am just putting forward an idea. I know my method would be very complex but you can try making realtions with roots such as- (alpha×beta×gamma)= (-d/a). Simmilary get relations for (alpha+ beta+ gamma) and also for (aplha×beta + beta×gamma + gamma×apha). Now you have 3 equations and 3 variables and now just solve.
Comment: you will Need this here https://math.vanderbilt.edu/schectex/courses/cubic/
Comment: The basic techniques don't work well here and it has complex roots, so my guess is that you need to use the full formula for the roots.
Comment: Is it maybe $2x^3+3x^2+75x-81=0$ or $2x^3+x^2+78x-81=0$?
Answer: $$2x^3+x^2+75x-81=2\left(x^3+\frac{1}{2}x^2+\frac{75}{2}x-\frac{81}{2}\right)=$$
$$=2\left(x^3+3\cdot\frac{1}{6}x^2+3\left(\frac{1}{6}\right)^2x+\left(\frac{1}{6}\right)^3+\left(\frac{75}{2}-\frac{1}{12}\right)x-\frac{1}{216}-\frac{81}{2}\right)=$$
$$=2\left(\left(x+\frac{1}{6}\right)^3+\frac{449}{12}x-\frac{8749}{216}\right)=$$
$$=2\left(\left(x+\frac{1}{6}\right)^3+\frac{449}{12}\left(x+\frac{1}{6}\right)-\frac{449}{72}-\frac{8749}{216}\right)=$$
$$=2\left(\left(x+\frac{1}{6}\right)^3+\frac{449}{12}\left(x+\frac{1}{6}\right)-\frac{1262}{27}\right).$$
Thus, we need to solve the following equation
$$y^3+py+q=0,$$
where $y=x+\frac{1}{6}$, $p=\frac{449}{12}$ and $q=-\frac{1262}{27}$.
It's obvious that our equation has unique real root
because for example $$\left(\left(x+\frac{1}{6}\right)^3+\frac{449}{12}\left(x+\frac{1}{6}\right)\right)'=3\left(x+\frac{1}{6}\right)^2+\frac{449}{12}>0.$$
Let $y=u+v$ is a root of the equation $y^3+py+q=0$.
Hence, $$u^3+v^3+3uv(u+v)+p(u+v)+q=0$$ or
$$u^3+v^3+q+(u+v)(3uv+p)=0.$$
Let $uv=-\frac{p}{3}$.
Hence, $u^3+v^3=-q$, which says that $u^3$ and $v^3$ are roots of the equation
$$z^2+qz-\frac{p^3}{27}=0$$ or
$$z^2-\frac{1262}{27}z-\frac{1}{27}\left(\frac{449}{12}\right)^3=0,$$
which gives
$$x=-\frac{1}{6}+\sqrt[3]{\frac{631}{27}+\sqrt{\left(\frac{631}{27}\right)^2+\frac{1}{27}\left(\frac{449}{12}\right)^3}}+\sqrt[3]{\frac{631}{27}-\sqrt{\left(\frac{631}{27}\right)^2+\frac{1}{27}\left(\frac{449}{12}\right)^3}}$$
Comment: @amWhy I think it would better if I'll write a full solution. What do you think?
Comment: Sure, if you'd like to!  I'd be willing to upvote your answer if it's written well to address the level of the asker.  And even if it's at any level, since the asker hasn't made clear his/her needs, level of study, etc.
Comment: Nice work, @Michael


A power even smaller than Fermat's Little Theorem suggests?

Question: So I know that Fermat's little theorem states: let $p$ be a prime number, let $a$ be an integer where $p \nmid a$. So $a^{p-1} \equiv 1 $ (mod $p$).
But is it possible to prove that there is some smaller power of $a$ that is congruent to $1$ as well?
If I can find some integer $k$ where it is the smallest positive integer so that $a^k \equiv 1$ (mod $p$) then how can I prove that $k \mid (p-1) $ as that would complete the proof in stating that there IS some smaller power than $p-1$.
Comment: $k\mid (p-1)$ would not prove *that*, since trivially $(p-1)\mid (p-1)$. If you're looking for a smaller $k(a)$ that works for *a single* $a$, then for some $a$ you can find it. Trivially, $1^1\equiv 1\pmod p$ and, $k(a^2)=\frac{p-1}2$ works for $p\ne2$. However, if you are looking for a $k$ which works for all $a$ coprime with $p$, you are ultimatley interested in [Carmichael's function](https://en.wikipedia.org/wiki/Carmichael_function). However, Aryabhata answered the question for primes $p$.
Comment: There isn't always a smaller power, but there can be.
Answer: Of course it's possible for some $a$.  For example, if $a = -1$, then we have $a^2 \equiv 1 \pmod{p}$ regardless of $p$.  For others, $p-1$ is the smallest positive integer for which this holds, e.g. $2$ in $\mathbb{Z}_5$ or $3$ in $\mathbb{Z}_7$.  If the latter is the case, we call $a$ a primitive root modulo $p$.  This is number-theoretic terminology expressing the fact that $\mathbb{Z}_p^\times$ is a cyclic group and $a$ is a generator of it (which is not necessarily unique).
To answer your second question, let's suppose the multiplicative order of $a$ in $\mathbb{Z}_p^\times$ is $k < p-1$. The division algorithm lets us write $p\!-\!1 = qk + r$ for some $0 \leq r < k$ and $q \in \mathbb{N}$.  Thus, $a^{p-1} = a^{qk + r} = a^{qk}a^r = (a^k)^qa^r = 1$.  What's $(a^k)^q$?  What must be true of $r$?
So it is true that the order will divide $p\!-\!1$.  However, finding the multiplicative order of an element modulo $p$ is computationally difficult$^\dagger$.  If we have at least been blessed with the prime factorization of $p\!-\!1$, we have to essentially brute force the possibilities, dividing off a given prime factor until the exponentiation no longer yields $1$, then moving on to the next prime factor.

$^\dagger$This is a discrete log problem. No polynomial-time algorithms for classical computers have yet been discovered for this task.
Answer: For a fixed $a$, it is definitely possible. Notice that if $a=1$ then $k=1$ works. For a slightly less trivial example, $4^4=1\pmod{17}$. However, there is no smaller power that works for all values of $a$. Numbers that require an exponent of $p-1$ exactly are called primitive roots. It is a famous theorem that for every prime, there is at least one privative root (in fact there are several, because if $GCD(p,q)=1$ then $g$ is a primitive root (also called a "generator") if and only if $g^q$ is.
Now, suppose $a^k=1\pmod{p}$. We want to prove that $k|p-1$. Since $p$ is prime, we know that there exists some primitive root, $g$. If we look at the set $\{g,g^2,\ldots , g^{p-1}\}$ we see that every number in $\{1,\ldots p-1\}$ shows up precisely once. To prove that this is the case, notice that since there are $p-1$ possible values and $p-1$ locations, every number at least once if and only if every number shows up at most once. WLOG let $p>m>n>0$. If $g^m=g^n,$ then $g^{m-n}=1\pmod{p}$. But this contradicts the fact that $g$ is a generator. Thus every number shows up at most once and so every number shows up exactly once. Since every number shows up exactly once, for some $m$ $g^m=a$. Then $1=a^k=g^{km}$ so $km=p-1$ since $g$ is a generator. Thus $k|p-1$.
Answer: There isn't.
The group $\mathbb{Z}/p^{*}$ is cyclic.
See also: primitive roots and carmichael function.


Books for further math self study after APs/A levels?

Question: I am almost done with my A levels ( AP's in america) and I've become very fond of math and I wish to further study it myself and not for any examination. If someone could recommend me a book regarding a topic of math they found interesting to study after their Highers were over it would be much appreciated. Also I plan on choosing computer science as my university major so I wont be introduced to the more difficult and fun areas of mathematics.
Answer: Well I found that for myself, the area of math which drew me the most was Calculus by far. In high-school, Single Variable Calculus is introduced, with such good books as
"Stewart 7e Early Transcendentals" is a good foray into Single-Variable Calculus, the study of functions of the form $f(x)$. I would also start looking into differential equations in functions of a single variable.
But why stop there? In the real world, there are several applications of Multivariable Calculus, functions of the form $f(x,y,...)$ as well as vector calculus, the study of functions of the form $\vec{f}(t)=[f_1(t),f_2(t),f_3(t)]$.
In fact, especially if you plan to go into computer science, much of electrical circuit analysis depends on equations involving vector functions, and their derivatives.
For making the transition from single variable into multivariable calculus, or even from single variable into vector calculus, and even a little of differential equations, all of Paul Dawkins Online Notes are really good places to start. There's plenty of info there. These are his calculus pages:
http://tutorial.math.lamar.edu/Classes/CalcI/CalcI.aspx
http://tutorial.math.lamar.edu/Classes/CalcII/CalcII.aspx
http://tutorial.math.lamar.edu/Classes/CalcIII/CalcIII.aspx
http://tutorial.math.lamar.edu/Classes/DE/DE.aspx
Also, to go further into vector calculus/multivariable calculus, tensor calculus is a good place to jump after.
I'd recommend these books for Tensor Calculus:
http://www.ita.uni-heidelberg.de/~dullemond/lectures/tensor/tensor.pdf
"Introduction to Tensor Analysis and the Calculus of Moving Surfaces" by Pavel Grinfeld
Hope that's a good start! There's a lot of good stuff in the world of Math! Don't abandon it. I myself am in a Biochemical/Medical Science major at a university, but, like you still stayed curious about it. Stick with it! It'll turn up in a lot of places throughout your degree.
Comment: My A levels syllabus does include the integration/ differentiation of multiple variables along with single variable differential equations. Thank you so much for your answer.
Comment: Anytime! Definitely if you've gone to that level, the next progression should be vector, then tensor calculus, then differential geometry. They unite alot of the ideas already found. Have fun!


Creating a Context Menu with React-Redux

Question: We use Redux in large parts of our React application. One area where we struggle with is the context menu. Up to now it worked like this:
onRightClick -> createItems -> openMenu -> onItemClick: invoke callback and close menu

So we had a callback in each item when it is clicked. With Redux, that no longer works, because:
dispatch(actionCreator_openContextMenu(items))

... performs a store update. The Redux action returned by the action creator cannot have callbacks in it, because they are not serializable/jsonizable.
We furthermore need to perform asynchronous operations (i.e. server roundtrips) in many context menu click actions, so the click actions are not plain store updates.
The question is: how does this align with the Redux pattern and its constraints? How would one do this with Redux?
To clarify: this question is not about the UI side in react, it's about redux.
Answer: I actually wrote an article that covers this exact question: Creating Reusable Generic Modals in React and Redux.  The approach I described in that article can be summarized as having the code that requests the dialog include a pre-made action object that gets passed to the dialog component as a prop, and the dialog can then dispatch that action (possibly with additional info attached) when it's closed.
A couple other options:

Have the dialog dispatch some "signal" action when it closes, and use sagas or observables to execute the additional async logic in response
There's an interesting-looking library called redux-promising-modals.  I haven't used it yet myself, but it appears to have a prebuilt middleware and reducer for tracking a lost of open modals.  The middleware returns a promise whenever you dispatch PUSH_MODAL_WINDOW, and will resolve the promise when you dispatch the corresponding POP_MODAL_WINDOW.
Comment: Thanks for this answer. Our internal discussion was similar. "Just include an action to call on close" - "But we need an async action creator there!" - "Then use Redux Saga!" ... and I was like "What? Shooting birds with cannonballs? Come on, there has to be a simpler way to do this."   Apparently I was wrong. Redux does have its dark sides I suppose. Still, thanks for the comprehensive answer.
Comment: For what it's worth, you _can_ include functions in action objects, and Redux itself will work - it's primarily time-travel debugging that may have issues.  See http://redux.js.org/docs/faq/Actions.html#actions-string-constants and http://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-1/ for more information.  And Redux-Saga _is_ meant for this use case of distributed/async behavior based on dispatched actions.
Answer: I think what you are looking for is a redux middleware that could handle async side effects. There are dozens of libraries out there that can help with this, but I would suggest your team looks into some of the following libraries that have great communities and are well documented:

Redux-Saga https://github.com/redux-saga/redux-saga (easy to understand and test)
Redux-Thunk https://github.com/gaearon/redux-thunk (extremely easy to understand, hard to test)
Redux-Observable https://redux-observable.js.org/ (you would need some previous knowledge on reactive programming, easier to test than redux-thunk)


How to find what an Apache httpd process is doing?

Question: I have a web application that is used nearly constantly by 5 - 10 users. Between 1 and 3 times a day it will grind to a halt.
When this happens I can see the following in TOP:
last pid:  1744;  load averages: 15.50, 45.91, 31.79                                                        up 0+01:04:01  14:47:59
357 processes: 1 running, 351 sleeping, 5 waiting
CPU:  0.2% user,  0.0% nice,  2.8% system,  2.4% interrupt, 94.6% idle
Mem: 1612M Active, 180M Inact, 174M Wired, 8012K Cache, 103M Buf, 108K Free
Swap: 4096M Total, 2104M Used, 1992M Free, 51% Inuse, 40M Out

  PID USERNAME    THR PRI NICE   SIZE    RES STATE   C   TIME   WCPU COMMAND
 1384 www           1  44    0   156M  3256K pfault  0   0:36  0.00% httpd
 1477 www           1  44    0   154M  8008K pfault  1   0:35  0.00% httpd
 1053 mysql       161  44    0   199M 54108K umtxn   0   0:27  0.00% mysqld
 1441 www           1  44    0   154M     0K WAIT    0   0:26  0.00% <httpd>
 1521 www           1  44    0   164M     0K sbwait  1   0:20  0.00% <httpd>
 1519 www           1  44    0   156M  7832K pfault  0   0:19  0.00% httpd
 1520 www           1  44    0   138M  8724K select  1   0:19  0.00% httpd
 1527 www           1  46    0   138M     0K accept  0   0:17  0.00% <httpd>
 1422 www           1  44    0   138M  3096K pfault  0   0:16  0.00% httpd
 1290 root          1  44    0   130M  9060K select  1   0:15  0.00% httpd
 1529 www           1  44    0   164M  3740K pfault  1   0:15  0.00% httpd
 1532 www           1  44    0   154M 22704K pfault  0   0:15  0.00% httpd
 1530 www           1  44    0   164M     0K sbwait  0   0:14  0.00% <httpd>
 1525 www           1  44    0   156M     0K sbwait  1   0:14  0.00% <httpd>
 1531 www           1  44    0   138M  8168K pfault  1   0:13  0.00% httpd
 1528 www           1  44    0   164M     0K sbwait  0   0:13  0.00% <httpd>
 1533 www           1  44    0   156M  3252K pfault  1   0:12  0.00% httpd
 1534 www           1  44    0   156M  3592K pfault  1   0:12  0.00% httpd
 1544 www           1  44    0   156M  4620K pfault  1   0:12  0.00% httpd
 1540 www           1  44    0   156M  4340K pfault  1   0:12  0.00% httpd
 1543 www           1  44    0   156M  4744K pfault  0   0:11  0.00% httpd
 1546 www           1  44    0   154M 11764K pfault  1   0:11  0.00% httpd
 1547 www           1  44    0   154M  8176K pfault  0   0:11  0.00% httpd
 1545 www           1  44    0   154M  8660K pfault  1   0:11  0.00% httpd
 1541 www           1  44    0   156M     0K WAIT    1   0:10  0.00% <httpd>
 1558 www           1  44    0   158M 19996K pfault  0   0:10  0.00% httpd
 1559 www           1  44    0   154M 10324K pfault  0   0:10  0.00% httpd
 1555 www           1  44    0   154M 18796K pfault  1   0:09  0.00% httpd
 1569 www           1  44    0   156M  6208K pfault  0   0:09  0.00% httpd
 1566 www           1  44    0   154M 10996K pfault  0   0:09  0.00% httpd
 1561 www           1  44    0   156M 15724K pfault  1   0:09  0.00% httpd
 1562 www           1  44    0   154M  8076K pfault  0   0:09  0.00% httpd
 1572 www           1  44    0   154M 11308K pfault  0   0:09  0.00% httpd
 1571 www           1  44    0   154M     0K sbwait  0   0:08  0.00% <httpd>
 1553 www           1  44    0   154M     0K sbwait  1   0:08  0.00% <httpd>
 1567 www           1  44    0   154M 13108K pfault  1   0:08  0.00% httpd
 1565 www           1  44    0   152M 17284K pfault  0   0:08  0.00% httpd
 1602 www           1  44    0   156M  4232K pfault  1   0:08  0.00% httpd
 1548 www           1  44    0   154M  8948K pfault  0   0:08  0.00% httpd
 1577 www           1  44    0   156M 15732K pfault  0   0:08  0.00% httpd
 1573 www           1  44    0   156M 16244K pfault  0   0:08  0.00% httpd
 1554 www           1  44    0   154M     0K sbwait  0   0:08  0.00% <httpd>
 1585 www           1  44    0   156M     0K WAIT    1   0:08  0.00% <httpd>
 1552 www           1  44    0   154M     0K sbwait  0   0:08  0.00% <httpd>
 1575 www           1  44    0   154M 11956K pfault  0   0:08  0.00% httpd
 1570 www           1  44    0   156M 16260K pfault  1   0:08  0.00% httpd
 1583 www           1  44    0   156M 15368K pfault  1   0:08  0.00% httpd
 1580 www           1  44    0   154M 11112K pfault  0   0:08  0.00% httpd
 1600 www           1  44    0   156M  4248K pfault  1   0:08  0.00% httpd
 1589 www           1  44    0   154M     0K sbwait  1   0:08  0.00% <httpd>
 1578 www           1  44    0   154M     0K sbwait  0   0:08  0.00% <httpd>
 1557 www           1  44    0   154M     0K sbwait  1   0:07  0.00% <httpd>
 1617 www           1  44    0   154M 11244K pfault  1   0:07  0.00% httpd
 1574 www           1  44    0   154M  8360K pfault  1   0:07  0.00% httpd
 1560 www           1  44    0   154M 10156K pfault  0   0:07  0.00% httpd
 1603 www           1  44    0   156M  4968K pfault  0   0:07  0.00% httpd
 1590 www           1  44    0   154M 11860K pfault  0   0:07  0.00% httpd
 1592 www           1  44    0   156M 14280K pfault  1   0:07  0.00% httpd
 1581 www           1  44    0   156M  6412K pfault  0   0:07  0.00% httpd
 1586 www           1  44    0   154M 11176K pfault  0   0:07  0.00% httpd
 1608 www           1  44    0   156M  7256K pfault  1   0:07  0.00% httpd
 1568 www           1  44    0   154M 10784K pfault  1   0:07  0.00% httpd
 1591 www           1  44    0   154M 13256K pfault  0   0:07  0.00% httpd
 1610 www           1  44    0   156M  3440K pfault  0   0:07  0.00% httpd
 1650 www           1  44    0   156M     0K sbwait  1   0:07  0.00% <httpd>
 1616 www           1  44    0   154M 13724K pfault  0   0:07  0.00% httpd
 1611 www           1  44    0   154M 10084K pfault  0   0:06  0.00% httpd
 1564 www           1  44    0   154M 12220K pfault  1   0:06  0.00% httpd
 1607 www           1  44    0   156M     0K sbwait  0   0:06  0.00% <httpd>
 1601 www           1  44    0   154M 13728K pfault  1   0:06  0.00% httpd
 1634 www           1  44    0   156M     0K sbwait  0   0:06  0.00% <httpd>
 1606 www           1  44    0   156M     0K sbwait  1   0:06  0.00% <httpd>
 1626 www           1  44    0   156M  3340K pfault  1   0:06  0.00% httpd
 1633 www           1  44    0   156M     0K sbwait  0   0:06  0.00% <httpd>
 1579 www           1  44    0   154M  8508K pfault  1   0:06  0.00% httpd
 1596 www           1  44    0   156M     0K sbwait  1   0:06  0.00% <httpd>
 1584 www           1  44    0   156M  2388K pfault  1   0:06  0.00% httpd
 1641 www           1  44    0   156M  3060K pfault  0   0:06  0.00% httpd
 1632 www           1  44    0   156M  3144K pfault  1   0:06  0.00% httpd
 1657 www           1  44    0   156M     0K sbwait  1   0:06  0.00% <httpd>
 1630 www           1  44    0   156M  6872K pfault  0   0:06  0.00% httpd
 1609 www           1  44    0   156M     0K sbwait  1   0:06  0.00% <httpd>
 1661 www           1  44    0   156M  5688K pfault  0   0:05  0.00% httpd
 1612 www           1  44    0   156M 17816K sbwait  1   0:05  0.00% httpd
 1670 www           1  44    0   156M  4904K pfault  0   0:05  0.00% httpd
 1576 www           1  44    0   154M 13980K pfault  1   0:05  0.00% httpd
 1673 www           1  44    0   156M     0K sbwait  0   0:05  0.00% <httpd>
 1645 www           1  44    0   156M  3312K pfault  0   0:05  0.00% httpd
 1597 www           1  44    0   156M  6004K pfault  1   0:05  0.00% httpd
 1587 www           1  44    0   156M  6008K sbwait  1   0:05  0.00% httpd
 1628 www           1  44    0   156M     0K sbwait  0   0:05  0.00% <httpd>
 1660 www           1  44    0   156M  6180K pfault  0   0:05  0.00% httpd
 1647 www           1  44    0   158M     0K sbwait  1   0:05  0.00% <httpd>
 1582 www           1  44    0   156M     0K sbwait  0   0:05  0.00% <httpd>
 1664 www           1  44    0   156M     0K sbwait  0   0:05  0.00% <httpd>
 1651 www           1  44    0   156M     0K WAIT    1   0:05  0.00% <httpd>
 1674 www           1  44    0   156M  7560K pfault  0   0:05  0.00% httpd
 1631 www           1  44    0   156M  6464K pfault  0   0:05  0.00% httpd
 1655 www           1  44    0   158M     0K sbwait  0   0:05  0.00% <httpd>
 1669 www           1  44    0   156M     0K sbwait  0   0:04  0.00% <httpd>
 1659 www           1  44    0   156M  5936K pfault  1   0:04  0.00% httpd
 1663 www           1  44    0   156M  5828K pfault  0   0:04  0.00% httpd
 1672 www           1  44    0   156M  5764K pfault  0   0:04  0.00% httpd
 1613 www           1  44    0   156M  5784K pfault  1   0:04  0.00% httpd
 1667 www           1  44    0   156M  3696K pfault  1   0:04  0.00% httpd
 1662 www           1  44    0   156M  3336K pfault  0   0:04  0.00% httpd
 1671 www           1  44    0   156M  5036K sbwait  0   0:04  0.00% httpd
 1675 www           1  44    0   156M  6228K pfault  1   0:04  0.00% httpd
 1629 www           1  44    0   156M  5788K pfault  0   0:04  0.00% httpd

Is there any way to find what the httpd processes are getting stuck doing?
Answer: First, as ETL wrote, enable mod_status with ExtendedStatus On to see current requests and their states, execution times... etc. You can also use an apachetop to get information which file is most popular. If it's not enough information to you, as timmeyh wrote, you can use strace but I will suggest -ff and -p switches (make sure that you specified main apache proccess id).
-ff switch

If the -o filename option is in effect, each processes trace is
  written to filename.pid where pid is the numeric process id of each
  process. This is incompatible with -c, since no per-process counts are
  kept.

-p switch

Attach to the process with the process ID pid and begin tracing. The
  trace may be terminated at any time by a keyboard interrupt signal
  (CTRL-C). strace will respond by detaching itself from the traced
  process(es) leaving it (them) to continue running.
Answer: You can use the common strace command to trace what your httpd is doing.
your command would be like the folloing:
strace -f -o trace.txt /etc/rc.d/init.d/httpd start
The "-f" strace option traces child processes as they are created by currently traced processes as a result of the 'fork' system call. The -o trace.txt is your outputfile to which you want to dump your trace.
Hope this helps
Answer: You could also use the status module and extended status page to see what are the current requests.


PHP and Excel sheet

Question: this is code to retrive data and insert it in to excel sheet
<code>header( "Content-Type: application/vnd.ms-excel" );
header( "Content-Type: text/html; charset=ISO-8859-1" );
header('Content-Type:text/html; charset=UTF-8');
header( "Content-disposition: attachment; filename=spreadsheet.xls" );

$rs = mysql_query("select * from organizations");
while ($row = mysql_fetch_object($rs)) {

    echo $row->name1 . "\t" . $row->name2 . "\t" . $row->name3 ."\t" . $row->email . "\n";
}
</code>
($row->name1) is in arabic format
the problem is in excel sheet Arabic language is unreadable
any solution please
Comment: Why are you overwriting the `Content-type` header 3 times? And presenting a tab-separated file with a `.xls` extension?
Comment: Don't do CSV. It breaks in Excel when you have Excel in different languages. Use a decent XLS(X) generator. They exist.
Comment: 1) You send twice the `Content-Type` header.
2) This is not an Excel spreadsheet. It's actually a tab delimited file (`\t` sequence). I'm not sure if there's a way to "code" the codepage in a file like this. This is why you get unreadable text. If you try to import it, using the Arabic codepage, I'm sure you'll read it fine.
Comment: No it isn't, it's badly written code to generate a tsv file - use PHP's built-in fputcsv() function (http://www.php.net/manual/en/function.fputcsv.php), and use the correct content type headers - which isn't text/HTML
Comment: Check you character encoding
Answer: their being some 3rd party tools for reading Microsoft Word/Excel files, but as aforementioned, the best is to export as CSV.
Comment: Beg to differ - best solution isn't CSV because you can have problems with opening in MS Excel because of Excel's locale settings, and because it's difficult to work with non-ASCII charsets in CSV. Best solution is to create A BIFF format xls file or an OfficeOpenXML xlsx file that can eliminate these problems

PHP and Excel sheet


Where can I download RiaServices.msi nowadays?

Question: Where can I download RiaServices.msi from the web, after Microsoft removed it?
I need to prepare a new virtual machine to host a legacy Silverlight application.
Thanks!
Answer: As far as I know, downloading ria.services separately may not be easy to find at the moment, you can use NuGet to install it.
Comment: Hi! I assume that by "install" you mean: 1: Run NuGet on the target machine to get the package. 2: rename the .pkg file to .zip, and extract its contents. 3: run some .script file there that will put the file in the right places on the targe machine. Correct?
Comment: Yes. You can try to do that.
Answer: After the hint from @Jiayao, I decided to forget about the RiaServices.msi installer and manually copy the necessary files to the target host machine, where the Silverlight app was published.
Luckily the files simply need to be copied to the silverlight "bin" folder.
The files I copied were:

System.ServiceModel.DomainServices.Client.dll
System.ServiceModel.DomainServices.Client.Web.dll
System.ServiceModel.DomainServices.Hosting.dll
System.ServiceModel.DomainServices.Server.dll

These libraries are available in the "lib" folder of riaservices.silverlight.4.2.0 and riaservices.server.4.2.0  NuGet packages. You can download the packages, rename the .nupkg files to .zip and extract them.
If I have the chance to compile the Silverlight application from the source, I plan to add these NuGet packages as dependencies of the project, so they can be normally deployed within the Silverlight application.
Answer: Simplest way to install the RIA WCF Services is to use Visual Studio 2015 installation in custom mode and to tick "Silverlight Development Kit". It works, I just did it a few minutes ago.
A bit overkill, perhaps...
... and well, you'll have to find an installer for VS 2015, too.


Fusion chart showing No Data to display in React Native

Question: I am doing react native application. In that, I am trying to showing bar chart. So, I am using Fusion Chart, It is mandatory to use this library in my application. So, I followed this library installation and it was successful. But, Data is not showing at all.

No Data to display showing in screen.

My code is
export default class App extends Component {
  constructor(props) {
    super(props);

    this.state = {
      type: 'bar2d',
      width: '100%',
      height: '100%',
      dataFormat: 'json',
      dataSource: {
        chart: {
            captionFontSize: '16',
            subcaptionFontSize: '14',
            showAlternatevGridColor: '0',
            numDivLines: '0',
            valueFontColor: '#ffffff',
            yAxisMinValue: '0',
            yAxisMaxValue: '100',
            showYAxisValues: '0',
            // "canvasBorderColor" : "#b3ffb3",
            canvasBgColor: '#ffffff,#e6eeff',
            canvasTopMargin: '100',
            paletteColors: '#990000',
            usePlotGradientColor: '1',
            plotGradientColor: '#ff8080',
            divLineAlpha: '0',
            plotSpacePercent: '60',
            useDataPlotColorForLabels: '1',
            showPercentInTooltip: '0',
            showLegend: '1',
            showLabels: '0',
            showValues: '0',
            placeValuesInside: '1',
            showBorder: '0'
          },
          data: [
            {
              label: 'Travel & Leisure',
              value: '41'
            },
            {
              label: 'Advertising/Marketing/PR',
              value: '39'
            },
            {
              label: 'Other',
              value: '38'
            },
            {
              label: 'Real Estate',
              value: '32'
            },
          ],
          annotations: {
            showBelow: '0',
            autoScale: '1',
            groups: [{
              id: 'user-images',
              items: [{
                id: 'dyn-label-bg',
                color: '#000000',
                align: 'left',
                type: 'text',
                text: 'Best when calm',
                x: '$canvasStartX+0',
                y: '$dataset.0.set.0.ENDY-0'
              }, {
                id: 'dyn-label-bg',
                color: '#000000',
                align: 'left',
                type: 'text',
                text: 'Very Relaxed',
                x: '$canvasStartX+00',
                y: '$dataset.0.set.1.ENDY-0'
              }, {
                id: 'dyn-label-bg',
                color: '#000000',
                align: 'left',
                type: 'text',
                text: 'Mellow',
                x: '$canvasStartX+00',
                y: '$dataset.0.set.2.ENDY-0'
              }, {
                id: 'dyn-label-bg',
                color: '#000000',
                align: 'left',
                type: 'text',
                text: 'Out of Control',
                x: '$canvasStartX+00',
                y: '$dataset.0.set.3.ENDY-0'
              }]
            }]
          }
    }

    };

    this.libraryPath = Platform.select({
      // Specify fusioncharts.html file location
      ios: require('./assets/fusioncharts.html'),
      //android: { uri: 'file:///android_asset/fusioncharts.html' },
    });
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.heading}>
          FusionCharts Integration with React Native
        </Text>
        <View style={styles.chartContainer}>
          <FusionCharts
            type={this.state.type}
            width={this.state.width}
            height={this.state.height}
            dataFormat={this.state.dataFormat}
            dataSource={this.state.dataSource}
            libraryPath={this.libraryPath} // set the libraryPath property
          />
        </View>
      </View>
    );
  }
}

I have customised this for design.
Can anyone tell me, Where I am doing wrong?
Comment: Refer to the sample in the below GitHub link :
https://github.com/fusioncharts/react-native-fusioncharts-samples
Comment: I have already checked them too. If I add annotations,  the issue happens.  Any help
Answer: Make Sure you have correct path of fusioncharts.html
and uder the package.js in script tag run this command
"build:assets": "fc-build-assets --fc-template ./src/assets/fusioncharts-tpl.html"
Answer: Make Sure you have add the .fcscript into the asset extensions section.
Here is the code -
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, Alert } from 'react-native';
import ReactNativeFusionCharts from 'react-native-fusioncharts';

export default class ListenEvents extends Component {
  constructor(props) {
    super(props);

    const chartConfig = {
      type: 'column2d',
      width: '100%',
      height: '400',
      dataFormat: 'json',
      dataSource: {
        chart: {
          caption: 'Countries With Most Oil Reserves [2017-18]',
          subCaption: 'In MMbbl = One Million barrels',
          xAxisName: 'Country',
          yAxisName: 'Reserves (MMbbl)',
          numberSuffix: 'K',
          theme: 'fusion'
        },
        data: [
          { label: 'Venezuela', value: '290' },
          { label: 'Saudi', value: '260' },
          { label: 'Canada', value: '180' },
          { label: 'Iran', value: '140' },
          { label: 'Russia', value: '115' },
          { label: 'UAE', value: '100' },
          { label: 'US', value: '30' },
          { label: 'China', value: '30' }
        ]
      }
    };

    this.state = {
      chartConfig,
      events: {
        // Add your events method here:
        // Event name should be in small letters.
        dataplotclick: (e, a) => {
          Alert.alert(`You clicked on ${e.data.categoryLabel}`);
        }
      }
    };
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.header}>Listen to events from chart</Text>
        <View style={styles.chartContainer}>
          <ReactNativeFusionCharts
            chartConfig={this.state.chartConfig}
            events={this.state.events}
          />
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 10
  },
  header: {
    fontWeight: 'bold',
    fontSize: 20,
    textAlign: 'center',
    paddingBottom: 10
  },
  chartContainer: {
    height: 400,
    borderColor: '#000',
    borderWidth: 1
  }
})

To know more about it please refer - https://www.fusioncharts.com/dev/getting-started/react-native/your-first-chart-using-react-native


how to modify the default tcp implementation in linux kernel

Question: i am doing some simulations of DDOS SYN FLOOD attack on a real network using virtual machines and i want to modify the current behavior of TCP three-way-handshake on Linux Mint, can anyone give me a guide or the steps to do ?
Answer: If you want to change the kernel code, then you need to know where they are, and then edit the code, compile them and run. Here is a network can help you know how to do these things, but the knowledge of Linux network stack is not include.


Language model created with SRILM does not sum to 1

Question: I created an n-gram language model on the Penn Treebank using the following command:
<code>ngram-count -text $trainfile -order 5 -lm $temp/templm.ptb -gt3min 1 -gt4min 1 -kndiscount -interpolate -unk
</code>
This code snippet was taken from Mikolov's rnnlm toolkit.
I tried to check if the created ngram LM is valid, and I think it is not (or maybe I don't understand something).
When I open the created ARPA file, I looked, for example, on all bigrams that start with the word "country":
<code>-1.445136   country 's  -0.06955435
-0.91566    country </s>
-1.380222   country <unk>   -0.06098625
-2.46688    country N   -0.06098624
...
-1.756313   country with    -0.06098624
-2.699641   country without -0.06098625
-1.975222   country would   -0.1501413
</code>
and on the unigram
<code>-3.751397   country -0.3271779
</code>
Now, as I understand (and probably I have a mistake somewhere), the number to the left of all bigrams are the log10 conditional probability: $\log_{10}(\Pr(\text{word|prev word=country}))$.
In addition, the number to the right of the unigram "country" (which is -0.3271779) is log10 of the backoff.
When I sum all the probabilities P(word|prev word=country) (without the backoff) I get:
$$ \sum_{word\in W} \Pr(\text{word|prev word=country})=0.64$$
The backoff number is
$$ 10^{-0.3271779}=0.47078444$$
When I add this number to the sum I get 1.110339152, which is higher than 1.
What do I miss? Shouldn't it be equal to one?
Answer: When you have a bigram like "country with" you should be backing-off to the unigram "with" not the unigram "country". Additionally, the backoff weight is different for each bigram. You need to look at the number to the right of "country with" to see how much weight to take from the unigram probability for "with".
Answer: I think "Backoff" term need to multipy lower-order probability.
that is sum(10 ** (-0.3271779 + p)), where p is lower-order log probability of those n-gram not exists in train set, and finally sum up all of them.


How do you add title and meta description on a DjangoCMS template?

Question: i'm working with djangoCMS and i have created all the templates and they are working fine, now my issue is on the djangoCMS page creation fields i fill a couple of fields, the page name, slug, menu title and page title. How do i add and display meta descriptions on my pages?
Comment: Did you check this out? https://djangocms-page-meta.readthedocs.io/en/latest/usage.html
Answer: I ran into the same problem and I managed to solve by the below code in my base template
<code>{% page_attribute "meta_description" %}
</code>


Tactics to counter pushing

Question: What are the best tactics to use against a player who uses excessive pushing?
I play with a group of about 20 guys each week without a referee. Every now and then a player will come along who relies on pushing to get past opponents.
I try to play as reasonably as possible and the shoving is not bad enough that I want to push someone on their ass for doing it. So, what are the best legal tactics to prevent this kind of person from pushing past?

Should I call a foul and risk being ignored because the pushing is not extreme?
Should I push back?
Is there a way that I can position myself without using hands to counter this behaviour?
Something more aggressive like chopping the hands?
Comment: ...push harder back and play harder. There is nothing more fun than to get into harder games. Pushing is an extremely important tool, it is a part of the dominance in the game. If you run fast enough, you cannot even notice other ones pushing. If run too slow, everyone is pushing you...I think I have learnt one of the most important lectures from the most pushing opponents, you must learn to play hard when you need to.
Comment: ...some picture would help, there are many different `"pushings"`...
Comment: "chopping the hands" might be a bit extreme!  ;o)
Answer: If it is a particular player and you see him coming at you, it is not illegal to position yourself to take the push. Lean into the push and/or go shoulder to shoulder with the player. If someone gets physical with you, you have to get physcial back. Obviously, I don't mean fighting and confronting the player, but you can't just give up the physical battle with someone. Outmuscling opponents is part of the game.
Alternativley, you could just flop and call for the foul. This is also a part of the game... although it is a strategy that is looked down upon, and is actually techinically illegal.
Comment: I was saying that flopping (diving) was technically illegal. Nothing wrong with the other stuff you mentioned.
Comment: ...`"technically illegal"`? Wait a second, which law are you reading? If you keep your arms down, push hard back -- or if you keep your arms out to balance in fast speed, there is nothing wrong. Is there?
Answer: Are you playing with the same set of guys each week?  If so, is it possible for someone (or you) to address the group before you start playing and generally talk about rules?  You don't need to single out the culprit (unless you want to), just talk in a general manner.
If you want to go at the issue yourself without trying to cause conflict, sounds like you probably need to see the guy coming and just shield him off the ball with your body.  If he does try to push you, it should be an obvious foul (which you should call).
Answer: Keep your arms out and fend him off.  If he can't reach your body then he can't push you out of the way, so use your arm to keep your distance.  As moesef's answer notes you do need to respond physically if other players are being physical.
Answer: As mentioned by others it is a part of the game. To understand it better you need to realize that football is a contact sport (not as much as rugby but still) and it's physically demanding. For that very reason players (especially in amateur divisions) will use physical intimidation as a way of winning the ball. Keep in mind that, going into a tackle if you are thinking that you might be hurt or whatever, you've pretty much already lost the ball. :)
That being said you do not need to start kicking people around, or strangle them by hanging on their shirts. In terms of pushing I believe you mean shoulder challenge whilst running. In that scenario it's very important to take stable steps, so that you have a solid balance when you take on the player. See to that the contact happens in your terms, as in be mentally and mechanically ready for the collision, and try to make sure that you go in with your hip or your shoulder. These are stronger joints, that way hopefully the momentum of the collision will not get your off your balance.
If you are referring to pushing while keeping/shielding the ball, then you might need to get a bit dirty. A lot of players will play rough in an attempt to intimidate opponents from reaching to the ball. Try to tilt his/her balance by pushing your opponent off balance. It helps trying to pay attention to how stable his/her stance is and how his/her weight is distributed. Trivial example; if the opponent has one leg on the ball and using his body to shield the ball, you obviously want him to move his pivot leg to block your movement. WHile that leg is in motion, the player is off balance and will most likely lose the ball if you push in a bit yourself.
These are my two cents, hope I didn't misunderstand your question. Good luck and keep in mind to have fun out there in the field. That's what matters really ;)
Answer: A simple personal example of what you can do: I often have the "dirty" job of stopping counterattacks by any means necessary. However I'm not a strong guy and I always rely on pushing or pulling. I've seen some players that didn't engaged with me for a long time, but they pulled back and let me lose my balance. It's a long shot to try that, but you can also get rid of that player in some situations.
Another way is to pull down his hand or shirt, again, with the purpose of making him lose the balance. This method works better, but it's not legal or nice to use it.
You should play hard, but avoid hitting players.

Tactics to counter pushing