beta regression or glm binomial?

Question: I have a big dataset (first 36 samples in image below) with proportion data (Proportion) that refer to the substrate that some insects eat: for example sample 1 eats 100% wood, sample 25 eats apx 81% wood. These data originate from counts which I transformed to proportions in order to  be able to merge with some older data (that were already proportions). As a result of that not every sample is independent because for example samples 19 and 30 refer to the same insect, which does not eat any wood (0%) but eats exclusively (100%) soil.
I would like to examine the effects of the type of substrate and the group (phylogeny) the insects belong to. And in order to do that I would like to fit everything in a model. After looking around a little bit, I realized that my options are either beta regression or glm binomial. I already tried a glm-binomial model but the results made no sense at all! Categories that I expected to see huge differences (and be highly significant) were not significant at all...
On the other hand, I was under the impression that I cannot use beta regression because I have lots of '1' and '0'
Any advice on what to do and how to do it will be greatly appreciated... :)
Comment: You may want to look at Dirichlet regression, which is specifically good for composition data https://cran.r-project.org/web/packages/DirichletReg/index.html
Comment: Can your huge differences be demonstrated in a simple overview of the data? What went wrong with the binomial data? How did you set it up?
Comment: How does your data really look like? Your current display of the first 36 samples does not show the relation between sample 19 and 30. Do you have somewhere else more data about your experiments? What is exactly known? Or not known, for instance are there gaps in the data?
Comment: thanks everyone for the quick responses. I tried to do it in R using sth like this: `code` fit <- glm(delta.CT$Value ~ interaction, family=binomial, data=all_forage)
Comment: I have now added a figure on top showing how the data look after fitting them in that binomial glm. As you can see (i guess) the biggest problem is the huge error bars that I get for the categories that are absolutely 0. I guess i could solve that by adding sth like 0.0001 to every value? or is this too arbitrary? In addition, I am still not convinced that what I am doing is the right approach! Is binomial the right one? should I do sth else? and how to choose? If someone wants to play with the data, I am happy to send a link
Comment: Btw in the top figure the comparisons that I am interested in are the ones that are of the same categories (i.e. leaf feces vs non feces, leaf flower vs non.flower etc etc)
Comment: It would be helpful to also plot the individuals (possibly with jittering, to make them more clear). Or plot boxplots. Then you can really assess if the error margins make sense. also place some descriptive data. How many samples do you have? With your current table I might think that you only have one single observation with group=high and substrate=wood. Or post all your data (is it 7x2 categories?).
Comment: Hi Martijn, added a plot on the top! As you can see I have a lot of 0's some 1's and also some values in between. Like you said it is indeed 7x2 categories. Sample number is 1295. i would add the entire table but I dont know how! thanks again :)
Comment: In this text from glen_b an example is shown how you can add a simple data table. If you put it in a code block like that (starting with 4 spaces), then it will become a block with a scroll bar and does not add much length to your post. Other ways are to link to some other website where the data might be available. https://stats.meta.stackexchange.com/a/2813/164061
Comment: thanks Martijin. After reading a bit more I am leaning towards using fmlogit, however the implementation in R is pretty poor... I cant find any good examples. I m pretty sure I cannot use beta regression as I have lots of )'s and 1's
Answer: General linear models are so versatile (in fact a lot of linear models are just special cases of GLM) that I'd go for it.
" and the group (phylogeny) the insects belong to" Why don't you take a look at phylogenetic comparative methods so that you can explicitly take phylogeny into account instead of an arbitrary "group" variable? There are a lot of methods for studying quantitative variables given a phylogeny.
Comment: Hey gabalench thanks but that is not what my question is about. I am specifically interested in that transition, I dont want to widely explore their phylogeny, I just need to see the substrate contrasts across the different groups.
Comment: Ok, then I would go for a GLM and posthoc comparisons with the R package `multcomp`.

beta regression or glm binomial?


A new stopping time built from a stopping time

Question: Let $T$ be a stopping time for the filtration $(\mathcal{F_n})_{n \in \mathbb{N}}.$ For all $n \in \mathbb{N}  \cup \left\{+\infty \right\},$ we set $\phi(n)=\inf\left\{k \in \mathbb{N};\left\{T=n \right\} \in \mathcal{F_k}\right\}$.
Show that $\phi(T)$ is a stopping time and that $\phi(T) \leq T.$
I wrote $\left\{w;\phi(T(w))=n \right\}=\left\{w;T^{-1} (\left\{T(w) \right\}) \in \mathcal{F_n} \ and \ T^{-1}(\left\{T(w) \right\}) \notin \bigcup_{k=0}^{n-1}{\mathcal{F}_k} \right\} $ by I don't see how this will help us to prove that $\left\{w;\phi(T(w))=n \right\} \in \mathcal{F}_n$.
Answer: For fixed $k \in \mathbb{N}$ we define $$X_{n}(\omega) := 1_{\{\phi(n) \leq k\}} \phi(n) 1_{\{T = n\}}(\omega).$$Then $X_n$ is $\mathcal{F}_k$-measurable for each $n \geq 1$. Indeed:

Case 1: $\phi(n)>k$. Then $X_n=0$ and therefore $X_n$ is trivially $\mathcal{F}_k$-measurable.

Case 2: $\phi(n) \leq k$. By the very definition of $\phi$,
$$\{T=n\} \in \mathcal{F}_{\phi(n)}.$$  As $\phi(n) \leq k$ this gives  $$\{T=n\} \in \mathcal{F}_{\phi(n)} \subseteq \mathcal{F}_k$$  and therefore $X_n = \phi(n) 1_{\{T=n\}}$ is $\mathcal{F}_k$-measurable.

Hence,
$$\phi(T) 1_{\{\phi(T) \leq k\}} = \sum_{n=1}^{\infty} 1_{\{\phi(n) \leq k\}} \phi(n) 1_{\{T=n\}} = \sum_{n=1}^{\infty} X_{n}$$
is $\mathcal{F}_k$-measurable. As $k \geq 1$ is arbitrary, this proves that $\phi(T)$ is a stopping time.
Answer: for $k \in \mathbb{N},\{\phi(T)\leq k \} =\bigcup_{n \in \mathbb{N}}(\{T=n\}\cap \{\phi(T) \leq k\})$ and for all $n \in \mathbb{N},\{T=n\}\cap \{\phi(T) \leq k\}$ is either $\emptyset$ (if $\phi(n)>k$) or $\{T=n\} \in \mathcal{F}_{\phi(n)} \subset \mathcal{F}_k$ (if $\phi(n) \leq k$), so $\{\phi(T) \leq k\} \in \mathcal{F}_k,$ which means that $\phi(T)$ is a stopping time. Since, for a fixed $w,T^{-1}(\{T(w)\}) \in \mathcal{F}_{T(w)}$ this means that $\phi(T(w)) \leq T(w)$


Cannot start NFS daemon

Question: I'm trying to set up a NFS share but I cant start NFS service:
$ service nfs start

Starting NFS services:                                     [  OK  ]
Starting NFS daemon:                                       [FAILED]

$ service nfs status

rpc.mountd is stopped
nfsd is stopped

Portmap is running:
$service portmap status

portmap (pid 6522) is running...

Exports contents (the real exports file has valid IP address instead of xxx.)
$ cat /etc/exports

/var/www/vhosts/ xxx.xxx.xxx.xxx(ro,sync)

/var/log/messages output after service nfs start
Apr 14 13:24:18 s15315044 nfsd[2483]: nfssvc: Function not implemented

As requested:
$ grep NFS /boot/config*

/boot/config-18.104.22.168rootserver-20081028a:CONFIG_NFS_FS=y
/boot/config-188.8.131.52rootserver-20081028a:CONFIG_NFS_V3=y
/boot/config-220.127.116.11rootserver-20081028a:CONFIG_NFS_V3_ACL=y
/boot/config-220.127.116.11rootserver-20081028a:CONFIG_NFS_V4=y
/boot/config-18.104.22.168rootserver-20081028a:# CONFIG_NFSD is not set
/boot/config-22.214.171.124rootserver-20081028a:CONFIG_NFS_ACL_SUPPORT=y
/boot/config-184.108.40.206rootserver-20081028a:CONFIG_NFS_COMMON=y
/boot/config-22.214.171.124rootserver-20081028a:CONFIG_NFS_FS=y
/boot/config-220.127.116.11rootserver-20081028a:CONFIG_NFS_V3=y
/boot/config-188.8.131.52rootserver-20081028a:CONFIG_NFS_V3_ACL=y
/boot/config-22.214.171.124rootserver-20081028a:CONFIG_NFS_V4=y
/boot/config-18.104.22.168rootserver-20081028a:# CONFIG_NFSD is not set
/boot/config-188.8.131.52rootserver-20081028a:CONFIG_NFS_ACL_SUPPORT=y
/boot/config-22.214.171.124rootserver-20081028a:CONFIG_NFS_COMMON=y

I'ts a dedicated server: CentOS release 5.7
$ cat /proc/version

Linux version 184.108.40.206rootserver-20081028a (root@rpmbuildd-amd64) (gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)) #1 SMP Tue Oct 28 06:03:38 EDT 2008

Any ideas?
Comment: Run `LANG=C service nfs start` and post the real output. Also, check your logs (`/var/log/syslog` and/or `/var/log/messages`)
Comment: Updated with real output and added `messages` output
Comment: Please add OS specifics to your question (distro, version, kernel version, `grep NFS /boot/config*`, physical/virtual, VPS, ...)
Comment: Ok, done. It's a physical dedicated server.
Comment: is this a custom kernel?
Comment: Don't know. It's the distro that came with my server.
Answer: Apparently, your kernel does not have the NFSD bits activated. It can be an NFS client, but not an NFS server.
/boot/config-126.96.36.199rootserver-20081028a:# CONFIG_NFSD is not set
You should recompile the kernel to have this enabled.
Comment: Instead of recompiling the kernel, do you believe that a `yum upgrade kernel-smp` would help?
Comment: Trying can do no harm
Comment: I've accepted the answer but I'm not going to deal with kernel recompilation, instead I'm using rsync. It seems to be a better option to transfer files from server to server.

Cannot start NFS daemon


What does it mean to have a 'slash chord' with more than one note after the slash?

Question: I'm used to slash chords like D/F# or Am/G where the second part after the slash informs you of the bass note.
I just saw a video with someone talking about chords like C+/Db+. I didn't even know slash chords could be used like this, what does this more complex notation actually mean?
Also, is there a more proper name for these chords than 'slash'?
Comment: Lawrence's answer is on the money but I just want to point out the distinction between the two is poly chords should use a horizontal line (see his second chord) but chords with bass notes other than the root should use a slash (his third chord).
Comment: Yes, you can technically have more superimposed chords, but it's a bit strange to have two chords that are only a semitone apart. What video is it?
Comment: @musicamante a bit off-topic but it was an ear-training demo by Rick Beato. I guess it was chosen to be deliberately very difficult
Comment: Can you give us a link so that we could better understand what it's about?
Comment: I remember seeing a question bringing up at least somewhat related notation with a _ with one chord on top and another below, with the example taken from *The Phantom of the Opera*.
Comment: It looks like a polychord notation, but that would be odd unless it's a very advanced ear-training video. A screenshot from the video, plus a link to the video, would be helpful.
Comment: The question about the Kurt Rosenwinkel piece is mainly about his failure to properly differentiate between slash bass and polychord notation. Not really a duplicate of this one.  Where do we vote to reinstate it?
Comment: @LaurencePayne In the line just above the comments (where you should see an option for "Share," "Edit," "Flag," etc.) there should be a "Reopen" option.
Comment: @Richard  Thanks.  Or perhaps you take the point and could just reverse your decision?
Comment: @LaurencePayne I'm happy to be overruled here, but I still think the linked duplicate answers this question. In fact, I think those answers (your own included) answer this question even *better* than your answer here.
Comment: I think the other question _answers_ my question, but I would never have found it with such a specific title!
Answer: I think you're looking at a Polychord.  One chord on top of another.  Often both triads, but the system allows more complex chords.
Sometimes a harmonic device all its own, sometimes a method of simplifying the notation of an extended chord.
Stravinsky used them (though he was unlikely to have labelled them with chord symbols!)  As did ALW in 'Phantom' (where he did. Show-off!)
Chord symbols live on the border between harmonic analysis and practical reading aid.  When you end a jazz-styled piece with a nice 'dirty' Cmaj13(♯11) you might well think of it, for practical playing purposes, as a D over Cmaj7 polychord.  Purely as an aid to where your fingers go, no deep harmonic meaning.
Comment: So we think it might be slightly lazy/loose notation in the video I saw, because a slash chord _does_ only allow a single note to be specified?


What does ${}^{\mathsf{T}}$ mean in the context of the binomial distribution?

Question: In a presentation of the binomial distribution on this website, the probability of the success of a trial is presented as $\pi=g^{-1}(\eta)$, with $g$ the inverse link function. $\eta=\alpha+\boldsymbol{\mathrm{x}^\mathsf{T}\beta}$ is described as a "linear predictor."
Is $^\mathsf{T}$ here the transpose symbol? If so, what does it mean in the context of a linear model? If not, what is this symbol?
Comment: It's a transpose symbol.  $x$ is a column vector, so $x^t$ is a row vector.  $x^t \beta$ is a row vector times a column vector, hence a scalar.   Thus, $x^t \beta$ is just a fancy way to write a dot product.
Answer: What the equation is describing is not a "binomial distribution", but a generalized linear model. Such model is described in terms of linear predictor:
$$
\eta = \alpha+\boldsymbol{\mathrm{x}^\mathsf{T}\beta}
$$
link function
$$
\pi = g^{-1}(\eta)
$$
and likelihood function
$$
Y \sim \mathcal{Bernoulli}(\pi)
$$
as described in multiple places on this site. When using Bernoulli distribution as a likelihood function, we are talking about logistic regression.
As about the $^\mathsf{T}$ symbol, it stands for transpose (alternatively you could see $^{'}$), so it is a shortcut to saying
$$
\mathrm{a}^\mathsf{T} \mathrm{b} = a_1 b_1 + a_2 b_2 + \dots + a_k b_k
$$
where, depending on context, it could be matrix times vector, or vector times vector.


Navigate in website with getElementByName

Question: I am looking to download an excel file from a website.  I have followed a few tutorials on here, but am having trouble.
My variables are publicially declared.  But as expected, when I get to element.Click, I get my error.  I know I am confusing the method/function that I am calling, and am hoping for a bit of help.  Thanks.
Public Sub testLogin()

Set objIE = CreateObject("InternetExplorer.Application")

webSite = "https://na30.salesforce.com/00O36000006xEvX"
webSite = "my url here"

With objIE
    .Visible = True
    .navigate webSite
    Do While .Busy Or .readyState <> 4
        DoEvents
    Loop

    Set element = .document.getElementsByname("csvsetup")

End With

element.Click 'error happens here

End Sub

Answer: getElementsByname returns a collection of elements - even if there's only one match for the name - so likely what you want is something like:
element(0).Click

depending on whether you have more than one match and the position of the element you want to click in the collection of returned matches. For example (0) would be the first match.
Comment: I really appreciate it.
Comment: Yeah, this is definitely my error.  I did not realize the return had a collection.  Now the tutorials make more sense with `(0)` portion.


Locally Lipschitz at a point and around a point.

Question: I am confronted with 2 definitions
Let $A \subseteq \mathbb R^n$ and $f:A\to \mathbb R^m$.
$f$ is said to be locally Lipschitz at a point $c \in A$ if
$$
(\exists \delta>0)(\exists L \ge 0)(\forall x \in A)\\ \Vert x-c\Vert<\delta \implies \Vert f(x)-f(c)\Vert\le L\Vert x-c\Vert
$$
 and $f$ is said to be locally Lipscihtz around a point $c\in A$ if $$
(\exists \delta>0)(\exists L \ge 0)(\forall x,y \in K(c,\delta))\\ \Vert f(x)-f(y)\Vert\le L\Vert x-y\Vert
$$
obviously the second definition asks for more and every locally Lipschitz function around a point is also locally Lipschitz in a point, but I am trying to prove that the opposite isn't true and have been failing for a while
the only thing the first definition gives is
$$\Vert f(x)-f(y)\Vert \le L (\Vert x-c\Vert + ||y-c||)$$
edit: $K(c,\delta)$ is an open ball around $c$ with a radius $\delta$
Comment: If you're willing to give up differentiability, and even continuity, at points away from $c,$ then consider $f:{\mathbb R} \rightarrow {\mathbb R}$ defined by $f(x) = x$ if $x$ is rational and $f(x) = 0$ if $x$ is irrational. It is easy to see that $f$ is locally Lipschitz at $x=0$ $(L = 1$ works) and $f$ is not Lipschitz in any neighborhood of $x=0.$ Note that the graph is just the graph of $y = |x|$ with all points having an irrational first coordinate moved down to the $x$-axis.
Answer: Let $f(x)=x^{2}\sin(1/x^{2})$ for $x\ne 0$, $f(0)=0$, we have $f'(0)=0$, so it is locally Lipschitz at $0$, but $f'(x)$ is unbounded around $0$, so it is not locally Lipschitz around $0$.
Comment: how is $f'$ not bounded around 0? Isnt $f'(x)=2sin(1/x)-cos(1/x)$ for $x \not= 0$ and $f'(0)=0$?. Isnt that bounded by 2?
Comment: What about now?
Comment: Now it becomes $f'(x)=2x\sin(1/x^{2})-(2/x)\cos(1/x^{2})$ for $x\ne 0$.


extra padding problem in Safari

Question: The sample page:
<!DOCTYPE html>

    <meta charset="utf-8">
    <title>Button test</title>

    Adjacent text<button>
Button
</button>

Here is the image:

You can see the extra white padding in the button. Is it possible to get rid of that padding in Safari browser?
Comment: You could use ANCHOR's to simulate buttons. [Anchors don't have such styling problems](http://jsfiddle.net/simevidas/jjCQ4/)
Comment: See my reply to the similar suggestion below.
Comment: Have your tried using a CSS reset sheet?
http://developer.yahoo.com/yui/3/cssreset/
Comment: Yes I did. It won't help as well. :-(
Answer: Bit late to the party but I found over-riding it the webkit border fit with:
-webkit-border-fit:border !important;
worked a treat for me.  Esspecially useful for Magento where webkit-border-fit property comes in handy at times but can cause problems for certain <button>'s.
Comment: Nah, doesn't work, too. In the Safari version I tested it back then. In the latest version it's fixed thought and works as it is.
Comment: Sorry to hear that.  Worked for me in Chrome (latest as of date of this comment), but only with the addition of `!important`.  Okay, so it seems this still hasn't been solved.  Is this a Chrome bug?
Answer: The following CSS from The Filament Group has worked for me in all browsers for some time now. The base of the CSS, to strip buttons of all their styling is as follows:
The span is used for the sliding-doors technique (better than the div you are currently using, this could be a problem), a full style listing can be found via the link.
button {
    position: relative;
    border: 0;
    padding: 0;
    cursor: pointer;
    outline: none; /* for good measure */
    overflow: visible; /* removes extra side padding in IE */
}

button::-moz-focus-inner {
    border: none;  /* overrides extra padding in Firefox */
}

button span {
    position: relative;
    display: block;
    white-space: nowrap;
}

@media screen and (-webkit-min-device-pixel-ratio:0) {
    /* Safari and Google Chrome only - fix margins */
    button span {
        margin-top: -1px;
    }
}

Comment: Downside of targeting entire browser (not version lower than some number) is that when the bug will be fixed in browser, `margin-top: -1px` will get causing _undesired_ offset.
Answer: The problem is fixed in some version of Safari, I'm not sure what exactly, but in latest (5.1.5) it works for me.
Answer: button { background: red; outline: 1px solid red, position: fixed; }

To fix the issue of extra padding in Chrome & Safari. you will have to specify position: fixed, this solved the problem for me. hope it will work for you guys too!
Comment: Tried it but that munted the button width/height (and border stuffed up). Using iOS5. Also tried `-webkit-appearance: none;` but that didn't help either.
Answer: Form elements such as <button> are usually implemented/drawn as a native OS control, so they can look and behave differently in different browsers. If you want complete control over  styling, you'd be better off using an  tag.
Comment: I would like it to send a form with "POST" HTTP method, and it should work in the user-agents with no JS support.
Comment: @d.m: I'm out of ideas in that case -- it's a difficult requirement especially when considering form elements. Hopefully somebody else can come up with a hack for Safari.
Comment: @dmedvinsky: You can replace `button` elements with links via JS so that non-JS-capable users will see just slightly understyled native button which is generally perfectly acceptable: if rare user has disabled JS, he is already ready for some inconsistencies.

extra padding problem in Safari


jquery validation plugin disable error messages but keep highlights

Question: I don't need error messages from jquery validation plugin, how can i disable them?
I saw this workaround here a lot, but it also removes highlights, so I guess it doesn't work for the new version.
errorPlacement: function(error, element) {
            return false;
},

What else can I do?
Comment: This plugin? What plugin?
Comment: jquery validate i said it already
Comment: Yeah, it's not like there are 300 jquery validation plugins out there :)
Comment: http://jqueryvalidation.org/ it is really called like this:P
Comment: haha :) okay then, I'm having a look
Comment: From the example on this page http://jqueryvalidation.org/files/demo/marketo/, you want to hide the red line that appears at the top in case of fail? It has an `.error` class, so just add `.error{ display:none; }` to your CSS. If it doesn't work, try  `.error{display:none!important; }`
Comment: oops, use `div.error`, otherwise it will also hide all the input that also have the `.error` class
Comment: sounds, good. but this is kind of too global solution
Comment: That also only applies to [the one demo](http://jqueryvalidation.org/files/demo/marketo/), since any CSS styling is **not** included with the plugin and the default error container is a `label`.
Answer: This is still the correct code for preventing the validation messages from being inserted onto the page.
errorPlacement: function(error, element) {
    return false;
},

I saw this workaround here a lot, but it also removes highlights,

The plugin does not remove, nor create, any "highlights".  Any/all styling is external to the plugin and totally up to your own designs.
Aside from simply assigning an error or valid class to the invalid or valid elements, the plugin has nothing to do with CSS and does not include any CSS properties.  It's up to you to assign or not assign CSS properties to the error and valid classes.
Otherwise, the plugin gives you options called errorClass and validClass that allows you to change the class names from error and valid into whatever you wish.

What else can I do?

Inspect the DOM before and after removal of the error messages.  What are the differences?  Fix those.


How would you design a machine learning system to play Angry Birds?

Question: After playing way too much Angry Birds, I started to observe my own strategies. It turns out that I developed a very specific approach to getting 3 stars on each level.
That made me wonder about the challenges of developing a machine learning system that would be able to play Angry Birds. Interacting with the game and launching the birds is trivial. But one question that I had is about the "building blocks" of the system.
Machine learning systems seem to work with simple concepts or understanding about the problem.  This is often encoded as features as inputs. So it seems that the system needs to have the ability to understand some high level concepts to generate a strategy.
Is this true? Also, what are the challenges or difficult parts of developing such a system?
EDIT #1:
Here's some clarification. Getting 3 stars is a difficult problem because you have to maximize the points. This can be done in two non-exclusive ways: 1) Minimizing the number of birds used (you get 10,000 points for every unused bird). 2) Maximized the destruction of glass, wood and other objects. Each object destroyed gives you points. It is possible to destroy more than 10,000 points worth of objects with a single bird.
Here's a little more explanation about "high level concepts". In order to maximize the points described above, you need to use the special powers of each bird. So, that means launching different birds with different trajectories, depending on the layout of the map. And, while playing I develop a strategy that destroys certain areas with certain birds in a certain order.
It seems that without an understanding of how to use each bird to destroy a specific area the system could not learn to get 3 stars. So, how do you manage and encode something like that? How do you ensure that the system can learn these high level concepts?
Answer: Assuming you could get the right hooks into the software (or you work with your own mock-up), some things would be easy here, and some less so. This is quite a tough problem I think. As carlosdc mentioned, Reinforcement Learning (RL) is one possible avenue, although I'm not sure it's the right one.
When you begin, you have to define what your state space, action space, transition dynamics, and reward function are. The state/action spaces can be continuous or discrete, and the transition dynamics could be given by the problem or modelled mathematically. Finally the reward function may be given a-priori, or may be sampled (with or without noise).
The action space is simple: it's simply the direction and power that you shoot the current bird at. For the human, this is a discrete problem (the mouse/touchscreen is a digital input device) - let's say (for example) there are 32 possible directions and 10 possible powers, giving 320 possible actions.
The reward function is also fairly easy to derive: the goal is to get rid of all of the pigs with the fewest number of birds (OK so there extra points for other things but let's ignore that for now). The best thing would be if we knew the actual function that generates points from killing pigs (depends on the size of pig etc IIRC) - but for a single level this could be modelled perfectly.
The state space and transition dynamics are much more difficult. In order to model this correctly, we'd have to know the entire layout of the map and the physics of the game. The transition dynamics say "If I am in state x and I perform action y, I will land in state z". You can see the difficulty of this, firstly as the complex physics of the system mean that this will be extremely difficult to model accurately, and secondly as there are so many possible resultant states after even the first round (320), and this is if we assume there is no stochasticity in the physics engine, which from having played it I suspect there is. I think at this stage you would give up and go home.
Another approach is to treat it like a human does at the very start - i.e. trial and error. The human, at least to begin with, fires virtually randomly (although with a fairly strong prior to send the birds towards the pigs, but this can easily be coded in), until a range of good actions are found. This is more like the multi-armed bandit setting. The "arms" of the bandits here are the possible actions. The algorithm tries to balance exploration and exploitation - i.e. exploring the action space and exploiting good actions when they're found. For this you don't need to know anything about the underlying dynamics - you only need to know about actions and rewards. To do it fully you would have to have an arm for each possible action over all the rounds (e.g. you have 5 birds * 320 action = 320^5 = approx 10^12 actions), so the action space is very large! However you could use some tricks to improve this if you know a little bit about the state space. For example, you could probably rule out actions that send the bird away from the pigs, down into the ground, or without enough power to reach any of them. Also you only need to reach the 5th bird if you haven't killed the pigs in the previous rounds, so a proportion of the action states aren't actually possible. This is somewhat reminiscent of the approach used in the algorithm MoGo, which is a computer programme for playing Go based on Upper Confidence bounds applied to Trees, one approach to solving the multi-armed bandit problem.
Comment: Great answer! I think that the action space is much larger than 320 possible actions. Every pixel swept by an arc of perhaps .7 inches (on iPad) from horizontal left to vertical down will generate a different trajectory and result. The iPad has a resolution of 132 dpi, so that might be about 8,000 possible pixels to choose to launch from. I didn't want to dwell on the details,but does  increasing the action space to 8,000 change the answer? How can you work with a larger action space?
Comment: Trying to simulate the dynamics is a completely different (and difficult) question. I think for this discussion we should assume that we have access to the source code and can accurately get the state information. Also, the reward function is not only how many pigs you kill. To get 3 stars on a level, you have to do something more difficult. See edit to question.
Comment: @BSeven In principle no, the larger action space doesn't change the answer, although you might have to do more pruning and use a lot more computing power ;-) Note however that this is a perfect candidate for parallel processing. The question of the stars is tricky, as this implies that there is no simple mapping from kills to stars, although I thought that you got more stars simply by crossing points thresholds (usually this is done by using less birds). If not, you'd have to artificially increase the amount of exploration to avoid settling on suboptimal paths too early.
Answer: Cool question!
It seems like this question is about the natural technique for this type of
problem. I think think the natural technique for this type of problem is
reinforcement learning (RL). RL is about how an agent ought to take actions in
an environment so as to maximize some notion of cumulative reward. Perhaps the
best known algorithm for RL is Q-learning. I think this is the first question in
this site about reinforcement learning.
I think what you're asking is true if you try to approach this as
classification/regression, but those do not seem like the right tool for this
problem. This is naturally a RL problem where sequences of actions and outcomes
need to be taken into account.
Answer: Check here how others are doing it or participate yourself:
Angry Birds AI Challenge http://ai2012.web.cse.unsw.edu.au/abc.html
Comment: perhaps you can summarize what the link is about and howvit relatescto the question. As it is now, your answer is better as a comment.
Answer: just mentioned this over in meta. there was a pioneering use of genetic algorithms by Koza to solve the video game Pacman. he constructed algorithmic primitives that could sense and act. as I recall these were combined in Lisp-like trees to create larger algorithms. crossover with Lisp trees involves substituting or exchanging subtrees that represent the algorithm expressions. the success function is something like "dots eaten" or "dots plus ghosts eaten" or "time stayed alive". there is still some work in this area. there is a koza ref in this paper following. training time may be very long and "convergence" very gradual for these types of problems.
Learning to Play Pac-Man: An Evolutionary, Rule-based Approach by Gallagher and Ryan


Why might a 413 not be flushed to the client immediately?

Question: I have my local development server returning status 413 for oversized file uploads and the client is receiving these immediately - as I require.
My remote server is the same version of Nginx and more-or-less the same configuration, but the  413 never reaches the browser.
An error indicating the data is oversized appears in the error log straight away and nothing appears in the access log. The browser continues to send the data and after 30 seconds the 413 status appears in the access log (and again in the error log) and the browser times out with an internal 'connection reset' error.
What configurations on the remote server could cause this delay?
Comment: Starting to wonder if it's the latency that's the difference. Local network being fast enough that the file can upload before the timeout period and get the 413 response. i.e. The browser *must* send the whole file before receiving a response, and over the web that's too long. -- thinking out loud.
Answer: The problem is that most HTTP clients don't read the response until they've sent the entire request body. If you're dealing with webbrowsers you're probably out of luck here. The only server side configuration you can do is set keepalive_requests to 0 (which disables persistent connections), which might make nginx close the connection after sending the 413 which should cause the client to stop sending the data. The client is likely to report a network error instead of 413 however.
Comment: Yeah, this will likely result in the client reporting "connection reset by peer" rather than actually reading and parsing the response body.
Answer: I guess browser must still finish the upload and only then recieve 413 error. The best way to check file size is to check it in JS before hitting the upload button.
Comment: That certainly is the best way, and I am doing for /modern/ browsers. I've tried to use the Microsoft ActiveX thing to do the same in IE, but it produced nasty security warnings, so I ditched my attempts at that.


copy multiple columns from file1 of an excel sheet to other column/row of file2 other excel sheet using python , use pandas or anything else

Question: I need to copy from file1 (I), from Ith column entire row after 9th cell and paste the data into D column from row 4 into file 2 using python. Also again I need to copy from file1 from b4 to b8 into file2 as J7 to j11.
Answer: i tried this code:
<code>import openpyxl as xl
from openpyxl import load_workbook
import pandas as pd

# opening the source excel file
filename1 ="elementsheetsample.xlsx"
wb1 = xl.load_workbook(filename1)
ws1 = wb1['Sheet1']

# opening the destination excel file
filename2 ="filledelementsheetsample.xlsx"
wb2 = xl.load_workbook(filename2)
ws2 = wb2['INACTIVE Sheet']

i1=9 #I row in file1
i2=4  #D row in file2

# calculate total number of rows and
# columns in source excel file
mr = ws1.max_row
mc = ws1.max_column

# copying the cell values from source

if i1==2:
    if i2==2:
        for j1 in range (2, mc +1):
            for j2 in range (2, mc + 1):
                    c = ws1.cell(row = i1, column = j1)
                    ws2.cell(row = i2, column = j2).value = c.value

updatedtx = "updatedtx2.xlsx"
# saving the destination excel file
wb2.save(str(updatedtx))
</code>


Hamiltonian Monte-Carlo with piecewise differentiable log likelihood

Question: This is a bit of a curious situation. I have an energy function $E=S+N$ which is the sum of a smooth differentiable function $S$ and a piecewise constant "noise" function $N$. This means that on average the gradient does point in the right direction, but even a tiny step in the gradient's direction will fall on a different piece.
Is there any way to adapt HMC to handle this situation? For all practical purposes, the "noise" function is a black-box.
So far I'm thinking of using HMC updates based only on the gradient of $S$, with a MH acceptance step at the end. The only difference with regular HMC being that the acceptance ratio may not be 1 (or close to 1). Is this correct or am I missing something?
P.S. I put "noise" in quotes because it does capture the look of the function (low spatial correlation), but it is not noise in the sense that I do not want to ignore its contribution to the energy function.
Comment: Hamiltonian can be defined on a [symplectic manifold](https://en.wikipedia.org/wiki/Symplectic_manifold). A symplectic manifold must be differentiable (and smooth) to be classed as such. Therein lies the problem that you are most likely aware of. This is an interesting problem though. I would expect that one can solve the Equations of Motion (EOM) in a piecewise fashion and bootstrap them together though. I will look into this in more detail over the summer when I start my thesis on HMC.
Answer: This paper is likely relevant.  Abstract:

Hamiltonian Monte Carlo (HMC) is a successful approach for sampling from continuous
  densities. However, it has difficulty simulating Hamiltonian dynamics
  with non-smooth functions, leading to poor performance. This paper is motivated
  by the behavior of Hamiltonian dynamics in physical systems like optics. We introduce
  a modification of the Leapfrog discretization of Hamiltonian dynamics on
  piecewise continuous energies, where intersections of the trajectory with discontinuities
  are detected, and the momentum is reflected or refracted to compensate for
  the change in energy.


Creating N fields with N 'subfields'

Question: I'd like to create a content type "Enterprise" where user can define N services and, for every service, N tasks. I have already created the other fields for this content-type (name, description, ..., easy fields) but I don't know how to start with the services and tasks.
I'd like to be able to create services and tasks in the same form. What would be the best way to do it?
Comment: Not really following what you need, are you looking for something like:

http://drupal.org/project/hierarchical_select?
Comment: What data does a service contain? What data does a task contain?
Are you writing a module? Or looking to "click it"?
You're not giving enough info for useful advice, and I don't want to give you a solution that's potentially completely wrong.
Comment: Westie, hierarchical_select module is based on taxonomy. I would like to read values from other content-types; user should be able to create his own values for this content-types. These content-types would have a hierarchical structure (2 levels) inside the parent content-type (Enterprise).

Bojan, a service could be "Car reparation" and tasks the actions that this enterprise can do in this field (things that can repair). Another service could be "Cleaning"; the tasks for this service could be "complete cleaning of your vehicle", "Wheels cleaning",...
Answer: In case of use d6, you can use Flexifield, then after you install you should create a content type that should represent your subfields, and in your main content type you should create a new field, with Flexifield type, and then, define the it's a number of values of the field, and then, in the creation node form of your main content type, you`ll have a field (kind of group), that will have multiple subfields, and depending of the number of fields defined, you should have multiple "groups of subfields".
Answer: In drupal 6.x this used to be accomplished by using cck-3.x which had support for multi-group which is the behavior you're asking for.
In drupal 7.x this can be accomplish by using the field_collection module (http://drupal.org/project/field_collection) - THis module also requires the entity module.
Once you have that module set up the UI is a little different than jut adding a field and groups.
You're going to want to go to you "Enterprise" content type and add the new Field Collection field (right now the only display is hidden).
Once you added the field collection field :-). You will now need to go to field collection configuration screen over at admin/structure/field-collections. Here you control the fields within your collection.
So you should now see the new field_collection field you added, You will need to add the two new fields you want to that collection. In your case is the services and tasks fields.
Now you have a collection with two fields in it.
The weird thing is that in order to add collection right now you can't do it when creating the node. You will need to create the node and then you're provided with a "Add collections" link which allows you to add those "Services and Task".
Is a little wierd but it works. I'm sure in the future they're be more widgets available but for now thats whats available in drupal 7.
Hope this helps.

Creating N fields with N 'subfields'


Firewall with layer 3 switch or without it?

Question: I am trying to make a simple network architecture for a small company.
One of the sites is built of a firewall (to create a DMZ, to make the VPN between the sites) and three switches, like in link below.

There are workstations connected to each of the switches. It is a VLAN-based network. Employees obtain their addresses with DHCP server. The company has got also another site, connected with a VPN/IPSec tunnel.
My question is, would it be reasonable to use a layer 3 Switch as SW3? I would then configure the DHCP server and routing inside the site on SW3, leaving ASA for things related with DMZ and VPN.
Or do you think using a layer 2 switch will be enough as SW3, and make all the routing and DHCP configurations on ASA?
Thank you for every answer. I am just afraid it is not worth it doing it with layer 3 switch and a firewall.
If you know some literature about creating an architecture I would appreciate.
Answer: List pros and cons for both scenarios and decide. Only you can know which option is best as you know what your environment requirements are.
I will start :
With Layer 3 switch

Less load on the ASA
ASA only deals with external traffic
all LAN subnets are contained withing the switches.

Without Layer 3 switch

No need to buy layer 3 switch
All of the internal network is exposed to ASA
You can filter internal traffic using ASA if needed.

etc..
Comment: Yes, this is in general the thing I am considering, that there are pros for both approaches. I only was not sure if in general it is worth being considered. Thank you for ensuring!
Comment: If you have heavy inter-vLAN traffic you should more heavily consider the L3 Switch design as the ASA will quickly become a bottleneck. If this is not the case without the L3 Switch would be simpler and cheaper.


How to import generated class from Apollo Client (GraphQL) in Android Studio

Question: I'm new to Android studio and want to write a small example app with GraphQL and the Apollo Client.
I've successfully setup my build environment and the automated code generation. Here's a screenshot of the file structure, build/generated/apollo/AllPostsQuery is the class that was autogenerated based on src/main/graphql/AllPosts.graphql:

My only issue now is that I don't know how to import the AllPostsQuery class into my MainActivy.
I simply tried:
import AllPostsQuery;

but that doesn't work:

Can not resolve symbol AllPostsQuery.

Do I need to add any prefixes to the import path?
Comment: See here how to let AS auto-import classes for you https://stackoverflow.com/questions/22272524/how-to-auto-import-the-necessary-classes-in-android-studio-with-shortcut
Comment: You should set up a package directory tree under `graphql/`. The generated code will go into that package. See [this sample project](https://github.com/commonsguy/cw-graphql/tree/v0.3/Trips/CW/StaticList).
Comment: Thanks for the comment! I believe my auto-import is already setup, it did work for all the other classes (I didn't write a single import myself so far). https://imgur.com/VcVFXp4 any other ideas?
Comment: ah great that worked @CommonsWare! if you add this as an actual answer I'll mark it as accepted and you get your points :)
Comment: Were you able to resolve the ANDROID_HOME issue?
Comment: @cricket_007 no unfortunately not! I've just started a fresh project now where the build works... I still can't run the sample project from the apollo-android repo...
Answer: The way your project is structured in the question, you have your GraphQL document and the schema JSON directly in graphql/. That will result in your generated Java class not being put into a package. That's probably not what you want.
Apollo-Android takes the approach that is used for some other forms of source code (Java, AIDL, etc.), and uses a package directory tree. In this sample project (from this book), I have my GraphQL document and schema JSON in graphql/com/commonsware/graphql/trips/api. As a result, my generated Java classes are in the com.commonsware.graphql.trips.api package.
So, set up a series of subdirectories for whatever Java package you want your generated code to go into, and move your GraphQL document and schema JSON there.


Testing Assumption of Linearity for Multinominal Logistic Regression

Question: I have a nominal DV (0 through 3). IVs are all continuous. I'm trying to test the linearity assumption, however I can't run the logistic regression function in SPSS with the LN IV variables because of the DV being more than 2 values. Can someone explain to me how I need to test the assumption in SPSS?
Comment: Welcome to Cross Validated! You might want to start by using a software implementation of a *multinomial* logistic regression. It is not obvious that the SPSS function can handle a multinomial likelihood.
Comment: Did you try Analyze...Regression...Multinomial logistic?
Comment: I don't think you can use logistic regression on a DV with 4 responses, as logistic regression is typically only used for binary responses (0 or 1).
Comment: Be sure your variables are appropriately formatted on the variable view page as well aka nominal variables are nominal, continuous variables are scale, etc. Try also this link for procedure steps - https://statistics.laerd.com/spss-tutorials/multinomial-logistic-regression-using-spss-statistics.php
Comment: Yes, I'm running as a multinomial log reg. I'm not sure how to test assumption 5 (Assumption #5: There needs to be a linear relationship between any continuous independent variables and the logit transformation of the dependent variable.) from https://statistics.laerd.com/spss-tutorials/multinomial-logistic-regression-using-spss-statistics.php
Answer: You can evaluate the linearity assumption for multinomial logistic model visually by plotting the residuals separately for each dependent variable category against the predicted probabilities, and by plotting the residuals (again separately for each dependent variable category) against each of your continuous predictors, and look for any patterns in these plots (no pattern = good). I'm not sure how to do this in practice in SPSS unfortunately, but I think this article may help.
Comment: This link was super helpful and helped me test the assumptions of the multinomial logistic regression. It's a tedious process, but important to do. Thanks for the help! :)
Comment: I'll definitely try this and report back. Thanks!!
Comment: Hey, I'm really glad it helped - I personally have little experience of multinomial models, but I remembered this is what I was taught back in the day!


Big Query: how to use Variable and loops with column names

Question: I am trying to use a loop to update a table in Bigquery. My table structure is as following (with 100 columns and thousands of rows):

DATE
PERIOD1
PERIOD2
PERIOD3
PERIOD4
PERIOD5
PERIOD6
PERIOD...
PERIOD100

2021-01-01
row

2021-02-01
row

For each date, I would need to use a loop to populate the values with something like
<code>---
DECLARE VAR_PERIOD INT64 DEFAULT 1
LOOP
IF PERIOD > 100 THEN LEAVE;
END IF;
---
update `mydataset.mytable` set CONCAT('PERIOD',VAR_PERIOD) = (select{+my query})
</code>
which obviously cannot work, so I'm wondering what alternative method can be used to easily update my table columns ?
Answer: For this you can try using BigQuery API client libraries link.
There are more languages available but I am using python here.
You can directly start in cloud shell. There you can write a Python program to
do your job.
There is some assumption I am taking regarding your requirements :
You want to use SELECT clause to get some value and using which you want to
update values of Period columns.
<code>from google.cloud import bigquery

''' Construct a BigQuery client object. '''
client = bigquery.Client()

query = """
    select col_name from `projectID.dataset.table`
    where condition
"""

''' Make an API request. '''
query_job = client.query(query)

''' Store the value of query result in some variable (value). '''
for row in query_job:
    value = row[0]

'''
Creating the query to update the columns using the value.

UPADTE `projectID.dataset.table`
SET Period1 = Period1 + value, Period2 = Period2 + value ...
where condition
'''

query = "UPDATE `projectID.dataset.table`  SET "

for i in range(1,101):
    query += 'period'+str(i)+' = ' + 'period'+ str(i) + ' + ' +str(value) +','

query = query[0:-1]
query += ' WHERE condition'

''' Make an API request. '''
query_job = client.query(query)
</code>
All BigQuery Update statement must have a WHERE Clause. If you
want to update all the rows than in WHERE condition mention TRUE link.
Comment: Thank you Chandra for your response. Unfortunately this becomes too complex for my use case, I need to limit the option to BigQuery UI / Console


Rails doesn't seem to randomize primary key after deployment

Question: I'm not exactly sure where the problem lies, but I get the following errors when trying to create a (generic) joke (model):
ActiveRecord::RecordNotUnique (Mysql2::Error: Duplicate entry '2147483647' for key   'PRIMARY': INSERT INTO `jokes` (`content`, `created_at`, `id`, `rating`, `updated_at`) VALUES ('dsfgdsfgdfgd', '2013-02-27 16:33:12', 90650754896700, 0, '2013-02-27 16:33:12')):
  app/controllers/jokes_controller.rb:141:in `create'
  app/controllers/jokes_controller.rb:140:in `create'

And when I try to save another one:
ActiveRecord::RecordNotUnique (Mysql2::Error: Duplicate entry '2147483647' for key 'PRIMARY': INSERT INTO `jokes` (`content`, `created_at`, `id`, `rating`, `updated_at`) VALUES ('dsfgdsfg', '2013-02-27 16:32:23', 29733688655250, 0, '2013-02-27 16:32:23')):
  app/controllers/jokes_controller.rb:141:in `create'
  app/controllers/jokes_controller.rb:140:in `create'

The error mentions that I have a duplicate entry (the primary key 2147483647). I am only able to create one joke ever. I never had this problem before deployment, the only notable thing I can think of which changed is the database type, from sqlite3 to mysql2.
Here's the important code bits from my joke model:
before_create :randomize_id
#...
validates :content, :presence   => true
validates :content, :uniqueness => true
#...
  private
def randomize_id
begin
  self.id = SecureRandom.random_number(100_000_000_000_000)
end while Joke.where(:id => self.id).exists?
end

Comment: Why are you doing this?
Answer: Your key is too large. You can only put a 32 bit (signed) integer in that ID field. Not sure why you're trying to create your own primary key, but anyway, try this:
  self.id = SecureRandom.random_number(1000_000_000)

By the way (2^32)/2 -1 = 2147483647
Comment: No problem, though I do wonder why you're creating your own primary key? You could just let mysql do it's thing and create them for you. Anyway, glad to help
Comment: Ah, I wanted them to assigned id's in a specific way, the randomize was just a place holder =)


Is there a computable procedure for testing whether a given modal schema is true in a given finite relational model?

Question: Is there a computable procedure for testing whether a given modal schema is true in a given finite relational model?

This is inspired by question 2 on page 19 by internal numbering (PDF page 34) of the full build of Boxes and Diamonds. (Warning: some spoilers for exercises)
That question is about the truth of the schema $A \to \lozenge A$ in model $M$, where $A$ is an arbitrary formula.
The model $M$ is defined as follows.
There are three worlds $w_1, w_2, w_3$.
There are three primitive propositions $p_1, p_2, p_3$.
The accessibility relation $R$ is $\{(w_1, w_2), (w_1, w_3), (w_2, w_3), (w_3, w_3)\}$.
And the valuation function $V$ is defined by $V(w_i, p_j) = 1$ if and only if $i \le j$, otherwise $V(w_i, p_j) = 0$.
We can demonstrate that $A \to \lozenge A$ doesn't hold everywhere by picking $A$ to be equal to $\lnot p_2$ and picking $w_1$.
$\lnot p_2$ holds at $w_1$. However $\lnot p_2$ fails at both $w_2$ and $w_3$, therefore the original formula $A \to \lozenge A$ is not true.
However, this was a lucky guess and naively testing all possible combinations of formulas and worlds would take infinite time.
This got me wondering: is there a computable procedure for testing whether a given modal schema is true in a finite relational model?
Comment: With a finite relational model, your above propositional modal logic statement can be algorithmically turned into classic PL derivation such as the common tableaux tree branching method, so in this sense there's a computable procedure. For your example here $A \to \lozenge A$, you can first assume its negation, ie, $A \land \square \lnot A$. But even $w_1$ is accessible to $w_2, w_3$, under Kripke model we cannot branch into any of them because the modality begins with $\square$, so your original statement is not a tautology. But adding symmetry to K, $A \to \square \lozenge A$ is true...
Answer: Since normal modal logics are robustly decidable the existence of such procedures should come as no surprise. Indeed, there's much work in modal logic on classes of algorithms that for a given pointed Kripke model $(M, w)$ and a modal formula $\varphi$ decide in a finite number of steps, whether $\varphi$ is true in $(M,w)$ or not given a certain computational bound. Such algorithms are typically called 'model checkers'.
Much of this work centers around temporal logics and is therefore not easily adaptable to the case of the logic $K$. See for instance  L. A. Dennis et al: 'Practical Verification of Decision-Making in Agent-Based Autonomous Systems'. CoRR, abs/1310.2431, 2013.
Recently, there has been efforts to provide model checkers specifically for the logic $K$. See for example J.-M. Lagniez et al.: 'On Checking Kripke Models for Modal Logic K'. In: P. Fontaine et al. (eds.): Proceedings of the 5th Workshop on Practical Aspects of Automated Reasoning (PAAR 2016), Coimbra, Portugal, 69-81.
This publication uses a model checking algorithm that is based on a very simple computation procedure termed 'Algorithm 1' (p.71), which is then optimized in various ways to respect certain complexity bounds.
Answer: Here's a direct proof of decidability:
Suppose we're given a finite model $M$. By definition, this $M$ consists of a finite set of worlds $W$, an accessibility relation $R$, a finite set of propositional atoms $P$, and a valuation function $v$. Given a modal scheme $\mathscr{S}$, here's how we test whether $\mathscr{S}$ is true in $M$:
The point is that since $M$ is finite, there are only finitely many "definable sets of worlds" - and so only finitely many distinct things we need to plug into $\mathscr{S}$ to test the truth of $\mathscr{S}$ in $M$. Note that it's important we don't overshoot here: not every subset of $W$ is $M$-definable! So even though the full powerset of $W$ is easily computed, we need to be a little cautious about computing the "$M$-definable powerset of $W$" - call it $\mathscr{D}$ - which is the thing we actually care about here.
To compute $\mathscr{D}$, we do the following:

For $n\in\mathbb{N}$, let $F_n$ be the set of modal formulas in $P$ involving at most $n$ logical symbols (say $\Box,\Diamond,\neg,\wedge,\vee$). Note that each $F_n$ is finite.

Search for some $n$ such that every subset of $W$ which is $M$-definable by a formula in $F_{2n+1}$ is already $M$-definable by a formula in $F_n$. Since $W$ (and hence $\mathcal{P}(W)$) is finite, we are guaranteed to eventually find such an $n$. Crucially, since the map $\varphi\mapsto\varphi^M$ is computable, this is a step we can actually perform.

But then it's easy to see that this $F_n$ - or rather, the set of subsets of $W$ defined in $M$ by formulas in this $F_n$ - is all of $\mathscr{D}$. So now we just verify the finitely many occurrences of $\mathscr{S}$ corresponding to formulas in this $F_n$.

Note that this argument is very coarse - it applies, for example, to higher-order modal logics as well.


Why Navigation Graph IDs are not listed in R.id?

Question: I'm new to Android Navigation Component and I think I have everything ready for using it but when I try to navigate to another fragment using an action or a fragment id, the ids generated in the navigation graph xml file are not listed in R.id, so I can't use them to navigate.
This is the code I'm trying to execute:
view.findNavController().navigate(R.id.action_mainFragment_to_addFragment)
This is my nav_graph.xml file (autogenerated):
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/nav_graph"
            app:startDestination="@id/mainFragment">
    <fragment android:id="@+id/mainFragment"
              android:name="com.example.nopesal.costlist.MainFragment"
              android:label="MainFragment"
              tools:layout="@layout/fragment_main">
        <action android:id="@+id/action_mainFragment_to_addFragment" app:destination="@id/addFragment"
                app:enterAnim="@anim/nav_default_enter_anim" app:exitAnim="@anim/nav_default_exit_anim"
                app:popEnterAnim="@anim/nav_default_pop_enter_anim" app:popExitAnim="@anim/nav_default_pop_exit_anim"/>
    </fragment>
    <fragment android:id="@+id/addFragment" android:name="com.example.nopesal.costlist.AddFragment"
              android:label="fragment_add" tools:layout="@layout/fragment_add"/>
</navigation>

As you can see, the ids are being generated with @+id/ and it's supposed to appear in R.id when I try to referentiate them, but they are not showing. It doesn´t matter if I try to reference an action or a fragment, neither are showing.
I've tried to clean the project, rebuild, change the gradle navigation implementation, change the id names, restart Android Studio... I can´t solve it. Also searching for tutorials, using R.id is he only way to referenciate them so I don´t know what I'm doing wrong.
If anyone have faced the same issue o knows the solution I would be completely grateful.
Thank you so much.
Answer: I just solved it!
I just noticed i had this imports at the beggining of the file. I suppose that they have imported automatically after copy and paste the navigation code. Deleting this imports fixed the issue.
import android.R.attr.data
import android.R

Answer: If you use android featured modularization architecture, make sure import the right .R
Example:
com.example.feature_camera.R
com.example.feature_camera.R as cameraR

Answer: Yes,I have removed import android.R and it worked for me.
Comment: Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer).


I have to click twice on the button the see my dropdown list. How to resolve?

Question: In the following example below, I have to click twice on the "Action" button the see my dropdown list. Why? Is it possible to resolve?

$(document).ready(function() {
  $(".actionButton").click(function() {
    $dropdown = $("#contextMenu");
    $(this).after($dropdown);
    $(this).dropdown();
  });
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

     Line 1
     Action

App

Send

Additional client-side logic. I upload this html on my server-side and then send it back as a response.
document.querySelector("#app").innerHTML = await view.getHtml();

    async getHtml() {
    let response = await fetch('/list', {
    method: 'POST',
           headers: {
            "Content-Type": "text/plain"
        },
    body: JSON.stringify({ x: 5, y: 6 }),
    headers: {
      'Content-Type': 'application/json'
    }
  }).then(response => response.json());

   if (response.ok) {
     return response.data;  // the html above
    } else {
        throw new Error(`${response.status}: ${response.statusText}`);
    }}

Comment: Converted your code to a snippet and it appears to work fine.  Please update the snippet to demonstrate the issue.
Comment: In the snippet it works fine. Check your browser developer console, maybe there is an error which might give you some hint.
Comment: @guyaloni Hi! I provided some addotinal client-side logic to see the way I am using this html.
I can confirm that it wroks fine independantly. But it still takes two clicks to see that dropdown based on my use case.
Comment: I see, you are calling `view.getHtml()`. But I don't see `view` object in your client side code. Can you please add that as well?
Comment: @Battle Hawk Hi! I am pretty sure the view object is not related to this issue at all. It is simply used to call that getHtml method.
I think that something is wrong when I use that html as a module. Bootstrap lib wasn't loaded on the 1st load?! JQuery?! Not sure what's actually wrong :)
Comment: @EvgeniySharahov If I do not see the full picture of your issue, then I am more lost about the issue than you are. In that case, I can only give you a suggestion that you inspect and check the console when you click. Like

```$(".actionButton").click(function() { console.log($(this), $("#contextMenu")); });```

And see when you first click, what does the console.log say in inspect?
Comment: @Battle Hawk Hi! https://prnt.sc/11jrumm   Each time I click on the button, I log proper output in the console. But the dropdown wasn't shown when I refreshed the page. Something is wrong with that bootstrap dropdown I think
Answer: What I understood so far, I think of two possible methods to get it around.
First method:
I suggest, you load following HTML code sample in your #app Element from ajax. In this way, you do not need to use onclick event on $(".actionButton") for this. Because according to bootstrap3 documentation, you do not need set any onlclick event for loading the dropdown, it'll be done by bootstrap3 itself.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

     Line 1

        <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Action
        </button>

App

Send

Second method:
If above way do not work, then you have to add bootstrap.min.css to  tag and jquery.min.js, bootstrap.min.js at end of the  tag in the main html file where  #app element resides in.
Then you would have to get the only barebone html from ajax and insert it into #app.
The barebone html code can be like below:

     Line 1
     Action

App

Send

And in this case, your js code for onclick event should be like below:
$(document).ready(function() {
  $("#app").on("click", ".actionButton", function() {
    $dropdown = $("#contextMenu");
    $(this).after($dropdown);
    $(this).dropdown();
  });
});

Comment: thank you so much! I did the following "jquery.min.js, bootstrap.min.js at end of the  tag in the main html file where #app element resides in" it solved the problem!
Comment: @EvgeniySharahov I am glad that one of the methods helped you resolve the problem. Happy coding and stay safe.


I am trying to hide and show react native date picker after clicking touchable opacity

Question: I am working on a react native application and I am trying to figure out how to hide the datepicker after clicking a touchable opacity component.
Here is the logic for setting up the datetimepicker
 const [showCompleted, setShowCompleted] = useState(false);
 const [isHidden, setHidden] = useState(true);

 const onChange = (event, selectedDate) => {
   const completedDate = selectedDate || Date;
   setShowCompleted(Platform.OS === 'ios');
   setCompletedDate(completedDate);
 };

 const showDatepicker = () => {
   if (isHidden === true) {
     setHidden({ isHidden: false });
     setShowCompleted(true);
   } else {
     setHidden({ isHidden: true });
   }
 };

Here is the logic for the UI
<TouchableOpacity
    style={{
      height: 50,
      margin: 15,
      backgroundColor: 'white',
      borderRadius: 5
    }}
    onPress={showDatepicker}
  >
    <View flexDirection='row'>
      <Text style={{ color: 'red', fontSize: 15, margin: 15 }}>
        Completed Date
      </Text>
      <Text style={{ marginTop: 15, fontSize: 14, marginLeft: 140 }}>
        Mar 17, 2020
      </Text>
    </View>
  </TouchableOpacity>
  {isHidden ? (
    <View>
      {showCompleted && (
        <DateTimePicker
          testID='dateTimePicker'
          placeholder='Completed Date'
          value={completedDate}
          mode='date'
          display='default'
          onChange={onChange}
        />
      )}
    </View>
  ) : null}

Any thoughts welcome. I am trying to accomplish the same effect as scheduling a new event on an iphone. Where you touch the date and the datepicker comes down and you touch it again and it goes up. Currently, it goes down but I can't figure out how to get it to go back. I think I am overlooking something very simple.
Answer: Your problem seems like you're updating the state in the wrong way, you are saving object with containing data, instead of doing that, try to just put the Boolean value instead, so simplify your opener function like this
const showDatepicker = () => {
   setShowCompleted(!showCompleted);
};

So each time your function gets executed setShowCompleted will negate the boolean value of showCompleted, so if you first get false when you click on the button the false becomes to true and next time true becomes false and so on.
So you can remove isHidden state and just use showCompleted value instead


Openfire : unable to converse with some external servers

Question: I'm running Openfire 3.9.3 with Debian Wheezy. When I use it, it works well with accounts registred on the server. I have a problem with accounts on others servers.
I tried to create an account on im.6x8.org and im.apinc.org. It works well. Then I tried with an account on jappix.com and I have the following problems :

I can't see my account status from the jappix server and reciprocally
I can send messages from the jappix account and my local account receive it
When I send messages from my local account to jappix, it didn't work. In some clients, I have the error "remote-server-not-found".

When I go to the server sessions in openfire console, I see that jappix has only an incoming connection but im.apinc.org have the both.
In the warn logs, I found this :
2014.12.05 08:12:52 org.jivesoftware.openfire.server.ServerDialback - ServerDialback: OS - Ignoring unexpected answer in validation from: jappix.com id: 7cf4a0dc-cad9-470a-80dc-d431dba5cfd1 for domain: xmpp.myserver.org answer:<stream:features xmlns:stream="http://etherx.jabber.org/streams"><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"><required/></starttls><bidi xmlns="urn:xmpp:features:bidi"/><dialback xmlns="urn:xmpp:features:dialback"><errors/></dialback><sm xmlns="urn:xmpp:sm:2"><optional/></sm><sm xmlns="urn:xmpp:sm:3"><optional/></sm><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression></stream:features>
2014.12.05 08:12:52 org.jivesoftware.openfire.server.ServerDialback - ServerDialback: OS - Ignoring unexpected answer in validation from: jappix.com id: 7cf4a0dc-cad9-470a-80dc-d431dba5cfd1 for domain: xmpp.myserver.org answer:<stream:error xmlns:stream="http://etherx.jabber.org/streams"><policy-violation xmlns="urn:ietf:params:xml:ns:xmpp-streams"/><text xmlns="urn:ietf:params:xml:ns:xmpp-streams">TLS encryption is mandatory but wasn't used</text></stream:error>

More logs here : http://pastebin.com/6nV0ytA8
In the firewall, I have the ports 5222, 5223, 5269, 7777, 5229, 7070 and 7443 open in tcp.
I spend a lot of time trying to resolve this but I found nothing and I have no more idea. Someone have an idea ?
Thanks by advance.
Regards,

Edit :
I just saw that jappix was with secure connection and not the others. If I force it, I have the same problem. I try to change the certificate with a valid one but nothing changed.
Answer: From the original logs, I see TLS encryption is mandatory but wasn't used- so apparently jappix.com needs you to support encrypted S2S connections.
btw, you can test your XMPP server (and others) via https://xmpp.net/
Comment: Thank's for your answer. Yes, I found later that jappix wasn't working because it was forcing me to use s2s encryption and the others don't. After some search, I found that it is a know bug in openfire. So I juste installed ejabberd and it works fine


Understanding proxy variable

Question: Can somebody help me to understand a topic? Say in my analysis I have the true variable education ($E$) which is measured by a proxy variable number of years in school ($S$). Here, the error is measurement is $E-S$.
I was told that, this error is independent of $S$ not of $E$.
I can not understand how it can be the case? Should not be that error dependent on both $S$ and $E$?
Thanks,
Comment: some more context might help.
Answer: You may be thinking that it might be possible that the length of time somebody is in school may affect how uncertain we are about their education.  I suspect that what you were told stems from a different way of thinking about this.
If the number of years in school is measured accurately, for example from reliable administrative records, then there should be no error in $S$.  Education is a more elusive concept: how much does a person learn?  And so the error in $E-S$ comes from $E$.
Answer: The statement that the error is independent of S sounds like this was an example and you have measured both S and E and done a regression model with S as the predictor and E as the response.  In that case the errors/residuals from the model are independent (if the model is correct) of the predictor variable (S in this case), but not E.  Those statents are facts based on the theory and assumptions of fitting regression models, if you need to understand that better then I would suggest a good book on linear models.
If I have misunderstood where the statement comes from, then more background on the context might help us to help you.
Answer: I know I'm very late to the party, but one thing that might help: You appear to be under the impression that there are three sources of randomness in your model: $S$, $E$, and $u = S - E$, where $u$ is the proxy measurement error. This is not correct. There are only two sources of randomness in your model. They are (in a typical setup), $E$, your latent variable, and $u$, your proxy measurement error.
$S$ is a random variable, in the sense that it is equal to $E + u$, ie the sum of two random variables. However, because $S$ is uniquely determined by $E$ and $u$, it follows that $S$ is not a source of randomness. So to discuss the dependency between $u$, $S$, and $E$ is not really meaningful, because at most only two of these three random variables can be a source of randomness in your model.
Note, in a typical framework, a common assumption is that $u$ (proxy measurement error) is independent of $E$ (latent variable). Your framework appears odd in that someone has told you that your proxy measurement error is independent of $S$. We could, of course, set things up this way, by assuming that $u$ and $S$ are the sources of randomness and that $E$ is uniquely determined by the two of them. But, as I said, this is an odd way of doing things.
Comment: The OP framework is called Berkson measurement error model. @Henry described in a different answer as to why this might be a reasonable model to entertain for this situation: four years in Stanford arguably give you more than four years in a local community college.
Comment: @StasK Interesting stuff (I just had a quick scan of the abstract and intro of the original paper). Thanks for the comment. By the way, if you edit for Wikipedia at all, feel free to improve [this entry on Berkson error](http://en.wikipedia.org/wiki/Berkson_error_model) as it is probably the most uninformative Wikipedia page I've ever seen :-)
Comment: I do edit Wikipedia, but I am not an expert on measurement error models. I wanted to improve the SEM entry for a very long time (introduce matrix notation and such), but never got to doing it.

Understanding proxy variable


Validate multiple textareas on submit before post to mysql

Question: I need to check multiple textareas if empty before I can write any data in a mysql db.
The form is generated dynamically and I don't know the id/name of the textareas.
Form with multiple, dynamic generated textareas, id and names generated dynamically as well:
<form action=\"$self\" method=\"POST\" id=\"daily_frm\"  enctype=\"multipart/form-data\">

  Station
  Comment
  QCIF
  Attachment

";

while ($stn_b = mysql_fetch_array($station_b)){
  print "

           $stn_b[station]
           <textarea id=\"$stn_b[station]_comment\" cols=\"60\" rows=\"5\" value=\"\"></textarea>
           <input type=\"checkbox\" id=\"$stn_b[station]_qcif\" value=\"1\"/>
          <input id=\"$stn_b[station]_attach\" type=\"file\" />

        ";
}

print"

<input type=\"submit\" value=\"Submit\" name=\"submit_daily\" id=\"submit_daily\"><input type=\"reset\" name=\"clear_daily\" value=\"Clear\">

</form>

My approach to check if any textarea is empty when clicking the submit button:


How to control pagination and data merge display when using view attachments

Question: Now I have a requirement to display the activity data in the activity list:
Judging by the current time, the activities that are about to start are sorted in ascending order; the activities that are starting or have ended are sorted in descending order.
Note: Upcoming data should come first, followed by past data.
I used the view's attachment to achieve this:

The main view shows upcoming events
The attachment shows the activity that is in progress or has ended

Now there are two more questions:

The data of the main view and attachments are separated, but I actually want to display them together; for example: my list should display 4 pieces of data in one row, but the main view has only three pieces of data, and the result is that the data of the attachments does not follow the main The view displays, but starts to display on a new line, and the first line has only three pieces of data; what I want is that the first three pieces of the first line are the main view data, and the fourth piece is the first data of the attachment.
Both the main view and the attachment have a paging bar, and I only want one paging bar, and the data of the main view and the attachment are merged and paginated.
Comment: At first I wanted to use HOOK_views_pre_build, HOOK_views_query_alter, HOOK_views_pre_execute to modify the query sql statement, but none of them took effect
Answer: I used another method to complete my needs, I don't need multiple views:
<code>function MODULE_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  if ($view->id() == 'events') {
    $query->orderby = [];
    $query->addOrderBy(NULL, '(table.field_date<CURDATE())', 'ASC', 'all_date');
    $query->addOrderBy(NULL, '(greatest(table.field_date,CURDATE()))', 'ASC', 'now_date');
    $query->addOrderBy(NULL, '(least(CURDATE(),table.field_date))', 'DESC', 'old_date');
  }
}
enter code here
</code>
refer to:
https://stackoverflow.com/questions/25892421/sort-records-by-future-asc-past-desc


Best distribution to model durations

Question: I am struggling to find an appropriate distribution to model the total number of vacation days taken in a year.
I originally thought of going with a standard count distribution like negative binomial or even using hurdle regression to combine negbin with a logistic model.  However, the nature of the dependent variable makes me second guess my choices.
The problem I have is that I am trying to predict the total number of days and these are not independent events.  If I was modeling "# of vacations" and not days, I would be more willing to use a count model.  I have searched all over for things like "duration modeling" but I am not finding anything helpful.
Any suggestions to point me in the right direction are greatly appreciated.
Comment: Depending on the available explanatory variables, you might think of using [Poisson regression](http://en.wikipedia.org/wiki/Poisson_regression).
Comment: Fitting a model to the frequency of the event, and then combinging that with a second model for the scale/duration/magnitude of that event, is a common problem for actuaries.  Eg a negbin model for number of accidents, and some gamma or similar for how much they cost.  Could be one way to go.
Answer: I don't know what is out there in the literature but since you said that you would be willing to use a count model to predict the number of vacations why not do that and set it up in a hierarchical fashion that involves fitting a distribution for the number of days per vacation.  Then take number of vacations and based on a likelihood approach take the highest mode of the number of vacation days, take the number of days for the mode and multiple it by the count model estimate for vacation days.  If there is a tie for the mode maybe an arbitrary pick would be reasonable.  Just a thought.

Best distribution to model durations


Importance of the normality assumption in linear statistical models

Question: Statistical model for Complete Randomized design
$y_{ij} = \mu + \tau_i + \epsilon_{ij}$
where, $i$ denotes treatment and $j$ denotes observation.
$i=1,2,...,k\quad and \quad j=1,2,..., n_i$
$y_{ij}$ be a random variable that represents the response obtained on the $jth$
observation of the  $ith$ treatment.
$\mu$ is the overall mean of the response $y_{ij}$
$\tau_i$ is the effect on the response of $ith$ treatment.
$\mu_i = \mu + \tau_i$
here $\mu_i$ denotes the true response  of the $ith$ treatment.
and $\epsilon_{ij}$ is the random error term represent the sources of nuisance variation that is, variation due to factors other than treatments.
the assumption is $\epsilon_{ij}\sim^{iid} N(0,\sigma^2)$
Why do we have to assume  $\epsilon_{ij}\sim^{iid} N(0,\sigma^2)$ ?
that is What is the importance of this assumption? If we do not assume it , what will be the effect?
Any help including reference will be appreciated.
Answer: The normality assumption is only used for testing and inference. Regression diagnostics can be utilized to assess this assumption. If the assumption is violated, either transformation of the dependent variable or generalized linear models can be the solution.
I think most regression textbooks addressed this issue, e.g. Page 86 of Regression Analysis by Example, 4th Edition, by Chatterjee & Hadi.


An image keeps going below the rest of the images in a group div?

Question: I have a collection of images sorted into three groups; a group with all the images, a group with the first half of the images and a group of the second half of the images. I want to put the images in a line, but the last image keeps dropping to the bottom... how do I fit this is the same line?`

#firstlot {
  z-index: 10;
  position: absolute;
  left: 61%;
  top: 3.5%;
}
#secondlot {
  z-index: -5;
  position: absolute;
  left: 61%;
  top: 3.5%;
}
#home {
  width: 17.5%;
}
#home2 {
  width: 17.5%;
}
#thecoopertimes {
  width: 38.5%;
}
#thecoopertimes2 {
  width: 38.5%;
}
#aboutme {
  width: 25%;
}
#aboutme2 {
  width: 25%;
}
#contact {
  width: 21%;
}
#contact2 {
  width: 21%;
}

I know when you look at the code you will say to make an unsorted list instead, but I'm doing it this way for a reason.
Comment: You should check your percents, #home 17.5% + #thecoopertimes 38.5%  + #aboutme 25% + #contact 21% = **102%**. You also have some space in between your inline elements, so you should use inline-block or floating blocks. Take a look at [this Example](http://jsfiddle.net/1a64Lq58/)
Answer: The problem is that if you adds all the numbers % on your images, it provides over 100%. Then you have space between your images, which you should also take into account.
I have tried and it resolves itself when you corrects the numbers.
Answer: It's because you have extra spaces in your code, check here :
Removing whitespace between HTML elements when using line breaks
Thus you can remove them or give a smaller width for each elements.
Example, if you don't format the HTML you won't have your problem:

Answer: Please try a vertical-align:top; to all div that is getting aligned to bottom
Comment: Sorry but I don't see how this can solve your problem. I've prepared a fiddle, I would be glad to see the solution in action : http://jsfiddle.net/fub3n07w/
Comment: Thanks, I still don't get how this could solve the OP problem which was the last image was going on a second line. Nothing to do with the alignement of the image in a vertical manner.
Comment: try editing with the fiddle and remove vertical-align : top and see what happens then


Using Jquery to prevent a "Submit Button" from posting data if a field is left blank

Question: So I'm putting together a little registration area for my web project, here. The user inputs various strings such as "Username", "Password", etc.
I already have a bit of code set up in order to prevent duplicate Usernames or Passwords in the database. I also have a guard in place if the "Password" and "Repeat Password" fields don't match.
What I'm trying to do now is to -
1: If the user attempts to Submit data while a field is blank, it will not post.
2: Display a "Fields cannot be blank" div I've assigned "display: none" to.
I was thinking something along the lines of assigning the input fields a class of "Required", and using some sort of code such as
if  == null
.show;
return false; //To prevent the rest of the function (the submit button posting to login/register) from firing.
Running into obscene problems. Anyway. Here's what I have so far.
$("#SubmitButton").click(function () { //Click Submit
            if ($("#PassReg").val() != ($("#PassConfirm").val())) { //Both fields match
                $("#PasswordMismatch").show(); //Or this div shows you messed up
                return false; //And nothing else fires
            }

            $.post("login/register", $('#ConfirmPanel *').serialize(), function (result) {

                if (result == 2) //Json return from C#
                    $("#UsernameInUse").show(); //Shows an error div
                else if (result == 3) //Json return from C#
                    $("#EmailInUse").show(); //Shows an error div
                else {
                    $("#ConfirmPanel").dialog('close'); //Closes the registration dialog
                }

            });
        });

Any thoughts? At first I thought that I literally -cannot- use "class" to mark an input field, and then have that input field compared to a null value. I don't know, though.
Comment: Ignore that bit about "if==null.show". I didn't use the proper code tags and it got fubared. Basically I wanted to select the "Required" class, compare that class .val to null, and if it's null, then display an error div and kill the submit function.
Comment: Avoid reinventing the wheel; use the [jQuery Validation plugin](http://bassistance.de/jquery-plugins/jquery-plugin-validation) and the [jQuery Form plugin](http://jquery.malsup.com/form/).
Answer: You should use the .submit() jquery event handler on the form instead of .click() on the button. Then return false to prevent the normal form submission if needed.
Comment: Yes, definitely use ``.submit()`` instead of ``.click()`` in case they trigger the submit some other way!
Comment: Thanks for that info. Appreciated.
Answer: Since you are trying to submit the form using $.post you should stop the default behavior of the form submit by alwasy returning false from submit button click handler.
$("#SubmitButton").click(function () { //Click Submit
            if ($("#PassReg").val() != ($("#PassConfirm").val())) { //Both fields match
                $("#PasswordMismatch").show(); //Or this div shows you messed up
                return false; //And nothing else fires
            }

            $.post("login/register", $('#ConfirmPanel *').serialize(), function (result) {

                if (result == 2) //Json return from C#
                    $("#UsernameInUse").show(); //Shows an error div
                else if (result == 3) //Json return from C#
                    $("#EmailInUse").show(); //Shows an error div
                else {
                    $("#ConfirmPanel").dialog('close'); //Closes the registration dialog
                }

            });

            return false;
        });

Answer: The jQuery way of preventing form submission is to use preventDefault(), like:
$("#SubmitButton").click(function (event) { //Click Submit
        if ($("#PassReg").val() != ($("#PassConfirm").val())) { //Both fields match
            $("#PasswordMismatch").show(); //Or this div shows you messed up
            event.preventDefault(); //And nothing else fires
            return;
        }

        //...
});

However, since you are posting the form asynchronously when validation passes, what you really want is something more along the lines of:
$("#SubmitButton").click(function (event) { //Click Submit
        event.preventDefault();  //we don't ever want to allow the default behavior
        if ($("#PassReg").val() != ($("#PassConfirm").val())) { //Both fields match
            $("#PasswordMismatch").show(); //Or this div shows you messed up
            return;
        }

        //post the form
});

The rest of what you suggest (using a class to mark each required input field, checking them all for empty strings) is reasonable.
Be aware that because you are binding the button's click event instead of the form's submit event it is entirely possible for the user to submit your form without ever clicking on your button and triggering your validation code.  For instance, by pressing return from any one of your text fields.
Also note that in this case you may find it more convenient to just use a traditional onsubmit directive on the form, like:
<form onsubmit="validateAndPost(); return false;">

</form>

Example:  http://jsfiddle.net/AwxGE/
Answer: I admire your desire to use jquery, however I would advise using a normal ASP.NET ReqiredFieldValidator control. As well as making your page substantially more concise and easy to maintain, it also allows you to very simply invoke server-side validation:
public void submitbutton_click(object sender, EventArgs args){
    Page.Validate();
    if(Page.IsValid){
        doStuff();
    }
}

Please don't reinvent the wheel, and don't trust the browser to behave as you think it will.
Comment: I agree 100% that server-side validation is key here, but this is just some "no blank fields" nonsense I'm trying to stomp out. I'll worry about the final product much later in the project's life.
Comment: Adding RequiredFieldValidators would have taken less time than asking the question...
Comment: client side validation should always be in addition to server side, but it produces a nicer user experience, especially on slow connections.
Comment: ASP.NET's standard validators include client-side validation by default!
Answer: use this -
$(document).on('click', '#SubmitButton', function () {
`enter code here`
});


RDP connection has the source IP of the host server

Question: I came across an event on one of my windows servers,
Machine ABC has a successful incoming RDP connection from 192.168.0.16,
But the IP of machine ABC is 192.168.0.16.
Is it even possible that a machine can RDP into itself?
Any leads as to how this can happen or what could have led to such an event?
Comment: **Is it even possible that a machine can RDP into itself?** - Yes.
Comment: It should be concerning if you, or another admin, didn't actually use an RDP session; if you did, then what was the real address of the connecting machine?
Comment: @Shōgun8 We did not initiate the RDP connection, I suspect that the machine is compromised.  Got some info on this link (https://security.stackexchange.com/questions/211768/windows-rdp-logging-into-itself) - trying to identify the mechanism used here.
Comment: @joeqwerty thanks, could you please elaborate or point me towards articles that gives further details on why someone would setup and use such a connection?
Comment: I have no idea why someone would setup and use such a connection. My point is that it is possible. You'll have to investigate it.
Answer: Well, it's definitely not something one would intentionally do since it serves no purpose. The only reason that would make sense, is if you wanted to hide your remote network address, and connect via some sort of proxy that's running on that machine.
Here is what I would do in your situation:

Install Sysinternals Sysmon and configure it to log all outgoing network connections, which would be event id 3. This will ensure that any process that opens a TCP connection will be logged. This obviously won't work retroactively, but it will work the next time it happens. Generally speaking I would recommend to run Sysmon on all machines that are somewhat critical for security.

Run "netstat -ab -p TCP" and see if there are any suspicious processes running and listening for incoming connections.

Make sure that you have proper auditing setup on that machine so that you can potentially investigate activity. For example: https://system32.eventsentry.com/security/auditing_for_everyone.

NetFlow is something I would also consider activating and collecting. Otherwise you have no clue what's entering and/or leaving your network. If you had NetFlow data, you could correlate network traffic with the RDP events you mentioned.

I would consider installing 3rd party tools as well. EventSentry integrates with Sysmon and can really help with reporting, and also shows you processes listening for network connections. It also flags suspicious IPs if you use the NetFlow feature. You can just download the trial, no need to purchase (and it's cheap for a single host).
I think that should get you on the right track ...


Can I delete Azure resources after creating an image?

Question: I created a CentOS 7.4 VM named "base" on Azure. When the VM was created, the following resources

base_Os_Disk_1_xxxx
basexxx (Network Interface)
base-ip (Public IP Address)
base-nsg (Network security group)
base (Virtual Machine)

Configured the VM as needed and created an image. The process deleted the VM named base and created a new resource named base-image-timestamp (Image).
However the other resources like disk, network interface, public ip, etc were not removed.
I can successfully create new VMs based off the image.
Can I now manually delete the resources that were initially created (base_OsDisk, base-ip etc) or are they needed for new VM creation?
Answer: Correct. You can delete all the leftover resources. Azure does not delete it automatically for you because you may want to use it for new deployments, let say, keep the existing network configuration and public IP address instead of creating a new one for the new VM.
Just make sure to not delete the image.
Comment: I tried to reuse the IP address resource and it was grayed out. Will double-check.
Comment: Must be because it is associated with the old network card which still exists.


discrete random variable PMF

Question: suppose You rented a house and realtor gave you 5 keys, one for each of the 5 doors of house. unfortunately all keys look identical. so to open the front door, you try them at random.
=> Find the  PMF (probability mass function) of the number of trials you will need to open the door, under the following supposition :
i. after an unsuccessful trial, you mark the corresponding key, so you never try it again
ii. at each level you are equally likely to choose any key
Comment: actually I am new to probability and I feel a lot of trouble to understand the problem. I hope U people will help me
Answer: We mark bad keys: The simplest way to look at the problem is the correct key is equally likely to be the first key you try, the second, and so on. So if $N$ is the number of trials needed, we have $\Pr(N=1)=\Pr(N=2)=\Pr(N=3)=\Pr(B=4)=\Pr(N=5)=\frac{1}{5}$.
Perhaps you are using the notation $f_N(k)$ for the probability that $N=k$. Then you could write $f_N(k)=\frac{1}{5}$ if $k=1$, $2$, $3$, $4$, or $5$, and $f_N(k)=0$ otherwise.
One can also do the problem more slowly. The probability that the first key opens the door is fairly clearly $\frac{1}{5}$, for there is only $1$ good key, and all keys are equally likely to be the good one.
In order to open the door with the second key, two things must happen: (i) The first key you try doesn't work and (ii) the second one does. The probability the first doesn't work is $\frac{4}{5}$. If the first doesn't work, then the probability the second does is $\frac{1}{4}$, since you have marked the first key. So the probability you get a failure and then success is $\frac{4}{5}\cdot\frac{1}{4}$. This simplifies to $\frac{1}{5}$.
A similar argument shows that the probability of failure on the first two, followed by success, is $\frac{4}{5}\cdot\frac{3}{4}\cdot\frac{1}{3}$, which again simplifies to $\frac{1}{5}$.
And so on! We get the same answer as with the first solution, but with more work needed.
We don't mark keys: Here $N$ can take on the values $1$, $2$, $3$, and so on forever.
The probability that the first key works is $\frac{1}{5}$.  So $f_N(1)=\frac{1}{5}$.
To get $N=2$ we need (i) failure on the first trial and (ii) then success. The probability of this is $\frac{4}{5}\cdot\frac{1}{5}$. Since we are not marking the key, our probability of success on any trial, given we have failed before, remains at a constant $\frac{1}{5}$. So $f_N(2)=\frac{4}{5}\cdot\frac{1}{5}$.
You should use the same idea to calculate $f_N(3)$. In general, we will find that
$$f_N(k)=\left(\frac{4}{5}\right)^{k-1}\cdot\frac{1}{5}.$$
Comment: thanks. u mean pX(x) = { 1/5 , whan x = 1,2,3,4,5 but it is the answer of second part. what about first part?
Comment: Sorry to disturb U again . can u explain these notations f_N(2)=\frac{4}[5}\cdot\frac{1}{5}
Comment: is this the geometric random variable?
Comment: ok thanks . thanks . U know U solved a bigger problem for me
Comment: You are welcome. I only solved the problem as stated. (Had not noticed the second "with replacement" part until posting first reply. By the way, the system does not like long strings of comments, so I am deleting mine.

discrete random variable PMF


avg # of guesses it takes to pick a certain number between 1-100 (random choices)

Question: essentially...
a square on a 10x10 board is randomly assigned the letter X
what is the avg # of times it would take to guess that position while randomly guessing one at a time and not choosing numbers already guessed
my intuition says it involves binomial / geometric series??
thanks for any hints
Comment: Could you calculate this for $1$ square? $2$? $3$? Can you spot a pattern?
Answer: Hint: As the only information you get is whether or not you're correct, it's equivalent to simply set the order of squares you will pick in advance. There are $100!$ such orderings.
Can you construct the expected value of the index of any particular number in a randomly chosen ordering, for example by pairing an ordering with its reverse?
Comment: wait i see... because it's completely random you are able to outright show all the possible ways you will guess 1-100
Comment: what do you mean by expected value of the index? I understand the 100! so I'm guessing it's some value divided by 100! ?
Comment: @user1990406 If you're trying to pick the integer $1\leq x\leq 100$, and your order of guesses is $a_1,a_2,a_{100}$, the index is the integer $1\leq i\leq 100$ for which $a_i=x$. In other words, it's the number of guesses you need before you hit $x$.
Comment: so the expected value of the index would be 50? if you pair 1..2..3..100 it with it's reverse 100..99..98..1 the expected value of any index is 50? or?
Comment: @user1990406 Almost --- you pair $1$ with $100$, $2$ with $99$, etc.
Comment: would the expected value of the index still be 50? despite my misinterpretation
Comment: @user1990406 Not quite; since you're pairing $i$ with $101-i$ the expected value is $\frac{101}{2}$, not $50=\frac{100}{2}$.
Comment: wow OK I see... cool how that is == to the summation provided by the other answer...  I just don't understand how you had the instinct to put the two orderings next to each other? just because it's one of the possible 100! orderings? and easy to examine?
Comment: @user1990406 The main idea of it is once you've reduced the problem to orderings, no one location (first guess, 37th guess, etc.) is "special" in any way, and so the expected value of the number of guesses is just the average location (index). This can be formalized by many different techniques - you can count the number of orderings that give the correct guess in any particular location, you can pair orderings (like I did; Gauss's proof of the formula for $1+2+\cdots+n$ is where I drew inspiration), you can use cyclic shifts of orderings to establish equal probabilities directly...
Comment: OK my last question is (and thank you so much for everything) is "As the only information you get is whether or not you're correct, it's equivalent to simply set the order of squares you will pick in advance. There are 100! such orderings." how did you draw this conclusion of equivalency?
Comment: I guess I don't really understand "it's equivalent to simply set the order of squares you will pick in advance"
Answer: The probability we choose the correct spot on the first try is $\frac{1}{100}$. The probability we don't choose the correct spot on the first try is $\frac{99}{100}$.
If we don't choose the correct spot (and that has $\frac{99}{100}$ probability), the probability we choose the correct spot on the second try is $\frac{1}{99}$.

Notice the probability we choose the correct spot on the second attempt $\frac{99}{100} \cdot \frac{1}{99}$ (by the multiplication principle) is the same as the probability we chose the correct spot on our first try. Indeed, one can see that the probability of choosing the correct position on the $N$ th try, where $N \in \{1,2,3,...,100\}$ is $\frac{1}{100}$.

$$E(N)=\sum_{N=1}^{100} NP(N)$$
$$=\sum_{N=1}^{100} N \left(\frac{1}{100}\right)$$
$$=\frac{1+2+3+...+100}{100}$$
This is the average of first $100$ positive integers, which is $\frac{100+1}{2}=51.5$.
Comment: so would this be a Bernoulli distribution with 100 bernoulli trials with p = 1/100?
Comment: You can say that the distribution of choosing the correct spot on exactly any specific trial follows a Bernoulli distribution with $p=1/100$. @user1990406