How to perform a what-if study using observational data?

Question: A team fit a Random Forest model to a dataset $S=\{\mathbf{x}_i,y_i\}_{i=1}^N$, where $\mathbf{x}$ is a vector of continuous and categorical variables, and $y$ is a binary response. The model has a low CV-error, and the precision-recall curve looks good.
Now, for new samples they would like to perform what-if studies, i.e. for a fixed variable $x_j$ they would like to see how $p(y=1|x_j)$ changes as a function of $x_j$, all other things being equal. The goal of this activity is the following: for new samples $\mathbf{x}$, they want to modify the value of $x_j$ to  $x'_j$ , so that  $x'_jp(y=1|(x_1,\dots,x'_j,\dots,x_n))$ is maximized. However, by doing so, it seems to me that they modify the distribution $p(\mathbf{x},y)$, thus the results are not reliable anymore. I think this is related to causal inference. Is there a way to modify this process so that it actually works? Which methods should I study to help this team?
EDIT: An important point I forgot to mention is that $x_j$ is one of the continuous variables, unfortunately.
Comment: This is a subschool of study under causal inference, usually referred to as "counter-factual reasoning". This is quite a good paper to get familiar with it: https://www.microsoft.com/en-us/research/wp-content/uploads/2013/11/bottou13a.pdf
Comment: The paper is focusing on "continuously valued variables with meaningful confidence intervals".
Comment: I recommend this for reading: https://ftp.cs.ucla.edu/pub/stat_ser/r354-corrected-reprint.pdf
It's a great primer for causal inference written by Pearl. Essentially, your problem is one of *identifiability*. In principle, purely observational data cannot yield any causal inference. However, if you assume a causal model, then a quantity such as $P(Y=y \mid do(x=x'))$ may or may not be identifiable considering what part of your model is *observed* (appears in the data). Note, this is *not* the same as $P(Y=y \mid x=x')$, the latter being a purely associational (not causal) quantity.
Comment: Thanks @Zhubarb. Actually, I thought counterfactuals would apply to a different problem - _what would have happened, had I set $x_j$ to $c$ rather than to $d$_. In this case, the new sample $\mathbf{x}$ is modified before I get the corresponding new result $y$. I thought do calculus would be more useful in our case. However, I know very little about both approaches, thus I may well be wrong. I'll read your reference with interest. If there's anything else you'd like to suggest, I'm all ears, as long as it's not an overly long book
Comment: @Zhubarb by the way, I forgot to specify that $x_j$ is continuous. I guess this complicates things quite a bit, doesn't it?
Comment: Apologies, I may have missed that nuance in your question, the suggestion was not in light of the temporal order you suggest. Still worth a read though. It is a v good paper and can give insights.
Comment: @Zhubarb One more reason to read it! Thanks.
Answer: This is linked to causal inference. The potential outcomes/counterfactual model will be useful for conceptualization. One easy way to do this is to use the g-formula. The g-formula is essentially the same as do-calculus. For an introductory paper, I would recommend this article by Snowden et al. 2011
The key part of the application of the g-formula is the identifiability assumptions. Common ones are exchangeability, causal consistency, and positivity. This paper describes the conditions. Exchangeability is the assumption that there is no common cause of $x_j$ and $y$. This is the d-separation rule of do-calculus. Causal consistency implies that you have sufficiently specified $x_j$ so that there is no difference in $y$ by residual differences in $x_j$. You can think about this as assuming taking an aspirin in the morning versus night has no difference on mortality. Positivity is the assumption that all individuals have a non-zero probability of having all values of $x_j$. Westreich & Cole provide further details.
Having said that, I would be careful with the usage of machine learning for causal inference. In general, confidence intervals for the g-formula are calculated by bootstrapping. There has been a lot of work showing that confidence intervals based on bootstrapping procedures is invalid for machine learning algorithms, like random forests. For an example, see Naimi & Edwards.
Lastly, since you mentioned that $x_j$ is a continuous variable, you will need to consider how $x_j$ is changed. You can imagine that everyone's $x_j$ is shifted by some quantity $\delta$. Alternatively, you can set a threshold, $\gamma$, where those below (above) are shifted to $\gamma$. The remainder of individuals retain their $x_j$ value
Comment: There is also a cross-fit procedure. Basically, you divide your sample into two pieces and fit whatever algorithm you want to the data. You then use the algorithm from one sample split to predict the outcomes under the different distribution of $x_j$ for the other sample split. This procedure is suppose to attain root-n convergence (even for estimators that converge slower than root-n), so bootstrapping would be a valid way to get confidence intervals. This paper gives the mathematics https://arxiv.org/abs/1801.09138 It is still a fairly new approach, so I haven't seen any applications yet
Comment: The issue is not only random forests (the Naimi paper linked above use xgboost as an option). The issue is that the convergence rate for a lot of machine learning is below root-n. For bootstrapping to work, you need your estimator to have root-n convergence (how fast the estimator converges on the true value as a function of sample size). Methods like random forest or xgboost have much slower convergence. As a result, the confidence intervals are overly narrow. GAMs would be alright to use as far as I know
Comment: Wanted to follow-up on this, I have a pre-print on cross-fitting and machine learning. This shows why the g-formula approach with machine learning isn't the best choice. Our paper also talks about best practices: https://arxiv.org/abs/2004.10337
Comment: Ah! The fact that bootstrapping is invalid for Random Forests is very interesting (also, very unfortunate). Would xgboost be better? The problem is that the team tried to use logistic regression, but the predictive accuracy was real crap. I will have a hard time convincing this team to change their ways, if, in order to predict consistently the results of interventions, they need to use a model with low predictive accuracy. Would a GAM model be ok, for what it concerns causal inference?


What will happen if a corner flag blocks the football rolling out of bounds?

Question: What happens when the ball rebounds off the corner flag? Does it count as out of bounds? Or does the match just continue?
Comment: There is an example of it happening here, with the match continuing: https://www.youtube.com/watch?v=jszMeoVWwtE
Answer: Play continues as usual. Ball doesnt count as going out of bounds until it actually goes out of bounds.
FIFA Laws of the game 2015/16, page 34 (emphasis my own):

Ball out of play
The ball is out of play when:

it has wholly crossed the goal line or touch line whether on the ground or in the air
play has been stopped by the referee

Ball in play
The ball is in play at all other times, including when:

it rebounds off a goalpost, crossbar or corner flagpost and remains in the field of play
it rebounds off either the referee or an assistant referee when they are on the field of play


Avoiding the use of htmlspecialchars() on  on dynamic contents, while avoiding XSS attacks

Question: I need your help with a really simple issue. Article Contents of some pages on my website are stored in MySQL database, and I've applied  htmlspecialchars() to it when outputting to the browser, but actually there are legitimate  , which are rendered as plain text, meanwhile they are supposed to be  valid images part of the article content.
How can I successfully display the image and at the same time  avoid a possible XSS attack and the likes.
Thanks
Answer: The common way is to NOT use HTML for this, but your own formatting language like bbcode or Markdown. That way you can easily transform that formatting into HTML and at the same time avoid letting the users input whatever HTML they want.
Answer: Parse the HTML according to the HTML standard and discard any elements/attributes/attribute values you don't want to keep. Check the src value of every img element to see if it's a valid URL, and if it is, check to see if it actually exists and is a valid image. If not, discard the element.
If you use a proprietary formatting language (e.g. BBCode or Markdown), you should still perform the checks against the value provided for each img element (many of the libraries that parse BBCode, Markdown, etc will perform these checks for you).
Answer: Use HTMLPurifier - it will remove any scripts, including javascript placed in tag attributes, while preserving (and also well-forming) the HTML code


Syncing messages on frontend with missed messages in order

Question: I have a chat component where people can send messages to each other. Everything works as expected if both users have the app active (foregrounded, backgrounded, doesn't matter). Each target user would receive a message from a source user over the socket connection.
I have a use case, where if a target user is offline, then a sent message from the source user would get queued, and upon reconnection with the server, the target user would receive all queued events, one of them being "UNRECEIVED_MESSAGE", with a payload of the message itself. There are also other events that could be queued, such as "MESSAGE_DELETED" or "BLOCKED_BY_TARGET_USER".
I've noticed, that I can easily run into an issue if a source user sends multiple messages to the, currently, offline target user. So when the target user returns online and reconnects, an "on connect" handler on my backend would query for all missed queued actions for the target user's user ID and in a loop iterate over them and send them out.
So the problem I have is that there is no guarantee that each unreceived message would reach the just-reconnected target user in the order that they were originally sent.
All received and sent messages are also stored locally in a SQLLite database, not just the application's state. Which means that once a user receives a message,

they parse it,
process it, and
save it asynchronously in the database

I would like to ensure that messages are stored in the correct order that they were sent out. There is no issue with the initial local SQLLite query to populate the app's state with messages, if there are any, as I order by id when selecting for them.
Each message has an id and created_at, amongst other fields. My approach would be to add each message into the state, and then sort that array based on each element's id. So for each "UNRECEIVED_MESSAGE" event, I would emit the payload over the socket:
// backend
const queuedActions = [. . .];
queuedActions.forEach(({ action_name, action_payload }) => {
  socket.emit(action_name, action_payload);
})

And then on the client:
// frontend
socket.on(. . .);

socket.on('UNRECEIVED_MESSAGE', async (payload) => {
  await storeLocalChatMessageInDb(payload.message);

  const isInSameChat = getState().currentChatId === payload.message.chat_id;

  if (isInSameChat) {
    const messages = getState().messages.slice(0).concat(payload.message); // retrieve messages in state and clone them (because state is immutable)

    messages.sort((a, b) => b.id - a.id);

    setState('messages', messages); // set them back to state
  }
});

socket.on(. . .);

Clearly my issue with the approach above is that for each unreceived message event coming in, (which could be in the hundreds, hypothetically), I get ALL messages, clone them, sort them and then set them back to state.
Another approach that I can think of is plucking all the "UNRECEIVED_MESSAGES" events from all queued actions on the backend, sort them there, and then invoke only one "UNRECEIVED_MESSAGES" event, with the sorted array of new messages as the payload. This way, the client wouldn't have to do anything, other than just intercept the socket event and just store the payload into the state.
Is there a better way of doing this or are these my only options?
Comment: SQL doesn't have an order, you'd want to `ORDER BY created_at` in every query anyway. So what's the problem?
Comment: I prefer to order by `id` to avoid problems with dates. And it's perfect for my use case anyway, because the larger the id, the newer the message. Anyway, I specified the problem toward the bottom of the question. I also specify: `[...]if there are any, as I order by id when selecting for them.`
Comment: I'm not quite sure what `getState()` and `setState()` are doing. I was referring to "*I would like to ensure that messages are stored in the correct order that they were sent out.*" and telling you that you do not need to worry, as (relational) databases do not store anything in an "order". They just store the set of messages, and when you insert the received messages it does not matter in which order they come.
Comment: Correct, but when I initially populate the state with locally-stored messages, I do something like `select * from chat_message order by id DESC`. And AFTER that, I received "unreceived" messages via `"UNRECEIVED_MESSAGE"`. As for the `getState` and `setState` methods, these are arbitrary. I'm using `effector`, but these could also be `Redux` methods. They're arbitrary because only their lexical naming matters within the context of my current question (retrieve state and set state).
Comment: I should add that my client is using SQLLite (android/iOS) and my backend uses Postgres. Postgres holds the queued actions, SQLLite is responsible for storing messages locally (so as to not always show an empty white screen with a loader, when opening up a specific chat and retrieving all messages with a limit). Kind of like what Telegram or WhatsApp does. They store data locally and then fetch new data afterwards
Comment: Oh so you mean that when you receive the messages, you do **not** "*save it asynchronously in the database*" but actually you do want to add them to the in-memory state array?
Comment: I've update the OP, I understand where the confusion arose fom. The received "unreceived" messages get stored locally always -- the in-memory state gets updated only if an incoming message belongs to the currently opened chat (if there is one).
Answer: Handling out-of-order messages, especially when dealing with offline scenarios, can be challenging. The two approaches you've outlined are reasonable. Sorting on the backend is a good practice and reduces the workload on frontend.
One suggestion I would give is that you can use a priority queue (min-heap) to keep the messages in order based on their created_at timestamps. When a new message arrives, insert it into the priority queue. This way, you maintain the order without sorting the entire array. When extracting messages, you get the next message based on the priority. This way, you avoid sorting the entire array on each message but maintain the correct order.
Comment: Right, but if a target user has 1000 unreceived messages coming in, then, in your solution with the priority queue, I would emit 1000 times to the target user, each iteration awaiting on a "confirmation" callback from the currently-emitted message. That doesn't seem maintainable, unless I'm missing something from your approach?
Comment: In such scenarios, you might want to batch the messages on the server side and send them as a single payload. This can help reduce the number of socket events and potentially improve performance. With this approach, you still sort the messages on the backend before emitting them, but you send them as a batch to reduce the number of emitted events.
Comment: But then I don't need a priority queue, if I'll be sorting on the backend, correct? Just batched queries with a limit and current offset, then sort on the backend before emitting the messages out.
Comment: Absolutely, you're correct. If you're sorting the messages on the backend before emitting them and sending them as a batch, you don't  need a priority queue.
Comment: Yeah, I just ended up using this approach
Comment: Great work brother.


Android multiple firebase projects using firebase-crashlytics

Question: Is it possible on android to programmatically initialize firebase-crashlytics SDK so it would not use the data in google-services.json ?
I am asking this because we use two firebase projects and currently google-services.json is of the project we use for Push notifications and AdMob integration, and I cannot replace it with google-services.json of the second project we have set up for crashlytics.
I have already tried using FirebaseOptions from my Application onCreate as follows:
<code> FirebaseOptions options = new FirebaseOptions.Builder()
                .setApplicationId("firebase_crashlytics_application_id")
                .setApiKey("firebase_crashlytics_api_key")
                .setProjectId("firebase_crashlytics_project_id")
                .build();
 FirebaseApp.initializeApp(this, options, "crashlytics");
</code>
So far no luck - firebase crashlytics is not properly initialized.
Comment: Related https://stackoverflow.com/q/62253691/1916449 https://stackoverflow.com/q/64373296/1916449 https://stackoverflow.com/q/53831792/1916449
Answer: I got an official answer from google support - we cannot programmatically initialize firebase crashlytics. I.e. it requires having the google services file related to the project you want to see the craslytics data for.
Therefore we would have to use a single firebase project somehow for all firebase services including admob and push.
Answer: Great question. You can set this up by following these steps.
Comment: sadly this did not help. as the data in the link implies you can configure multiple google services per flavour (which is not what I need) or you can programmatically  set additional project as I already tried - but this does not work crashlytics


Modal chord progression and tritone substitution

Question: Is is possible to use tritone substitution in modal chord progression?
For example I have a simple I-IV-V-I chord prog, in C mixolidian:
C-F-Gm-C.
Can I substitute the Gm with Db7? And if yes the functionality will remain the same?

I've read somewhere (i cant remember where) this work a little bit different. In this case I want to substitute the dominant chord, so according that I have to calculate the dominant chord's replacement chord in the major scale which is F major. In F major the dominant note is the C and its tritone is Gb. So It would be C-F-Gb7-C.
It seems wrong to me.
Thanks in advance.
Answer: The functionality will remain the same, as ♭II7 can be resolved to I the same way your Gm chord would be. However, you will lose the modality of the progression, because ♭II7 doesn't imply that mixolydian sound you have going when using the Gm. Also, Tim pointed out that the Gm might want to resolve to C7, then to F, but I think that that would depend on how you're using it, as it's certainly possoble to go from Gm to C without going to F.
Comment: So you say its possible to use a Db7 ( or most likely a Dbmaj75b ) instead of a Gm, but it will lack of the mixolydian sound?
Comment: Yes, because IV-♭II7-I is not diatonic to the mixolydian mode.
Answer:
...I-IV-V-I chord prog, in C mixolidian: C-F-Gm-C...

You're mixing up symbols and tonalities.
If C mixolydian, then the V - the triad on the dominant/^5 scale degree is a minor chord, so lower case v.

        C-F--Gm-C
C mixo: I-IV-v--I

If we speak properly of a dominant chord then the chord must have a leading tone the ^7 scale degree one half-step below the tonic.
Mixolydian mode doesn't have a leading tone, therefore it doesn't have a dominant. Strictly speaking then you don't have a dominant to substitute.
Side note: to me modal generally implies music without a real dominant chord. Ionian mode of course it just the major mode so that more or less excludes Ionian from the general sense of "modal" harmony. Except for the Lydian mode all the other modes do not have leading tones and so they don't have dominant chords. From that perspective tritone substitution may be foreign to modal harmony.
Back to your chords.
If you change your harmony to use a real dominant you will be in C major, you would get...

   C-F--G7-C
C: I-IV-V7-I

With labels

   C-F--Db7--C
C: I-IV-bII7-I

I suppose you could have that G7-C change and still have the music sound like it was Mixolydian, but it would depend on exactly how you handled G7-C. It would need to sound like a temporary tonal shift. It would help if the melody somehow clearly sounded Mixolydian. Perhaps by avoiding the raised ^7 degree. You would have to handle the harmony somehow to make Mixolydian the clear tonality and the bII7-I substitution seem temporary. You would probably need the minor v in the progression to make Mixolydian clear. You would have to play with that Mixolydian/major and B♮/Bb relationship.
Finally, the other way to look at this is to say your progression isn't really in C Mixolydian, but rather in F major. In that case you have to re-label your chords...

   C-F-Gm-C
F: V-I-ii-V

We have a proper dominant now, but it's in a different position in the order of the chords. The substitution might be like...

   Gb7--F-Gm-Gb7
F: bII7-I-ii-bII7

Back to part of your question...

...In F major the dominant note is the C and its tritone is Gb. So It
  would be C-F-Gb7-C. It seems wrong to me...

You were correct. The only problem is you substituted the wrong chord! You substituted the ii instead of the V chord.
So, make sure you identify a real dominant chord then make the tritone substitution.
Answer: Michael Curtis astutely points out that C mixolydian doesn't have a proper V7 chord, because the fifth degree chord is Gmin7, not G7. Hence, including either G7 or D♭7 in your progression will represent a deviation from the modal sound you seek.
However, that doesn't mean the song won't still sound modal. Many jazz standards that are considered modal archetypes deviate from strict/exclusive use of the given mode(s). An example is Footprints by Wayne Shorter. The song is in C Dorian minor, but the final turnaround is back-to-back ii-V's, one of which contains a tritone substitution: | F#minb5 | F7♯11 | E7b5 | A7♯9♭5 | Cmin |. In spite of this, the song is hailed as an iconic modal tune and often appears in lists of exemplary modal jazz songs.
So what makes a song "modal"? There isn't a single answer, but most people say that "modal" songs are built from a mode rather than a traditional chord progression and conventional harmonic resolutions. So if you're using lots of traditional harmonies (such as V7-I's or ii-V7's), then the song will sound less and less modal. Even if you are composing in a mode that contains a proper V7 chord, you still wouldn't want to use that V7 chord according to its traditional harmonic function.
So why does Footprints count as modal, despite the ii-V's in the final turnaround? There's a great answer to this question. The ii-V's break from traditional harmony in a crucial way: they end with A7♯9♭5, which then resolves to Cmin. But A7♯9♭5 to Cmin isn't really explained by traditional harmony. A much better explanation is that A7♯9♭5 is one note away from C dorian. (A7♯9♭5 contains C♯ instead of D.) So while the ii-V's appear, they are part of a resolution that is best explained through modes.
Answer: Tritone substitution relies on the juxtaposition of the 3rd and b7 of two chords. So, in key C, the dominant G7 will have Db7 as its tts. G7 is G B D F, whereas Db7 is Db F Ab Cb. So, the F changes place (3rd>7th), and the same sounding B/Cb goes the other way.
With your suggestion, there's only one common note between Gm and Db7. That's the F. So it's not really a tts.
If anything, to me, that Gm>C sounds like it's heralding a C7 to move onto subdominant F, and the 'tts' version throws a spanner in the works, so to speak!
Whilst you're correct in saying the scale is F, the sequence is not in F, although it is using the same pool of notes. In C Mixolydian, the home or root is C, that's the point. At the end of the day, anything is possible - there are no hard and fast rues saying 'thou shalt/ shalt not...' If you think it sounds good, keep it. If not, it was worth a try, but not this time thanks.
But, bottom line is, as said earlier, tts needs those two notes common. That's what makes it tts.
Comment: "There's only one common note between Gm and Db7"
What about if I dont  use the Db7 instead I write Bb75b? With the 5b I lowered the Ab into G and woala I have two matching notes ^^
And the Db F G B -> C E G Bb transition seems fine to me.
It sounds decent at least.
Comment: By Bb75b, do you mean Db75b (I prefer Db7b5 myself)?
Comment: Oh...I missed, yes! I wanted to write Db75b not Bb75b.
Answer: Yes, Db7 acts as a dominant of C.  We call it a 'tritone substitution' partly because its root is a tritone from the 'real' dominant - G, but mostly because it shares the tritone interval - F and B (Cb) - with the G7 chord.
But you want to be Mixolidian.  That's fine, but Mixolydian doesn't have a dominant 7th chord containing a tritone.  It doesn't even have a leading note a semitone below the tonic.  It's questionable whether the term 'dominant' is applicable to the chord built on the 5th degree of the Mixolydian scale.  If you're committed to Mixolydian, you need a different set of tricks to the sort of functional harmony that is all about dominant-tonic relationships.
When discussing harmony, people sometimes get hung up on the bVII chord (that's Bb major in the key of C).   We notice that it sounds just fine to get home to C by Bb, F, C  or even just Bb, C but agonize because it isn't diatonic.    Well, in C Mixolydian, G7 or Db7 aren't 'diatonic'.  You can use them, of course.  But you'll lose the Mixolydian flavour.  And I think we're still in a musical world where tonal can contain Mixolydian, but Mixolydian needs to maintain its identity.
Comment: I agree with this. Composing/improvising "modally" is meant to be a contrast to composing/improvising "tonally." Once you start borrowing notes and chords, you have left the modal world and entered the tonal world.
Comment: Sadly I miss wrote the Db chord, I wanted to write Dbmaj7 but in meantime i found out Dbmaj75b would be the key to a smooth transition. But you say its not mixolydian anymore, right?


Major scale box patterns

Question: I have mapped out the complete A Major scale

and the A Major pentatonic scale

I'm having an issue to understand the box scales, and almost all info relates to the C Major scale. I'm not sure if the box shapes stays the same, move up or move down from C Major to A Major.
Any clarity on this will be appreciated. If possible, where does my boxes lay on my images provided
Comment: Just a first comment before I might write up an answer: your A major pentatonic scale is not what most people would think it should be. The common A major pentatonic scale is: A-B-C#-E-F# (which are the same notes as the F# minor pentatonic scale). Your pentatonic scale is indeed a subset of the A major scale and has five notes, but it contains all the semi-tones of the major scale, which are commonly avoided in the pentatonic scales most commonly used.
Comment: I don't quite understand what your actual question is, but it seems to be about the relationship between the shapes of the C major scale and the A major scale on guitar. If we pick a "home position" of the lowest available A (or C) on the low E string, then the C major scale has a "home position" of the eighth fret, and for A, the fifth fret. So any C shape you know can be moved down five frets for A, and vice versa for A to C. Does that help?
Comment: @ToddWilcox from the previous comments, the issue came down to the wrong pentatonic scale formula which stuffed up my whole scale. Everything is sorted now
Answer: The issue here came down to a wrong formula I got for the pentatonic scale from an internet source. The formula I used was 1,3,4,5,7 which caused all the confusion for me.
@Matt L. helped me to the correct formula which is 1,2,3,5,6 and after correcting my scale, the box shapes are quite evident now.
Here is my corrected pentatonic scale for A Major
Comment: Yes, that's it. By the way, the formula 1,3,4,5,7 comes from the *minor* pentatonic scale. If you look at the notes starting from F# then you get exactly that formula. But for the major pentatonic scale it is indeed 1,2,3,5,6.
Comment: Indeed, it is the minor pent. A lot of guitarists use it rather than the major pent, and just call it 'pentatonic'.
Comment: @Matt L. I think that I might have misread something :-). I think I confused myself somewhere. Your comment proved to be very valuable. You can post that as an answer and I will accept it and then just keep mine as extra info or something
Comment: I think you've perfectly answered your own question, and there's not much to be added to it. You might as well just accept your own answer. You gave credit to me anyhow, so that would be OK with me.
Comment: Ok great, I will accept my answer then as soon as the restriction is lifted, hate this 2 day restriction :-). Once again, many thanks for your help @MattL.

Major scale box patterns


Is it possible to solve an equation look like this?

Question: $$
\int_{-\infty}^{\infty} f(x+t) \cdot g(t)dt=f(x), \forall x \in \mathbb{R}
$$
Any necessary regularity conditions can be assumed to hold.
I was wondering if there exists a generic method to solve an equation like this.
Comment: Do you intend to "solve for $f$", given that this equation holds for _many_ $g$'s? For example, all compactly-supported continuous $g$'s?
Comment: If $h(x)=f(-x)$ this becomes $$h(x)=\int h(x-t)g(t)\,dt=(h*g)(x).$$ where $*$ is the convolution.
Comment: If $g(t)$ is a probability distribution function for random variable $Y,$ then it means finding an $f$ such that $E(f(x+Y))=f(x).$ If $g(x)=g(-x)$ then this equality is true for any linear $f(x)=ax+b.$
Answer: Despite the ambiguities of the question, there are some possibly-interesting things that can be said.
First, with or without the change of variables (as @ThomasAndrews points out) to rewrite the equation as a convolution equation $h*g=g$, we can certainly view the left-hand side as an integral operator $T=T_g$ (using auxiliary function $g$) applied to $f$, and the equation requires that $f$ be an eigenvector for $T_g$, with eigenvalue $\lambda=1$.
If $T_gf=\lambda_g\cdot f$ is required for every $g$ in a sufficiently large class of functions (for example, compactly-supported and smooth, that is, test functions), the condition is (provably) equivalent to requiring that $f$ be an eigenfunction for translations, and the associated differential equation is $f'=c\cdot f$. So $f(x)=e^{cx}$ for some constant $c$.
None of these functions is in $L^2$, etc. But the eigenvalues are easy to determine:
$$\int e^{c(x+t)}\,g(t)\;dt \;=\; \Big(\int e^{ct}\,g(t)\;dt\Big)\cdot e^{cx}
$$
Second, with the rewrite to have a convolution equation $f*g=\lambda\cdot f$, if we assume that $f,g$ have Fourier transforms (in various possible senses), then $\widehat{f}\cdot \widehat{g}=\lambda\cdot \widehat{f}$. That is, (assuming both Fourier transforms have pointwise senses), $\widehat{g}(x)=\lambda$ on the support of $\widehat{f}$, is a necessary and sufficient condition.
For this to be possible for a wide range of $g$, it is necessary that the support of $\widehat{f}$ not be the whole line. If $f$ itself was compactly supported (and continuous, for example), then $\widehat{f}$ extends to an entire function, so cannot vanish on any set of positive measure. In that case, $\widehat{g}(x)=\lambda$, and $g$ was $\lambda\cdot \delta$ with Dirac $\delta$.
... and the equation holds for all continuous $f$, for $g=\lambda\cdot\delta$.
EDIT: as in @user3716267's comment/question, it may not be sooo common to understand precisely how being an eigenfunction under translation leads to the differential equation. Yes, we know (by the Mean Value Theorem) that translation invariance of $f$ gives $f$ constant, so $f'=0 = 0\cdot f$.
In fact, $f(x+y)=\lambda_y\cdot f(x)$ for all $x,y$ implies that
$$
{\partial\over\partial y}\Big|_{y=0} f(x+y) \;=\; {\partial\over \partial y}\Big|_{y=0}(\lambda_y)\cdot f(x)
$$
from which $f'(x)={\partial\over \partial y}\Big|_{y=0}(\lambda_y)\cdot f(x)$. Yes, some (of various possible) hypotheses are necessary to make this argument rigorous. A variant of it does just reduce to the Mean Value Theorem version for $f$ translation-invariant, by considering $f(x)e^{-\lambda x}$... But this heuristic is perhaps clearer as a suggestion of what is true.
Comment: It's clear that exponentials are eigenfunctions of translation, but (to me at least) it is not immediately obvious how the differential equation follows from the fact $f$ is an eigenfunction under translation.
Comment: Many thanks! This is a super simplified version of one equation that I am currently working on, and I apologize for its ambiguity. I will try the things you mentioned. Thanks again!
Comment: @cxxu96, good. I do find that quite often the real underlying question is about the ambiguity, after all! :)


python regex match a possible word

Question: I want to match a regex to match a word that might not exist. I read here that I should try something like this:
import re

line = "a little boy went to the small garden and ate an apple"

res = re.findall("a (little|big) (boy|girl) went to the (?=.*\bsmall\b) garden and ate a(n?)",line)

print res

but the output of this is
[]

which is also the output if I set line to be

a little boy went to the garden and ate an apple

How do I allow for a possible word to exist or not exist in my text and catch it if it exist?
Comment: The question mark quantifier `?` matches zero or one of a given pattern.  the regex `to the (small )?garden` matches both `"to the garden"` and `"to the small garden"` [DEMO](https://regex101.com/r/RDfCYm/1)
Comment: `re.findall(r"a (little|big) (boy|girl) went to the( \bsmall\b){0,1} garden and ate a(n?)", line)` Note the `r` in front of the string.  Without the `r` the backslashes are interpreted.  `'\b'` is the backspace character.  `r'\b'` is a backslash followed by a "b".
Comment: Actually, the `(?=.*\bsmall\b)` lookahead requires the whole word `small` to be present somewhere after the current location, after 0+ chars other than line break symbols. So, it does not have to be `garden`. Still, there must be a consuming pattern, Steven is right. Anyway, the pattern with `\b` must be declared with a raw string literal, or the backslash must be doubled.
Comment: @WiktorStribiżew:  You are correct.  I missed the `.*`.
Comment: I changed `'the (?=.*\bsmall\b) garden'` to `r'the( \bsmall\b){0,1} garden'`.  Note that your `?=` indicates that the pattern in parenthesis is a lookahead assertion.  Such a pattern does not consume the string when it matches.  That means that `"garden"` will have to be the word after `"the"`.  Instead I changed it to match zero or one times and included a preceding space in the match.
Comment: @StevenRumbalski: You may post an answer.
Answer: First, you need to match not only a "small" word, but also a space after that (or before that). So you could use regex like this: (small )?.
On the other hand you want to catch the word only. To exclude the match from capturing you should use regex like this: (?:(small) )?
Full example:
import re

lines = [
    'a little boy went to the small garden and ate an apple',
    'a little boy went to the garden and ate an apple'
]

for line in lines:
    res = re.findall(r'a (little|big) (boy|girl) went to the (?:(small) )?garden and ate a(n?)', line)
    print res

Output:
[('little', 'boy', 'small', 'n')]
[('little', 'boy', '', 'n')]

Comment: Awesome, thanks!

A question: why wouldn't this pattern work ```r'a (little|big) (boy|girl) went to the(?:(small) )?garden and ate a(n?)' ```
Comment: Thanks :) It doesn't work because with this regex you are trying to catch lines like these: `['a little boy went to thesmall garden and ate an apple', 'a little boy went to thegarden and ate an apple']`.
So you miss a space after 'the'.

python regex match a possible word


Como procurar um elemento com o querySelector filtrando pelo innerText?

Question: Gostaria de saber como posso através do querySelector (ou de qualquer outra função) obter um ou mais elementos (
, , <button>, ...), filtrando através do conteúdo do innerText.
No documento abaixo por exemplo, eu quero obter qualquer tipo de elemento que possua no innerText a string "bola". Como eu poderia fazer isso usando JavaScript?

/*
A função abaixo é um exemplo que deve retornar os seguintes elementos:

 - Linha 1
 - Linha 3

 - Linha 7

 - Linha 10
 - Linha 14
*/

const results = getElementsByInnerText("bola");

bola

    bola
    carro

bola

casa

bola

avião

bola
Comment: Isso aqui te ajuda? [Get Elements By InnerText](https://stackoverflow.com/questions/3813294/how-to-get-element-by-innertext)
Answer: É possível selecionar todos os elementos e depois filtrar eles pelo valor do atributo innerText. Confira-se a seguinte função:
const queryByInnerText = (text) => {
    return [...document.body.querySelectorAll('*')].filter(e => e.innerText === text);
}

Answer: Como @JassRiver disse, mas fiz um exemplo para você.
Positive o comentário dele caso ajudou!

const

aTag = document.getElementById("id-elemento"),

searchText = "bola",

found = [];

for (let i = 0; i < aTag.length; i++) {

  if (aTag[i].textContent == searchText)

    found.push(aTag[i]);

}

console.log (found)
<select id="id-elemento" name="existingList">
  <option value="1">bola</option>
  <option value="2">pedra</option>
  <option value="3">bola</option>
</select>

Obs: se quiser que explique cada linha me fala no comentário que edito.
Answer: Isso provavelmente não é uma boa ideia...
Se, no futuro, for determinado que é melhor pro negócio usar a palavra "esfera" no lugar de "bola", e, portanto, deve ser trocado os termos nas aplicações, o próximo desenvolvedor, ou você mesmo, achará estranho que uma troca simples de um texto faça que determinada funcionaldidade deixe de funcionar. Alterações em outros pontos que adicione "bola" ao conteúdo ou textos dinâmicos poderiam causar bugs e precisariam ser tratados adequadamente (o que, geralmente, não vale a pena)
Além disso, não existe uma API nativa para fazer o que deseja, e qualquer solução criada involve a busca em todos os elementos do DOM e depois filtrar, o que pode ser custoso, dependendo da situação
A solução ideal seria alterar o elemento, adicionando uma classe ou atributo pra ser utilizado como filtro:

bola

bola

Mas, se for analisado, e a melhor solução for realmente fazer uma busca pelo conteúdo do elemento, segue uma solução que tende a ser um pouco melhor que buscar em tudo:

((window) => {
  window.Element.prototype.getElementsByContent = function(search) {
    console.log('searching in', this);
    if (this.children.length === 0)
      return this.innerText === search ? [this] : [];

    let elements = [];

    for (const child of this.children)
      if (child.innerHTML.indexOf(search) !== -1)
        elements = elements.concat(child.getElementsByContent(search))
      else
        console.log('skip searching in', child);

    return elements;
  };
})(this);

console.log(document.body.getElementsByContent('bola'));

bola

    bola
    carro

barco

casa

bola

avião

bola

Nessa solução, não é simplesmente procurado em tudo, é feito uma verificação simples se o elemento DOM tem, em qualquer lugar, o texto procurado, o que permite pular certos blocos, como em
, já que não possui, pula todos os elementos abaixo dele. Nesse exemplo, não faz muita diferença, pois é pequeno e poucos elementos são pulados, porém, em situações reais pode deixar de fazer a busca desnecessária em dezenas de elementos
Outra observação importante, a busca é feita através do elemento base, no exemplo, document.body, se você tem controle de onde os elementos estão, pode usar um elemento mais a baixo e restringir melhor a busca, se a fizer a partir de document.getElementById('something0'), não será verificado o primeiro e último elemento (h1 e span)
Mas essa é uma solução simples, se o texto de busca for na verdade uma classe ou id ou parte dele, por exemplo,

 a verificação se contém a string "bola" retornará verdadeiro, porém o "bola" encontrado é de "bolacha" além de ser uma classe e não o contúdo do elemento


Template wordpress OnePage mas também paginado

Question: Estou desenvolvendo um template wordpress, e ele tem a seguinte dinâmica, é um site one page, ou seja ancorado. No menu chamo as paginas que são ancoradas do one page, mas no menu eu também chamo paginas que são paginadas, essas eu programei para serem criadas no wordpress, através do page.php.
O problema esta sendo seguinte, quando eu abro site, na parte inicial, eu consigo fazer que os itens do menu que levam para as paginas ancoradas funcionem normalmente.
Ex: Eu clico em Contato no Menu, a página desce lentamente até a parte do One Page onde está o Contato. Isso esta funcionando perfeitamente quando eu abro o site inicialmente.
Quando eu clico em serviços, o site vai para a pagina serviços (saindo do One Page). Até ae tudo bem, mas quando eu clico em Contato novamente para voltar pra a página One Page e ir até Contatos, ae ele não consegue voltar, é como se agora ele tentasse fazer o One page Na página Serviços.
O menu eu programei também, para ser criado no Wordpress.
Preciso fazer isso, um site OnePage mas também, um site paginado. Sem ter problemas de ir e voltar das paginas para as ancoras.
Comment: Já tentou algo como "urlIndex#onepage" no link *(desta forma o html sabe que tem 1 ir para a página urlindex e para  ancora onepage?
Comment: Então, o meu Menu esta da seguinte forma. Eu programei ele para ser feito no wordpress. Eu fiz os meus itens do menu como por exemplo:   Serviços (Chama a página criada no wordpress), e tem Contato (Essa eu criei um link personalizado que está "#contato", que funciona só quando esta na onepage, na "index.php").
Comment: Então se colocar o link de contato como "index.php#contato" não funciona ?
Comment: tenta usar o `site_url("#ancora")`no menu, onde precisa ser ancora e `site_url("nome_da_pagina")` onde é página
Comment: Mas eu devo colocar isso na URL do link personalizado do wordpress??
Já tentei colocar index.php#contato mas não deu certo @Bartolomeu
Answer: Consegui resolver o problema instalando um plugin.

Page Links To, esse plugin me da a opção de alterar a URL das minhas paginas e posts. Assim eu crio as páginas, e através da URL eu defino se elas serão parte do OnePage ancoradas ou se são paginadas.

Concluo chamando as páginas criadas normalmente no Menu Wordpress.


Prime Factorization

Question: Let $n\ge0$. What is the power of $2$ in the prime factorization of $(2^n)!\,$? Prove that the value is correct.
So far I've conjectured the value to be $2^n - 1$. This is true for $n=0,1,2,3,4$. Then I decided to use induction to prove the statement.
Base case: $(2\cdot0)!=1\cdot2^0=2^0-1$
IH: Assume for some $(2^n)!$, the power of $2$ in the prime factorization is $2^n-1$.
IC: Then it must be true for $(2^{n+1})!=(2\cdot2^n)!$
Am I using the wrong method?
Can anyone provide a proof?
Comment: Your conjectured formula is incorrect. For $n=3$ your formula gives the value $7$. In fact $6! = 720 = 16*45$. Therefore the correct result is $4$.
Comment: Sorry that was a typo. I meant 2^n.
Comment: I have a feeling the direct proof is the same as the inductive proof.
Answer: Hint:
Just count the 2s.
$(2^5)!=32!=32\times31\times\cdots\times2\times1$
Half of these are divisible by 2.
One fourth are divisible by 4 (so have one more factor of 2 than those divisible only by 4).
One eighth are divisible by 8 (so have one more factor of 2 than those divisible only by 2 and 4).
Answer: In general, the exponent of a prime $p$ in the decomposition of $m!$
is $v_m(p)=\lfloor\frac{m}{p}\rfloor +\lfloor\frac{m}{p^2}\rfloor+\lfloor\frac{m}{p^3}\rfloor+\cdots$
For the case $m=2^n$ and $p=2$ we have  $$v_{2^n}(2)=\lfloor\frac{2^n}{2}\rfloor+\lfloor\frac{2^n}{2^2}\rfloor+\cdots=2^{n-1}+2^{n-2}+\cdots +1=2^n-1$$
Your conjecture is correct.
Comment: Would you be able to prove the statement then? I'm unable to complete the proof as-is
Comment: prove which statement?the last step with summation or the situation with the exponent?http://www.cut-the-knot.org/blue/LegendresTheorem.shtml
Comment: The situation with the exponent (2^(n+1)  -  1)

Prime Factorization


Issue: ng-repeat with specific view should be displayed on click

Question: I have a scenario where there are tabs and when a user clicks on the tabs then only that tab should have stars not every tab
Here is my html code:

Topics

{{topics}}

            <uib-rating ng-model="rate" ng-if="displayStars" max="max" read-only="isReadonly" on-hover="hoveringOver(value)" on-leave="overStar = null" titles="['one','two','three']" aria-labelledby="default-rating"></uib-rating>

I have a controler code as below:
$scope.fngetQList = function(topics, index) {
        debugger;
        $scope.displayQList = true;
        $scope.displayStars = true;
        $scope.sTopics = topics;
        $scope.index = index;
        getCandidateInterviewListService.fnGetQList(topics).then(function(response) {
            $scope.aQuestionList = response;
            console.log($scope.aQuestionList);
        });
    };

Here topics is an array like ["html","css","angular"]
The problem im facing here is when i click one tab i am getting stars for all the tabs where i need stars for only the clicked tab
Any help would be appreciated.
Comment: please share your fiddle or plnkr link
Answer: All the tabs are getting stars because you have used the same scope variable displayStars in ng-repeat. Similarly, you will have the rate of all the topics to be the same because of the same scope variable rate.
Instead use an array for each of them as follows (Note that you need to know the length of the array oJdDetails.topics. So make sure your initialisations are correct.),
HTML code:

Topics

{{topics}}

            <uib-rating ng-model="rate[$index]" ng-if="displayStars[$index]" max="max" read-only="isReadonly" on-hover="hoveringOver(value)" on-leave="overStar = null" titles="['one','two','three']" aria-labelledby="default-rating"></uib-rating>

Controller code:
// you need to know the `length` of `oJdDetails.topics`
$scope.rates = new Arryay(oJdDetails.topics.length).fill(0); // initialisation of array with `0` value
$scope.displayStars = new Arryay(oJdDetails.topics.length).fill(false);; // initialisation of array with `false` value
$scope.fngetQList = function (topics, index) {
    $scope.displayQList = true;
    $scope.displayStars[index] = true;
    $scope.sTopics = topics;
    $scope.index = index;
    getCandidateInterviewListService.fnGetQList(topics).then(function(response) {
        $scope.aQuestionList = response;
        console.log($scope.aQuestionList);
    });
};

Hope this solves the issue.


WCF Service Web Service Concurrency.Single

Question: I have a WCF Service that I want to process one request from all clients at a time.  I want Client A's request to be processed and Client B to wait until Client A is finished before the service even attempts to look at it.  I thought the following code below accomplished this.
[ServiceContract]
public interface IRestServiceImpl
{...}

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)]
public class RestServiceImpl : IRestServiceImpl
{...}

How do I allow only a single client to be processed at one time and force others to wait in queue?
Answer: You need to control the number of instances of your service as well as the concurrency mode.  By default, your service will be configured as InstanceContextMode.PerSession.  This means that all of Client A's requests will be handled sequentially and so will Client B's, but they will not be handled sequentially in regards to each other as they are not using the same instance of the service.
Try modifying your ServiceBehavior as follows:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single,
                 InstanceContextMode=InstanceContextMode.Single)]
public class RestServiceImpl : IRestServiceImpl
{...}

For more information on the topic, check out the MSDN documentation on Sessions, Instancing and Concurrency.
Comment: I had stumbled onto these settings soon after posting the question and have been testing them.  Looks like they are holding up in my situation the way I need them to.  Thanks for your answer as well.


I can't figure out why I'm getting a Cannot add foreign key constraint error

Question: I'm working on a schema for a project and I'm trying to import it to my local host so I can work on writing some queries that will pull info from the database onto a webpage. I'm getting a #1215 - Cannot add foreign key constraint error, and it pertains to the use of cities(city_id) as a foreign key. I'm not sure what the problem is, they're both the same data type (INT) and city_id is the primary key of the cities table. I'm stumped here guys and I'm hoping somebody on here can lend a hand.
EDITED: So I got this working, but that's without the order table which I'll paste below the working schema.
DROP TABLE IF EXISTS cities;
-- Table for storing cities
create table cities (
    city_id INT(100) NOT NULL AUTO_INCREMENT,
    city_name VARCHAR(32),
    PRIMARY KEY(city_id)
)ENGINE=InnoDB;

DROP TABLE IF EXISTS drivers;
-- table for Drivers registered in lyft database
create table drivers (
    driver_id INT(100) NOT NULL AUTO_INCREMENT,
    fname VARCHAR(32),
    lname VARCHAR(32),
    address VARCHAR(32),
    contactnumber VARCHAR(32),
    driver_city INT(100),
    PRIMARY KEY(driver_id),
    FOREIGN KEY (driver_city) REFERENCES cities(city_id)
)ENGINE=InnoDB;

DROP TABLE IF EXISTS cars;
-- Table for storing cars information in lyft
create table cars (
    car_id INT(100) NOT NULL AUTO_INCREMENT,
    car_name VARCHAR(32),
    car_type VARCHAR(32),
    car_model VARCHAR(32),
    car_licencenumber VARCHAR(32),
    PRIMARY KEY(car_id)
)ENGINE=InnoDB;

DROP TABLE IF EXISTS customers;
-- Table for storing customers using lyft
create table customers (
    c_id INT(100) NOT NULL AUTO_INCREMENT,
    c_fname VARCHAR(32),
    c_lname VARCHAR(32),
    c_city INT(100),
    PRIMARY KEY (c_id),
    FOREIGN KEY (c_city) REFERENCES cities(city_id)
)ENGINE=InnoDB;

DROP TABLE IF EXISTS owns;
--  Table stores which drivers are having which cars
create table owns (
    driver INT(100),
    car INT(100),
    PRIMARY KEY (driver,car),
    FOREIGN KEY (driver) REFERENCES drivers(driver_id) ON DELETE CASCADE,
    FOREIGN KEY (car) REFERENCES cars(car_id) ON DELETE CASCADE
)ENGINE=InnoDB;

Table that I cannot add to database is below:
DROP TABLE IF EXISTS order;
-- Table stores which drivers are driving a customer
create table order (
    driver INT(100),
    customer INT(100),
    city INT(100),
    PRIMARY KEY (driver, customer, city),
    FOREIGN KEY (driver) REFERENCES drivers(driver_id),
    FOREIGN KEY (customer) REFERENCES customers(c_id),
    FOREIGN KEY (city) REFERENCES cities(city_id)
)ENGINE=InnoDB;

When trying to add it via phpmyadmin I get the following error:
Static analysis:

2 errors were found during analysis.

    An expression was expected. (near "ORDER" at position 21)
    Unrecognized keyword. (near "ORDER" at position 21)

SQL query:

DROP TABLE IF EXISTS ORDER

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER' at line 1

FINAL EDIT: I finally figured it out, my problem was that order is a reserved/key word in mysql so that was throwing an error. I changed it to orders and all is well. I'll post the final schema below incase anybody runs into the same trouble as I did.
DROP TABLE IF EXISTS cities;
-- Table for storing cities
create table cities (
    city_id INT(100) NOT NULL AUTO_INCREMENT,
    city_name VARCHAR(32),
    PRIMARY KEY(city_id)
)ENGINE=InnoDB;

DROP TABLE IF EXISTS drivers;
-- table for Drivers registered in lyft database
create table drivers (
    driver_id INT(100) NOT NULL AUTO_INCREMENT,
    fname VARCHAR(32),
    lname VARCHAR(32),
    address VARCHAR(32),
    contactnumber VARCHAR(32),
    driver_city INT(100),
    PRIMARY KEY(driver_id),
    FOREIGN KEY (driver_city) REFERENCES cities(city_id)
)ENGINE=InnoDB;

DROP TABLE IF EXISTS cars;
-- Table for storing cars information in lyft
create table cars (
    car_id INT(100) NOT NULL AUTO_INCREMENT,
    car_name VARCHAR(32),
    car_type VARCHAR(32),
    car_model VARCHAR(32),
    car_licencenumber VARCHAR(32),
    PRIMARY KEY(car_id)
)ENGINE=InnoDB;

DROP TABLE IF EXISTS customers;
-- Table for storing customers using lyft
create table customers (
    c_id INT(100) NOT NULL AUTO_INCREMENT,
    c_fname VARCHAR(32),
    c_lname VARCHAR(32),
    c_city INT(100),
    PRIMARY KEY (c_id),
    FOREIGN KEY (c_city) REFERENCES cities(city_id)
)ENGINE=InnoDB;

DROP TABLE IF EXISTS owns;
--  Table stores which drivers are having which cars
create table owns (
    driver INT(100),
    car INT(100),
    PRIMARY KEY (driver,car),
    FOREIGN KEY (driver) REFERENCES drivers(driver_id) ON DELETE CASCADE,
    FOREIGN KEY (car) REFERENCES cars(car_id) ON DELETE CASCADE
)ENGINE=InnoDB;

DROP TABLE IF EXISTS orders;
-- Table stores which drivers are driving a customer
create table orders (
    driver INT(100),
    customer INT(100),
    city INT(100),
    PRIMARY KEY (driver, customer, city),
    FOREIGN KEY (driver) REFERENCES drivers(driver_id),
    FOREIGN KEY (customer) REFERENCES customers(c_id),
    FOREIGN KEY (city) REFERENCES cities(city_id)
)ENGINE=InnoDB;

Comment: what engine are you using? The error is the same as there: https://stackoverflow.com/questions/18391034/cannot-resolve-table-name-close-to
Comment: @LioraHaydont Apparently, it's InnoDB engine
Comment: @LioraHaydont Sorry, I've updated my schema to show the Engine, Charset, and Collate for each table.
Comment: Please put your answer into an answer not your question. After the minimal wait time please accept it to show you found a solution. Next time before you post a question please google your error message without your specific names. Read many answers of many SO hits. Read the manual about it & errors in general. Read & act on [ask] and [mcve]. Reduce your code until there is no error to locate an error.
Answer: From the error Cannot resolve table name, I guess you are trying to create table drivers before you create table cities, that means you are referring a table which doesn't exist. So the solution is to create table cities first
Comment: Fixed, but still getting an error, here's the output:
`Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-foreign-key-constraints.html for correct foreign key definition.
------------
`
Comment: When importing via phpmyadmin I get this error: `#1215 - Cannot add foreign key constraint`
Comment: @Anonymous23234720-12473 now you have modified the `city_id INT(100) UNSIGNED`  of table `cities` but  table `drivers` still `driver_city INT`, the data type should be identical, so should be `driver_city INT(100) UNSIGNED`
Comment: Sorry, that was just a typo.
Comment: I've got my schema semi-working, but I can seem to add the `order` table. I've posted the error above in an edit.
Comment: @Anonymous23234720-12473 `order` is one of the MySQL reserved words, you should add `order` in back quotes ``
Comment: @Anonymous23234720-12473 refer to the [manual](https://dev.mysql.com/doc/refman/5.7/en/keywords.html)


Why is it important to be WS-I Basic Profile compliant?

Question: I see many people argue against WS-Transfer  saying WS-Transfer WSDL it is not WS-I BP compliant. An example is here. After reading it a few times I am still not getting the point why it has to be compliant. Does non-WS-I BP compliancy mean that you won't for example be able to use it in JBossWS?
Answer:
A Web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP-messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards.
http://www.w3.org/TR/2004/NOTE-ws-gloss-20040211/#webservice

That was the theory. In practice though, because different people understood the specifications in different ways (combined with lots of heterogeneous platforms, tools, applications and programming languages) it ended up being a mess, resulting in differences between vendor implementations. Those differences were affecting the "interoperable interactions" so making different implementations talk to each other was a nightmare.
Something had to be done to make different implementations truly interoperable.
WS-I was a move in this direction: it provided a set of guidelines on how the different specifications should be used to create interoperable web services. A set of tools to test these guidelines against different implementations was also provided.

Why is it important to be WS-I Basic Profile compliant?

Basically, WS-I Basic Profile provides the guidance on how to use together specifications
like SOAP, WSDL and UDDI to develop interoperable web services. It is important because
otherwise you will limit your target audience. A web service is meant to be connected to other components and having each component be WS-I compliant will make the job easier no matter the platforms, tools, applications or programming languages.
Using a non WS-I compliant web service in a private environment where you use the same
technology stack for all components might not end up to be an issue, but when exposing
a web service to the public, WS-I Basic Profile is important because it:

will significantly simplify the task of implementing interoperable Web services
  solutions within and across enterprise boundaries.
http://www.internetnews.com/dev-news/article.php/2247551


Interpreting the summary() of a lm() linear model in R

Question: I have a multiple linear regression with 4 independent variables. The summary() function returns the following:
Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.03039    0.16152  -0.188   0.8530
var1         -0.96553    0.18595  -5.193 7.34e-05 ***
var2        -0.25014    0.19732  -1.268   0.2220  *
var3         -0.40355    0.22072  -1.828   0.0851 **
var4         0.15887    0.18559   0.856   0.4039
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.5606 on 17 degrees of freedom
Multiple R-squared:  0.7572,    Adjusted R-squared:  0.6857
F-statistic:  10.6 on 5 and 17 DF,  p-value: 9.445e-05

It shows that var4 is not significant. However, when I remove it from the model, the new $p$-value increases, $R^2$ decreases, and the mean squared error (MSE) of the model also increases.
Question: Should I keep or remove var4 from the model? Will my model be criticized if I keep a non-significant independent variable?
Comment: Adding a variable ALWAYS reduces MSE thus increases R^2 and R^2 is inversely proportional to SSE. Use the adjusted R^2 to determine as to whether to include the variable or not. ie if the adjusted R^2 changes by alot when the variable is added/removed, then include the variable, otherwise leave it out
Answer: Onyambu is correct that adding variables always increases $R^2$ (technically, I think it can have no effect, but that doesn't happen in practice). But adjusted $R^2$ is by no means the only criterion (see AIC and BIC and Mallows Cp for instance) and  there are many reasons for including a non-significant variable:

It may be part of your hypotheses
It may be part of "theory"
There may be little power in the study (due to inadequate sample size)
It may be an important control (e.g. it may have important effects on other parameter estimates or their standard errors.

Will your model be criticized? That could happen either way. You want to have defenses to the criticism and reasons for your choices, and those go beyond $R^2$, adjusted or not.


What REST API can i use to record a file or a folder in records management site

Question: I'm trying to use Alfresco REST API to manage my files and folders in my own interface. Right now i'm trying to activate the records management module but i didn't find the REST APIs that i can use to do it.
Thanks for helping me
Comment: Are you having troubles using the RM/GS module, or actually activating it? What version of Alfresco are you using?
Comment: Did you try reading through https://docs.alfresco.com/rm/concepts/gs-api-overview.html ?
Comment: @Gagravarr I already checked, there's no description for the APIs of RM/GS module
Comment: @Lista i activated it, the graphic interface is working but i want to use the REST API in my own interface
Comment: Did you do as it says there, and download the API explorer and try it on your version?
Answer: I don't think there's a documentation available other than through the API Explorer. You could browse the Swagger file directly though, but I see no point in doing so.
https://community.alfresco.com/community/ecm/blog/2017/06/27/records-management-community-26a
https://github.com/Alfresco/records-management/blob/master/rm-community/rm-community-rest-api-explorer/src/main/webapp/definitions/gs-core-api.yaml
Depending on the version you are using, you could take advantage of someone else's work too.
https://github.com/Alfresco/gs-api-postman-collection
Answer: Once you install AGS module on ACS, the AGS API explorer will be available at the following url.
http://localhost/ags-api-explorer


Cannot assign a value to certain columns in Pandas

Question: Hi I am trying to assign certain values in columns of a dataframe.
# Count the number of title counts
full.groupby(['Sex', 'Title']).Title.count()
Sex     Title
female   Dona              1
         Dr                1
         Lady              1
         Miss            260
         Mlle              2
         Mme               1
         Mrs             197
         Ms                2
         the Countess      1
male     Capt              1
         Col               4
         Don               1
         Dr                7
         Jonkheer          1
         Major             2
         Master           61
         Mr              757
         Rev               8
         Sir               1
Name: Title, dtype: int64

My tail of dataframe looks like follows:
    Age Cabin   Embarked    Fare    Name    Parch   PassengerId Pclass  Sex SibSp   Survived    Ticket  Title
413 NaN NaN S   8.0500  Spector, Mr. Woolf  0   1305    3   male    0   NaN A.5. 3236   Mr
414 39.0    C105    C   108.9000    Oliva y Ocana, Dona. Fermina    0   1306    1   female  0   NaN PC 17758    Dona
415 38.5    NaN S   7.2500  Saether, Mr. Simon Sivertsen    0   1307    3   male    0   NaN SOTON/O.Q. 3101262  Mr
416 NaN NaN S   8.0500  Ware, Mr. Frederick 0   1308    3   male    0   NaN 359309  Mr
417 NaN NaN C   22.3583 Peter, Master. Michael J    1   1309    3   male    1   NaN 2668    Master

The name of my dataframe is full and I want to change names of Title.
Here is the following code I wrote :
# Create a variable rate_title to modify the names of Title
rare_title = ['Dona', "Lady", "the Countess", "Capt", "Col", "Don", "Dr", "Major", "Rev", "Sir", "Jonkheer"]
# Also reassign mlle, ms, and mme accordingly
full[full.Title == "Mlle"].Title = "Miss"
full[full.Title == "Ms"].Title = "Miss"
full[full.Title == "Mme"].Title = "Mrs"
full[full.Title.isin(rare_title)].Title = "Rare Title"

I also tried the following code in pandas:
full.loc[full['Title'] == "Mlle", ['Sex', 'Title']] = "Miss"

Still the dataframe is not changed. Any help is appreciated.
Comment: @JesseBarnett Can you find another duplicate please? That answer is a mess, and doesn't really address this question.
Comment: Possible duplicate of [Update row values where certain condition is met in pandas](https://stackoverflow.com/questions/36909977/update-row-values-where-certain-condition-is-met-in-pandas)
Answer: Use loc based indexing and set matching row values -
miss = ['Mlle', 'Ms', 'Mme']
rare_title = ['Dona', "Lady", ...]

df.loc[df.Title.isin(miss), 'Title'] = 'Miss'
df.loc[df.Title.isin(rare_title), 'Title'] = 'Rare Title'

Comment: Thank you coldspeed. I will check your solution and get back to you in a bit
Comment: I applied your code and checked the head and tail of the dataframe and seems like the title is not changed.
Comment: @JaneshDevkota I have a few ideas as to why. How have you loaded your data? It appears a lot of them have leading white space characters.
Comment: You are right. Looks like might code didn't work because of the white space characters. I removed them and it is working fine.
Comment: Good going, I thought that was it.


Evaluate Log Expression

Question: If $\log_22016=a$, $\log_32016=b$, $\log_72016=c$, evaluate $\frac{1}{2a}+\frac{1}{5b}+\frac{1}{10c}$
My work: I've added the fractions to be $$\frac{5bc+2ac+ab}{10abc}$$ and substituted $a, b, c$ with the change of base formula, but I can't get it to simplify. When you plug in the expression into a calculator you get $\frac{1}{10}$, but I'm not sure what log properties will get me there without a calculator.
Comment: Start with $$\frac1{\log_22016}=\log_{2016}2\ .$$
Comment: Hint 1:  $\frac 1{2a} + \frac 1{5b} + \frac 1{10} = \frac 1{10}{(5a + 2b + c)}$.  Hint 2:  $\frac 1{\log_m n} = \log_n m$.  So  $\frac 1{2a} + \frac 1{5b} + \frac 1{10} = \frac 1{10}(5\log_{2016}2 + 2\log_{2016}3 + \log_{2016}7)$.
Answer: Hint:
Since $\log_22016=a$, so $\frac{1}{a}=\log_{2016}2$. This means
\begin{align*}
\frac{1}{2a}+\frac{1}{5b}+\frac{1}{10c}& =\frac{1}{2}\log_{2016}2+\frac{1}{5} \log_{2016}3 + \frac{1}{10}\log_{2016}{7}\\[10pt]
& =\log_{2016}\sqrt{2}+\log_{2016}\sqrt[5]{3}+\log_{2016}\sqrt[10]{7}\\[10pt]
& =\log_{2016}\sqrt{2}\cdot \sqrt[5]{3}\cdot\sqrt[10]{7}
\end{align*}
Comment: $\ldots\,$and $\displaystyle \sqrt 2 \sqrt[5]3 \sqrt[10]7 = \sqrt[10]{2^5} \cdot \sqrt[10]{3^2}\cdot\sqrt[10] 7. \qquad$
Comment: ..and $2016=2^5 \cdot 3^2 \cdot 7$.
Answer: \begin{eqnarray*}
\frac{1}{10}( 5 \log_{2016} 2 +2 \log_{2016} 3 + \log_{2016} 7 )
\end{eqnarray*}
and note that $2016=2^5 \times 3^2 \times 7$.
Answer: Note:  If $\log_m n = k$ then $m^k = n$ and (assuming $m > 0$ then $m = n^{\frac 1k}$ so $\log_n m = \frac 1k$.
Or in other words $\frac 1{\log_m n} = \log_n m$
So
$\frac 1{2a} + \frac 1{5b} + \frac 1{10c} = $
$\frac 12 \log_{2016}2 + \frac 15 \log_{2016} 3 + \frac 1{10} \log_{2016} 7=$
$\log_{2016}2^{\frac 12}*3^{\frac 15}*7^{\frac 1{10}}$
Now the trick is to realize that if $m = 2^{\frac 12}*3^{\frac 15}*7^{\frac 1{10}}$ then $m^{10} = 2^5*3^2*7 = 2016$ so $m = 2016^{\frac 1{10}}$.
So $\log_{2016}2^{\frac 12}*3^{\frac 15}*7^{\frac 1{10}}= \log_{2016} 2016^{\frac 1{10}} = \frac 1{10}$
Answer: Let us see how the expression has come into being.
$$7^c=2016\iff7^{c-1}=3^22^5\iff5\log2+2\log3+(1-c)\log7=0$$
Similarly, form the other two equations in $\log2,\log3,\log5$
Using Cramer's Rule, as the right hand is $0(d_1,d_2,d_3$ in the link)
we must have $$\begin{vmatrix}
5 & 2 & 1-c \\
5 & 2-b & 1  \\
5-a & 2 & 1   \notag
\end{vmatrix}=0\implies abc=5bc+ab+2ca$$

Evaluate Log Expression


How to introspect a Raku operator?

Question: I can introspect routines in Raku, for example the say
routine:
[5] >  &say.WHAT
(Sub)
[6] >  &say.^mro
((Sub) (Routine) (Block) (Code) (Any) (Mu))

but how can I introspect an operator such as + (doc page)?
[7] >  &+.WHAT
Use of uninitialized value of type Callable in numeric context
  in block <unit> at <unknown file> line 1
  in any  at /home/toni/.rakubrew/versions/moar-blead/install/share/perl6/runtime/perl6.moarvm line 1
  in any <entry> at /home/toni/.rakubrew/versions/moar-blead/install/share/perl6/runtime/perl6.moarvm line 1

Use of uninitialized value of type Any in numeric context
  in block <unit> at <unknown file> line 1
  in any  at /home/toni/.rakubrew/versions/moar-blead/install/share/perl6/runtime/perl6.moarvm line 1
  in any <entry> at /home/toni/.rakubrew/versions/moar-blead/install/share/perl6/runtime/perl6.moarvm line 1

[7] >  &+.mro
No such method 'mro' for invocant of type 'Any'
  in block <unit> at <unknown file> line 1
  in any  at /home/toni/.rakubrew/versions/moar-blead/install/share/perl6/runtime/perl6.moarvm line 1
  in any <entry> at /home/toni/.rakubrew/versions/moar-blead/install/share/perl6/runtime/perl6.moarvm line 1

Since in Raku, operators are simply Subs after all and thus it's easy to declare new ones, I think I am doing something wrong but I cannot find out what precisely.
Answer: By trial and error this is what I found:
&infix:<+>.WHAT

This is what was printed:
(Sub+{is-pure}+{Precedence})

Comment: For infixes, there is actually a shortcut for that: `&[+].WHAT`
Answer: As zentrunix found out, you need both the & sigil (which you use to refer to a Sub object in general) and the operator category, arranged in the following fashion:
&cat:<op>

where cat is the operator category (e.g., prefix, infix, etc) and op is the operator.
For example, the operator - has both prefix and infix forms:
say &infix:<->.WHAT;
say &prefix:<->.WHAT;

As you discerned operators in Raku are simply functions with silly names¹, thus you could use the - operator as follows too:
say &infix:<->(5, 4); # «1␤»
say &prefix:<->(2);   # «-2␤»

❶ I remember reading this somewhere but I cannot recall if it was in the docs or somewhere else.
Comment: ❶ "functions with silly names" Larry called them ["functions with funny names and syntax"](https://design.raku.org/S01.html#:~:text=Operators%20are%20just%20functions%20with%20funny%20names%20and%20syntax.). I think the "funny" is one third a Wally pun ("funny" ≈ "functiony"), two thirds [a reasonable use of one of the meanings of "funny" as "strange or odd"](https://www.google.com/search?q=funny&rlz=1C1CHZN_enGB970GB971&oq=funny&aqs=chrome..69i57j0i433i512j0i512j0i433i512l2j69i61l3.2740j0j7&sourceid=chrome&ie=UTF-8#:~:text=difficult%20to%20explain%20or%20understand%3B%20strange%20or%20odd.).

How to introspect a Raku operator?


Function converting variable Type to Type* creating error C++

Question: I keep getting an error of:
In file included from user.h:3:0,
                from sn.cpp:5:
'mylist.h: In member function 'void MyList<L>::push_back(L) [with L = int]':
user.h:38:30:   instantiated from here
mylist.h:54:3: error: invalid conversion from 'int' to 'int*' [-fpermissive]
mylist.h: In member function 'void MyList<L>::push_back(L) [with L = User*]':
sn.cpp:61:25:   instantiated from here
mylist.h:54:3: error: cannot convert 'User*' to 'User**' in assignment
make: *** [sn.o] Error 1

I am creating a rudimentary social network where main takes 3 command line arguments - argv[1] is a GML file with nodes containing user information and edges that are user connections.  argv[2] is another file that I have not yet processed. and argv[3] is a GML file that will contain basically a copy of the user information after it has been parsed and put into an ADT list MyList that I wrote, containing instances of User* that hold private data for user id, name, zip code, and age.  For some reason my pushback function to add another item to my list is either making pointers double pointers or nonpointers pointers which creates the error above.  I just cannot figure out where I need to remove a * or what I did wrong. the GML reader function populates two vectors nodes and edges with information such as
nodes[0] = id 0 name "Mark Redekopp" age 34 zip 90018
nodes[1] = id 1 name "Tommy Trojan" age 124 zip 90007
and
edges[0] = source 0 target 1
edges[1] = source 1 target 0
The code to write a new GML file is not included yet
sn file
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include "user.h"
#include "mylist.h"
#include "gmlreader.h"

using namespace std;

int main(int argc, char* argv[]){
  if(argc < 4){
    cerr << "Please provide the input GML file, command file, and output file" << endl;
    return 1;
  }
vector<string>nodes;
vector<string>edges;
GMLReader::read(argv[1], nodes, edges);
for(unsigned int i =0; i<nodes.size(); i++){
    cout << "node[" << i << "]: " << nodes[i] << endl;
};
for(unsigned int i=0; i<edges.size(); i++){
    cout << "edge[" << i << "]: " << edges[i] << endl;
    cout << "printing an edge!" << endl;
};
cout << "about to create a mylist of users" << endl;
MyList<User*>Users;
cout << "initialized user list" << endl;
for(unsigned int i =0; i<nodes.size(); i++){
    string TextBlob = nodes[i];
stringstream ss(TextBlob);
cout << "started string stream" << endl;
User* newuser = new User;
    while(newuser->getName()=="" || newuser->getId()==0 || newuser->getZip()==0||        newuser->getAge()==0){
    if (TextBlob.compare("name")==0){
        string n;
        ss>>n;
        newuser->setName(n);
    }
    else if(TextBlob.compare("age")==0){
        int a;
        ss>>a;
        newuser->setAge(a);
    }
    else if(TextBlob.compare("id")==0){
        int d;
        ss>>d;
        newuser->setId(d);
    }
    else if(TextBlob.compare("zip")==0){
        int z;
        ss>>z;
        newuser->setZip(z);
    }
}
Users.push_back(newuser);
}
return 0;
};

mylist.h
#include <iostream>
 #include <string>
 #include <vector>
 #include <stdexcept>

 #ifndef MYLIST_H
 #define MYLIST_H

 using namespace std;

 template<typename L>
 class MyList{
private:
    L* data_;
    int len_;
    int MAX_LIST_SIZE;
public:
    MyList();
    ~MyList();
    void push_back(L newVal);
    int size();
    L& at(int loc);
    bool remove(L val);
    L pop(int loc);
    L& operator[](int loc);
    void changeLen(int new_len){
        len_=new_len;
    }
 };

 int MAX_LIST_SIZE=100;

 template<typename L>
 MyList<L>::MyList(){
        data_ = new L[MAX_LIST_SIZE];
        len_=0;
    };

 template<typename L>
 MyList<L>::~MyList(){
        delete [] data_;
    };

 template<typename L>
 void MyList<L>::push_back(L newVal){
if(len_==MAX_LIST_SIZE-1){
    L* tempList = new L[MAX_LIST_SIZE*2];
    for(int i=0; i<len_; i++){
        tempList[i]=data_[i];
        MAX_LIST_SIZE*=2;
        }
    tempList[len_++]=newVal;
    data_=newVal;
}
data_[len_++]=newVal;
    };

 template<typename L>
 int MyList<L>::size(){
        return len_;
    };

 template<typename L>
 L& MyList<L>::at(int loc){
    if(loc > len_)
        throw invalid_argument("Out of bounds");
return  data_[loc];
};

 template<typename L>
 bool MyList<L>::remove(L val){
for(int i=0; i<len_; i++){
    if(data_[i]==val){
        for(int j=i; j<len_-1; j++){
            data_[j]=data_[j+1];
        }
        changeLen(len_-1);
        return true;
    };
};
return false;
 };

 template<typename L>
 L MyList<L>::pop(int loc){
if(loc>len_)
    throw invalid_argument("Out of bounds");
L temp;
data_[loc] = temp;
    for(int i=len_; i>=loc; i--){
        data_[i-1]=data_[i];
};
changeLen(len_-1);
return temp;
 };

 template<typename L>
 L& MyList<L>::operator[](int loc){
return  data_[loc];
};

 #endif

user.h
#ifndef USER_H
#define USER_H
#include "mylist.h"

class User{
public:
    User(){
        name_=""; age_ =0; zip_=0; id_=0;};
    ~User();
    void setName(string name){
        name_=name;
    };
    string getName(){
        return name_;
    };
    void setAge(int age){
        age_=age;
    };
    int getAge(){
        return age_;
    };
    void setId(int id){
        id_=id;
    };
    int getId(){
        return id_;
    };
    void setZip(int zip){
        zip_=zip;
    };
    int getZip(){
        return zip_;
    };
    MyList<int> getFriends(){
        return Friends;
    };
    void addFriend(int friendid){
        Friends.push_back(friendid);
    };
    void printUser(){
        cout<< "User Name: " << name_ << endl;
        cout<< "User Age: " << age_ << endl;
        cout<< "User's Friends: ";
            for(int j=0; j<Friends.size(); j++){
                cout <<Friends.at(j) << " ";
        };
        cout << endl;
    };
private:
    string name_;
    int age_;
    int id_;
    int zip_;
    MyList<int> Friends;
};

#endif

Comment: That's way too much code, you couldn't narrow it down a bit ?
Comment: please: next time you post errors with positions like "mylist.h:54:3" and the whole file, at least provide line numbers. no one likes to count through that. Or make it shorter like suggested.
Comment: Your question and your code are both illegible.
Comment: Ughh, your code is so tightly packed... How can you read it without your eyes watering!?
Comment: Why not use some of the already-debugged and well-documented container classes that come with the C++ standard library? Or Boost's pointer containers, also debugged and documented. (What's line 54 of `MyList.h`?)
Comment: @DavidSchwartz we aren't allowed to include those classes - it's for an assignment.  and if I use `L data_;` then the array cannot be dynamically allocated but the `MyList` is supposed to be a list of `User*` so should the newuser be a `User**` ?
Comment: `Users.push_back(newuser);`and  `Friends.push_back(friendid);`  are what generate the errors @scones
Comment: @user2059901: The error is in `mylist.h`, line 54.
Comment: @DavidSchwartz `data_=newVal;` but that is in an if statement that should not run unless MAX_LIST_SIZE is exceeded OHH YES THANK YOU SO MUCH!
Comment: Your problem has nothing to do with what runs or doesn't run. It has to do with what compiles or doesn't compile.
Answer: The issue is in push_back, specifically, this line:
data_=newVal;

newVal is an L, but data_ is an L*. I think what you meant to say is data_ = tempList.
Don't forget to delete the old value for data_, though.


C# protobuf-net serialized object to java

Question: So I have a small problem:
A message is sent using MQTT, it consists of a series of serialized objects using protobuf-net in C# (I can't modify this code, but I have access to the source). At the other end i receive the serialized objects in Java, the problem is I can't seem to be able to deserialize the objects using protobuf, if anyone ever had this problem and solved it, please help :)
Example of object from C#:
using ProtoBuf;

namespace Concentrator.Services
{
[ProtoContract]
public class MeterID
{
    private byte[] _id;

    [ProtoMember(1)]
    public byte[] ID
    {
        get { return _id; }
        set { _id = value.Length == 16 ? value : null; }
    }

    [ProtoMember(2)] public string MeterType;
}
}

My attempt at recreating the same object in Java (the .proto file):
syntax = "proto2";

 package mqtt.entity;

 option java_package = "mqtt.entity";
 option java_outer_classname = "ProtoMeter";
 message Meter {
    optional bytes ID = 1;
     optional string MeterType = 2;
  }

  message MeterID {
     repeated Meter mid = 1;
 }

A solution to this example would be a huge help, Thanks a lot.
The code where the object is deserialized in C#:
var ms = new MemoryStream(data, 7, data.Length - 9)
var res = Serializer.Deserialize<List<MeterID>>(ms);

this works in C#, I'm trying to achieve the same thing in java
Comment: You say "I can't seem to be able to deserialize the objects", but what happens when you try? Compilation errors? Runtime errors? Data corruption?
Comment: Verify error when trying to deserialize
Answer: The message in your C# code matches just:
message MeterID {
    optional bytes ID = 1;
    optional string MeterType = 2;
}

There is no need for a 2-level model (unless you're using *WithLengthPrefix in the C# code).  You can also get that output by using:
var proto = Serializer.GetProto<MeterID>();

With your edit, a List<MeterID> could be mapped as
message List_MeterID {
    repeated MeterID items = 1;
}

to be used in combination with the previous MeterID fragment. Which is what you have in the question. So it comes down to "what currently happens?".
Comment: @cdanisor first check you have the current build of the google protobuf (not protobuf-net) package; if `protoc` still emits illegal java, then I would suggest to report it on the [protobuf list](https://groups.google.com/forum/?fromgroups#!forum/protobuf) or on the protobuf (not protobuf-net) [issue tracker](https://code.google.com/p/protobuf/issues/list)
Comment: I'm trying to deserialize in java, the objects comes in a list, I'll update the first post to add the code where they are deserialized in C#
Comment: @cdanisor you didn't mention the `List` :p With that, the .proto from your original question is fine. So that then prompts the question - what happens now? what doesn't work? do you get an exception...? or...?
Comment: There is another problem now :)
Exception in thread "MQTT Client Callback" java.lang.VerifyError: class mqtt.entity.ProtoMeter$MeterID overrides final method getUnknownFields.()Lcom/google/protobuf/UnknownFieldSet;
 at java.lang.ClassLoader.defineClass1(Native Method)
The class generated by protoc seems to be bugged, it overrides a final method.
Comment: You were right, I used a wrong version of protoc, different from the jar, it works flawlessly now. Thanks a lot.
Comment: Hi Cosmin, i am trying to achieve the same thing, trying to de-serialize the .bin file created in C# to object in JAVA.How have you achieved ?
Comment: @Aada it should *just work*. What problems have you encountered?
Answer: try regenerate proto-file by GetProto<T>
Comment: `var res = Serializer.GetProto>;` and use `res`
Comment: @cdanisor the re-implementation of `GetProto` is relatively recent compared to most of the code - I think it handles most scenarios, but if you get any problems with it, let me know
Comment: Be more specific please I never used protobuf before
Comment: Ok getting that in C# it's a good step but how do I export it in java?
Comment: http://stackoverflow.com/questions/7947277/protocol-buffer-how-to-import https://developers.google.com/protocol-buffers/docs/proto
Comment: GetProto method is great, because this was the simplest example other objects are way bigger and this makes my life a lot easier


Is the minimum of the Doksum ratio always unbounded?

Question: Consider $\mathcal{F}$ and $\mathcal{G}$ are two continuous distributions and that $\mathcal{G}$ is more dispersed than $\mathcal{F}$ in the sense of satisfying:
$$(1)\quad F^{-1}(\beta)-F^{-1}(\alpha)\leq G^{-1}(\beta)-G^{-1}(\alpha),\quad \forall 0< \alpha < \beta <1.$$
Then, we know (Kochar (2012), eq. 2.16) that (1) is equivalent to
$$(2)\quad\frac{F^\prime(x)}{G^\prime G^{-1}F(x)}\geq 1.$$
(I call the left hand side of (2) the Doksum ratio after (Doksum 1969))
Now consider the ratio:
$$(3)\quad\gamma(\mathcal{F},\mathcal{G})=\underset{x:F^\prime(x)>0}{\min}\;\frac{F^\prime(x)}{G^\prime G^{-1}F(x)}$$
For many distributions I find that, for fixed $\mathcal{F}$, $\gamma(\mathcal{F},\mathcal{G})$ can be made arbitrary large by shifting/rescaling $\mathcal{G}$.

For example, for the normal, student t, Weibull, gamma I find that
  $\gamma(\mathcal{F},\mathcal{G})$ is an increasing function of
  $\text{Var}(\mathcal{G})$.

My question is this: Is it always so that for fixed $\mathcal{F}$, $\gamma(\mathcal{F},\mathcal{G})$  can be made arbitrarily large by re-scaling/shifting $\mathcal{G}$?
Answer: It is geometrically obvious that shifting $G$ changes nothing and that rescaling will rescale the denominator by the same factor--it's merely a matter of keeping track of units of measurement.  The following is a rigorous algebraic demonstration.  Your conclusion follows immediately.

Let $a\gt 0$ and $b$ be real numbers and define $G_{(a,b)}$ to be the $a$-scaled, $b$-shifted version of $G$:
$$G_{(a,b)}(x) = G(ax + b).$$
Let $0 \le \alpha \le 1$.  Compute that
$$(G_{(a,b)})^{-1}(\alpha) = \frac{G^{-1}(\alpha) - b}{a}$$
and (via the Chain Rule)
$$\frac{d}{dx}G_{(a,b)}(x) = a \left(\frac{d}{dx} G\right)(ax + b).$$
Thus
$$\left(\frac{d}{dx}G_{(a,b)}\right)\left(\left(G_{(a,b)}\right)^{-1}(\alpha)\right) = a \left(\frac{d}{dx}G\right)\left(G^{-1}(\alpha)\right).$$
This shows that shifting does not change the denominator of the Doksum ratio and scaling multiplies the denominator by $a$. As $a\to 0^{+}$, the ratio will grow without bound provided its numerator $F^\prime(x)$ exists and is positive.


Vuetify Slider is Preventing Form Submission

Question: For some reason when I add a slider to my Vuetify form, pressing enter while in the text input no longer submits the form. When I remove the slider, the form submits when I type in the text input and press enter. When I add it back, pressing enter in the text input does nothing. Why is that?
<template>
<v-form
  v-model="valid"
  lazy-validation
  v-on:submit.prevent="search"
>
  <v-container>
    <v-row>
      <v-col>
        <v-text-field
          outlined
          v-model="searchString"
          class="pa-5"
          label="Search for submissions, attachments, samples etc."
        ></v-text-field>
      </v-col>
    </v-row>
    <v-row>
      <v-col>
        <v-slider
          label="Max results"
          class="pa-5"
          v-model="limit"
          max="500"
          min="10"
          step="10"
          ticks="always"
          thumb-label="always"
        ></v-slider>
      </v-col>
    </v-row>
    <v-row>
      <v-col class="text-right">
        <v-btn class="mr-4" color="success" @click="search"
          >Search</v-btn
        >
        <v-btn @click="clear">Clear</v-btn>
      </v-col>
    </v-row>
  </v-container>
</v-form>
</template>

Answer: HTML forms only submit on enter if there is a single input in them. If you have more than one input you also need a submit button for this to happen. You can add type="submit" to the v-btn to turn it into a submit button.
Comment: Jesus you're kidding me. I have been web developing for 13+ years ♂. Worked like a charm


Binomial Coefficient: monotonically decreasing in this range?

Question: relating to this question, I'd like to ask a further one.
Again we have $$f(x)={k-1 \choose x-1} p^x (1-p)^{k-x}$$
We know that this term is maximal for $x=kp$, before increasing, afterwards decreasing.
But what is, if we know that $kp \ll 1$ (for $n\rightarrow \infty$, where $n$ is not very relevant here) and $x$ can only take on constant values from $X$ (Independent from $n$). Then this would imply that $x \gg kp$ for all $x\in X$ and thus the function is decreasing in $X$, is this correct?
Stated differently, is it correct for $kp \ll 1$ and $x=O(1)$ for all $x\in X$, that this term above is monotonically decreasing in the range $X$?
EDIT:
Maybe I should ask my question differently, as I am not interested in the normal case for a fixed $x$ and fixed $k$, $p$. I know what's going on there.
My Problem is, when I know that only asymptotically $x < kp$ (and not necessarily for small values of $n$), is it safe to assume that asymptotically $f$ is decreasing?
Comment: A function of $x$ decreasing when $x$ is constant? Please explain.
Comment: $x$ has a range $X$, where the Minimum and the Maximum value in this range are constants. So every possible value $x$ can have is constant, but in this range $X$, for smaller $x$ the term is bigger.
Comment: ?? Sorry... $ $
Comment: We know that $k$ and $p$ depend on $n$, such that for $n \rightarrow \infty$ we have that $kp \ll 1$.

Further we have that $x$ can take some values from a range $X$, where all the values in $X$ are constants, thus Independent from $n$.
Thus, for every possible value we have $x=O(1)$.

Is it true that for all $x,y \in X$ it holds that:
$f(x)\geq f(y)$ for $x \leq y$ where $f$ is defined as this binomial term above.
Answer: We know $f(x)>f(x+1)$ is equivalent to $x>kp$ or $x\ge \lceil kp\rceil.$ So $f$ is decreasing if $x\gt kp.$
If $kp \lt 1$ then $f$ is decreasing on $X=\{1,2,3,...\}.$
It is not necessary that $ kp<< 1.$
Comment: It is not necessary that $kp \ll 1$, I know.
But if I know that $x=O(1)$ and I know that $kp \ll 1$, it is sufficient to know that $f$ is decreasing, for an asymptotic apprxomiation? Or is this not valid?
Comment: So again, for the ones who read this question and this answer.
What is written in this answer is absolutely clear for me and thus not at all my Problem.
My question was: If i only know that $kp \ll x$ (for big $n$), is it safe to assume that $f$ is decreasing in $x$?
Comment: where all the values in X are constants, thus Independent from n. Thus, for every possible value we have x=O(1).
Comment: This is unclear. I am left to guess what you mean. Use $k_n,p_n,f_n$ since they depend on $n$. $f_n$ is defined on $\{1,2,...,k_n\}.$ You have a subset $X$ of this domain that does not change with the changing values of $k_n.$ So maybe $k_n$ is increasing? If $k_np_n \to c\lt 1$ then there exists an integer $N$ such that for all $n \gt N, k_np_n \lt 1.$ Then from my Answer, $f_n,$ for all $n \gt N,$ is decreasing at each point it is defined and so on $X.$ Is this the Poisson approx. to the binomial?


What is the value returned by theme_get_registry, and why is it not NULL?

Question: I was going through Drupal code, and in the theme.inc file I found something that I couldn't understand. On theme(), I see the following code:
if (!isset($hooks)) {
  init_theme();
  $hooks = theme_get_registry();
}

theme_get_registry() is defined as follows:
function theme_get_registry($registry = NULL) {

  static $theme_registry = NULL;
  if (isset($registry)) {
    $theme_registry = $registry;
  }
  return $theme_registry;
}

I found the function is calling without any parameter, and the default parameter is NULL, but when I use print_r($registry) in the first line of the function theme_get_registry(), I get the values popped out; I assume the value should be NULL because it is not passing any value, and default value is NULL, from where $registry got values in the first line.
Answer: The value returned from theme_get_registry() is initialized by _theme_set_registry(), which is called by _theme_load_registry(), which is called by _init_theme(), called by init_theme().
function _theme_set_registry($registry) {
  // Pass through for setting of static variable.
  return theme_get_registry($registry);
}

init_theme() is called from theme(), right before calling theme_get_registry().
  $args = func_get_args();
  $hook = array_shift($args);

  static $hooks = NULL;
  if (!isset($hooks)) {
    init_theme();
    $hooks = theme_get_registry();
  }

The value used by theme_get_registry() ($theme_registry) is a static value; this means that the value theme_get_registry() gets from _theme_set_registry() is then returned all the times theme_get_registry() is called. NULL is the default value for $theme_registry, until $theme_registry = $registry is executed, and the calling function uses a value different from the default one.
To notice that the declaration of a static variable is different from the declaration of other local variables used by a function.
If I declare a variable as static $registry = NULL it doesn't mean the variable is always set to NULL. The constant value used in the declaration is the value assigned to the variable when it is initialized; the second time the function is called, its static variables are not initialized anymore, but they retain the value they had in the previous call of the function.
As reported in Variable scope:
function test() {
  $a = 0;
  echo $a;
  $a++;
}

This function is quite useless since every time it is called it sets $a to 0 and prints 0. The $a++ which increments the variable serves no purpose since as soon as the function exits the $a variable disappears. To make a useful counting function which will not lose track of the current count, the $a variable is declared static:

function test() {
  static $a = 0;
  echo $a;
  $a++;
}

Now, $a is initialized only in first call of function and every time the test() function is called it will print the value of $a and increment it.
Comment: And here drupal uses [static variables in PHP](http://php.net/manual/en/language.variables.scope.php#language.variables.scope.static) for $theme_registry. So $theme_registry will be initialized only first time
Comment: I added a note about PHP static variables used functions. Thank you for the suggestion.
Comment: if (!isset($hooks))
  {
    init_theme();
 print_r($hooks); //prints nothing
    $hooks = theme_get_registry(); //no values passing, value of the variable $registry become null,
 print_r($hooks); //print values
  }
Comment: @Thomas No, the value of `$registry` doesn't become `NULL`.


Is it possible to prove the Fundamental Theorem of Algebra for all polynomials of degree $n \le 4$?

Question: Recenly I've been wondering whether it's possible to prove the FTA for all polynomials of degree $n \le 4$ without utilizing advanced maths but, at most, basic linear algebra (concepts such as eigenvectors, eigenvalues, determinants etc.). I've tried to give this some thought but I've been only able to make very naïve and futile statements such as "all real numbers can be represented as complex numbers " and "some quadratics and quartics, such as $p(x)=x^2 + 1$ and $p(x)=x^4 -1$, contain complex solutions". Now, I would be really greatful, if it is indeed possible to prove the FTA for all polynomials with degree $n \le 4$, if someone could provide a reference of some sort.
Comment: Pulling out the quadratic/cubic/quartic formula and showing that they are correct is a proof of this. The only sticking point is choosing the right branch of the radicals.
Comment: I vaguely remember doing this for cubics, back in 2010 when I was first discovering that, hey, if you think about things for awhile, hey presto, sometimes you work things out! Can't remember the details, but in retrospect the argument was probably circular, because it probably used facts about matrices with complex entries that relied on FTA to prove in the first place.
Comment: The Wikipedia has some nice proofs:  https://en.wikipedia.org/wiki/Fundamental_theorem_of_algebra
Comment: The most elegant way is to use Liouville's Theorem.  You may start with the definition of holomorphic functions in a complex variable book.  An example is this one: http://www.math.s.chiba-u.ac.jp/~yasuda/ippansug/CV-bookfi.pdf
Answer: Let $p\in\mathbb{R}[X]\setminus\mathbb{R}$ be a polynomial of degree at most $4$.

If $\deg(p)=1$, then you can easily explicit the root of $p$.
If $\deg(p)=2$, same remark.
If $\deg(p)=3$, you can also explicit the roots of $p$ using Cardano's method.
If $\deg(p)=4$, you can also explicit the roots of $p$ using this time Ferrari's method.

Note that if $\deg(p)\geqslant 5$, in the general case, you won't be able to find such formulas for the roots of $p$, it's the Ruffini-Abel theorem


How to find the discrete Heisenberg group in this group given by a small presentation?

Question: Consider the group $G$ given by the following presentation:
$$G=\langle x,y\mid x^{-1}y^2xy^2=x^{-2}yx^{-2}y^3=1\rangle.$$
In this slides it is noted that this is a torsion-free polycyclic group, which is virtually the discrete Heisenberg group, see p.16.
I am interested in the last piece of information. According to the statement, one should be able to find a copy of the Heisenberg group $H$ in $G$, such that $G/H$ is finite.
One possible presentation of the Heisenberg group is given by $$H=\langle a,b\mid [a,[a,b]]=[b,[a,b]]=1\rangle.$$
How to find such a copy of $H$ in $G$ with finite quotient? Can this be done by hand or are the  computer-base algorithms that find such copies? I am not an expert in group theory, so maybe this is obvious?
Comment: The group that you have defined is not torsion-free. I expect you have made a mistake copying the presentation
Comment: @DerekHolt Fixed.
Answer: In the slides you link, it is mentioned this example comes from Lindsay Jennae Soelberg's Master's thesis. She mentions "[using] Magma as a tool to show that $G_Z$ is torsion-free [following] an idea of Derek Holt, given in response to a question at MathOverflow", which I suspect may refer to this answer.
To quote the thesis (p24):

Using Magma we search for a subgroup of $G_Z$ of small index and with an especially easy
rewrite system. It yielded the following subgroup which met the qualifications we required.
Let $H$ be the subgroup generated by the three elements $h_1 := yxy^{−1}x^{−1}$, $h_2 := y^2$, and
$h_3 := x^4$. The group $H$ has index $8$ in $G_Z$, it is a normal subgroup, and it is given by the
finite presentation
$$H = \langle h_1, h_2, h_3 : h_2 \textrm{ is central, and } h_3h_1 = h_1h_3h_2^8\rangle.$$

From this presentation, it becomes clear that $K := \langle h_1,h_3\rangle$ is isomorphic to the Heisenberg group, has index $8$ in $H$ and index $64$ in $G_Z$. Do note, however, that while $K$ is normal in $H$, it is not normal in $G$.
Comment: I rechecked the calculation using Magma again, and it is correct.
Comment: Thanks to both of you. I had a quick look at the thesis, but the Heisenberg group wasn't mentioned...should have had a longer look. But it seems to find H one really has to use a computer. Interesting!