Squiggly line in Alto Sax score

Question: I just got some new sheet music for alto sax and wonder how to play this notation:

For example in these contexts:
Answer: To follow up Wheat's definition answer, here's how I would play this:
When playing glisses on wind instruments, especially in a contemporary or jazz context, the change in pitch should be as continuous as possible. In contrast, a piano is only capable of playing absolutely defined pitches, so glisses all sound like a fast scale (chromatic or otherwise).
All wind instruments have ways of "fudging" glisses so that they sound continuous instead of just like a fast chromatic scale. Trumpet players, for example, would use half-valves in many cases, and clarinets can partially cover tone holes. Saxophone is a bit trickier since all of the tone holes are keyed, but there is quite a lot you can do with the embouchure to bend a pitch. The playing technique for this kind of gliss on saxophone will involve a mixture of embouchure bend and fingering, and the emphasis should be on the embouchure. For experienced players, it's not even imperative that you be fingering a chromatic scale instead of something that falls easier under the fingers, because the embouchure should be able to cover the missing ground anyway.
This takes a VERY well-developed embouchure, however, and a lot of practice. If you're just starting out, focus on making the chromatic scale clean and even, and practice embouchure bends separately before adding them in.
Comment: There are two styles of notating a fall-off in jazz. As a reed player, when I see the wavy line style that E. Lüders asked about, I _usually_ interpret that as a fingered (often chromatic) fall-off. The other style is a [non-wavy curved line](http://musescore.org/sites/musescore.org/files/issues/lipslursjpg.jpg), which I _usually_ interpret as a pitch bend fall-off using the embouchure. I especially tend to make the distinction in charts where the composer uses both styles. Context rules, though, and sometimes a particular interpretation makes more sense regardless of how it is notated.
Answer: The first example is a glissando. Wikipedia defines this as "A continuous, unbroken glide from one note to the next that includes the pitches between."
The second example is a fall-off, meaning to glissando downward in pitch to an unspecified point (you choose how far to go), possibly with a rapid decrescendo to silence.
Comment: As both a reed and (bowed) string player, I take exception to Wikipedia here.  Strictly speaking, glissando is what you can do on a piano, i.e. stream distinct notes.  Portamento is what string players can do by sliding their fingers along the string, producing a continuous delta frequency.  That said, I understand that most jazz and jazz-esque music expects a "gliss" to be more of the latter.
Answer: I disagree with the first (currently accepted) answer by @NReilingh
A glissando can be played on a piano - there is no embouchure changes or pitch bending at all.
NReilingh says:

The playing technique for this kind of gliss on saxophone will involve
  a mixture of embouchure bend and fingering, and the emphasis should be
  on the embouchure.

I have read many jazz saxophone charts (over 20 years) and upon seeing these 2 snippets you've shown, I would definitely not be using embouchure in either.
The definition of a "gliss" doesn't suggest it nor does this particular example require it.
Taking your 2nd snippet, it is very natural to start at the A (2 fingers held down) and roll the remaining fingers down to D (6 fingers held down) while allowing the volume to decrease. This is what I would do upon seeing this.
No embouchure change required.
In your 1st snippet (with a high D down to B) - this happens to work well with the fingering on a sax, in that it's easily possible to slide down chromatically from high D down to B - and this is a very natural gliss to play.
Once again, most definitely, no embouchure changes required (or desirable)
I've never used embouchure to play a gliss and I don't believe it's actually correct to do so - hence I believe @NReilingh's quote is wrong & that you should never use the embouchure when playing a gliss. Using the embouchure to drop from a note has a separate way of being notated ,after all.
Comment: FurryToes, thanks for your answer! It sounds very interesting and this way it seems to be easier to play a glissando. Maybe you can provide an example for your statement that using the embouchure to drop from a note is notated different.
Comment: See this Tenor Saxophone jazz chart for examples of embouchure drops and "ups" - several in the first few bars - http://cloud.freehandmusic.netdna-cdn.com/preview/530x4/warner/ggjzpolts1.png

Squiggly line in Alto Sax score


Term for Major Scale with a minor seventh

Question: Given a C major Scale, with C as root:
C D E F G A B
now make the 7th. step minor, and keeping C as root
(not switching to F Major)
C D E F G A Bb
What is the term / name for this key?
Comment: Thanks for adding a question and an accurate answer! I'm voting to close this question for the future, just because it's a basic piece of reference knowledge that can be obtained elsewhere with more context. I hope you stick around, and check out [the topics covered here](https://music.stackexchange.com/help/on-topic).
Comment: Check out my animated mode wheel here: https://b-p-thomas.github.io/   When this first displays it shows C Ionian, but if you click the [>] button once, it will flatten the B to Bb, and indicate that you're now playing C Mixolydian instead of C Ionian. Enjoy.
Comment: Brian, that animated mode wheel app works fantastically. very illustrative - understanding by geometry makes it so much easier. Thanks a bunch! Greetings & Happy Jamming!
Answer: Yes it is C mixolydian.
The formula for mixolydian scales is WWHWWHW, so if you put it on c it wI'll be like that. Hope this helps.
Answer:
What is the term / name for this key?

The key is C major, because the chord built on the first step is C major. Or to be more specific, it's most probably C major, as I presume in your composition C major chord would function as a tonic chord, the chord resolving the tension.
The scale, as the others said is C mixolydian.
As you noticed C mixolydian has the same notes as F major scale. It is a called a mode of F major. As the F major scale has 7 notes, it has seven modes: F ionian (same as F major scale), G dorian, A phrygian, Bb lydian, C mixolydian, D aeolian and E locrian.
Answer: Modes work from parent keys/scales. The parent for that set of notes is F major.
The 5th mode of F major, using C as the root, is the Mixolydian of  F, more often called C Mixolydian. Not so much a key (as you thought), but as a 'scale', properly known as a mode.
Answer: Now I think the answer is:
It is C Mixolydian.


Remove and uninstall module in a single patch

Question: One of the modules I maintain contains a sub-module. The sub-module doesn't do much; just provides views integration for the main module, i.e. only have implementation of hook_views_data. I would like to move this implementation to the main module.
If it was D7, I would have followed the steps below:

Remove the module files.
Write an update hook in the main module, to remove the entry from the system table.
In the same update hook, would delete the variables (if present).

For D8, I have written an update hook for the same in the module (Reference : #2781805 : Social stats field are not available in views):
/**
 * Implements hook_update_N().
 *
 * Removes entry of social_stats_views module.
 */
function social_stats_update_8001(&$sandbox) {
  // Read the configuration.
  $module_data = \Drupal::config('core.extension')->get('module');

  // Unset the modules you do not need.
  unset($module_data['social_stats_views']);

  // Write the configuration.
  \Drupal::configFactory()->getEditable('core.extension')->set('module', $module_data)->save();
}

I did not add anything else (like removing config, etc.), as the module only implemented a single hook.
I still see the following error after executing the update hook:

User warning: The following module is missing from the file system: social_stats_views in drupal_get_filename() (line 236 of core/includes/bootstrap.inc).

Is there a bullet-proof way to remove the module?
Comment: Yeah, you can't properly uninstall if the files are no longer there. Someone asked this just yesterday in IRC I suggested to simply leave the empty module file there and make it hidden: true so it no longer shows up for new installations. Or keep the module file and then you should be able to safely call uninstall(). If you don't want that, you need to figure out who still tries to look it up. Enable verbose error logging and see who calls it. My guess is update functions, you probably need to delete a key_value entry or so
Answer: You can use ModuleInstaller::uninstall():
\Drupal::service('module_installer')->uninstall(['social_stats_views']);

In D8 there is a lot of housekeeping to do. You can see this in the code of uninstall():
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Extension!ModuleInstaller.php/function/ModuleInstaller%3A%3Auninstall/8.2.x
Comment: The error still shows up. Maybe because the module is not present in the file system?
Comment: You might need to keep a mockup of the sub-module in the updated code of the main module or produce this temporarily in the update hook before running the uninstall.


About Normal Distribution Probability Density Function Notation

Question: The equation for probability density function is:
$$f(x|\mu, \sigma^{2})=(1/(2\pi \sigma^2 ))^{1/2}exp[-(x-\mu)^{2}/2\sigma^{2}]$$
What does the notation $f(x|\mu, \sigma^{2})$ mean? Does it have the same meaning as in conditional probability? And sometimes I'll see $\mu|\sigma^2$ being omitted becoming $f(x)$, or only $\sigma^2$ being omitted becoming $f(x|\mu)$. Does they mean the same?
And what about something like $f(x|a,b,\sigma^2)$ and $f(x|a,b)$?
Comment: It just indicates the parameters of the distribution (the mean and the variance) . Nothing to do with conditional probabilities.
Comment: Is it usual for $\sigma^2$ being omitted? Does the expression still the same?
Answer: Anything written after the pipe $\mid$ indicates parameters of the function that are usually held constant for each instance of the function – they can be inferred from context when omitted.
The same notation is found with elliptic integrals and functions: A&S uses $F(\varphi\mid m),\operatorname{sn}(u\mid m)$ and so on, where $m$ is called… the parameter.
Comment: What about for notation like $f(a|b)$ where both $a$ and $b$ are matrices, does it equivalent to $f(a|b,\Sigma)$ or $f(a|\Sigma, b)$?
Comment: @Theodore It depends on how the models are set up. $\Sigma$ may or may not be a parameter of the model.
Answer: Despite what some comments have claimed, such expressions are common in Bayesian probability and statistics and do have meaning in terms of conditional densities with respect to parameters and hyperparameters.
For instance, we could define a hierarchical model in which $$X \mid \mu, \sigma \sim \operatorname{Normal}(\mu, \sigma^2),$$ and $\mu$ is itself a random variable:  $$\mu \sim \operatorname{Normal}(\mu_0, \sigma_0^2).$$  In this model, $\sigma$ is fixed and known; $\mu_0$ and $\sigma_0$ are hyperparameters representing the prior distribution of $\mu$.  Then based on an observed sample $\boldsymbol X = (X_1, X_2, \ldots, X_n)$, we can compute a posterior density for $\mu$ given the data $\boldsymbol X$.  We write this as $$f(\mu \mid \boldsymbol X, \sigma, \mu_0, \sigma_0) = \frac{f(\boldsymbol X \mid \mu, \sigma)f(\mu \mid \mu_0, \sigma_0)}{f(\boldsymbol X)},$$ which is essentially Bayes' theorem.  Here, $f(\mu)$ is the prior density, and the denominator is the marginal density of the joint distribution of the sample $\boldsymbol X$.
The takeaway is that the symbols that are written after the $|$ sign are intended to represent those quantities that are fixed with respect to those symbols written before the $|$ sign.  Note that if we wanted to, we could write $$f(\boldsymbol X \mid \mu, \sigma) = f(X_1, X_2, \ldots, X_n \mid \mu, \sigma),$$ showing explicitly that the joint density is a mapping $f : \mathbb R^n \to \mathbb R$.


Mozilla Rhino NativeArray.add() is throwing an error - always

Question: I'm looking for build a javascript array in java using mozilla rhino NativeArray class,
however when I try to add elements to NativeArray a java.lang.UnsupportedOperationException is thrown.
here is my code:
NativeArray array=new NativeArray(1);
array.add("cccc");

and here is the error I'm receiving:
Caused by: java.lang.UnsupportedOperationException
    at org.mozilla.javascript.NativeArray.add(NativeArray.java:1826)

If I create the NativeArray with a java array from the begining everything is working great.
String[] str=new String[2];
str[0]="aaaa";
str[1]="bbbb";
NativeArray array=new NativeArray(str);

I was looking through NativeArray source code and I was surprised to see that the add method always throws an error
here is the source code: http://grepcode.com/file/repo1.maven.org/maven2/org.mozilla/rhino/1.7R4/org/mozilla/javascript/NativeArray.java#1825
Note: I'm using mozilla rhino 1.7R4 which is the latest version so far
It this a bug from mozilla rhino or am I doing something wrong?
Thanks
Comment: Is it a requirement to use Rhino ? There are others way to interact with JS in Java that are more stable than Rhino.
Comment: @JulienS. can you give me more detales?
Answer: My original answer (below) is incorrect. "Native" here means "native JavaScript array". Why .add() is not implemented, given that the implementation extends the List interface, I can't say. It is possible however to use the JavaScript means for extending the array (.push() etc).

It doesn't make sense to implement .add() for a native array. They're fixed-length arrays, and the length is constant.
Note that .add() is marked as an "optional operation" in the java.util.Collection interface.
Comment: yes.. you're right. I was thinking this is more like ArrayList
Comment: "They're fixed-length arrays". Are you sure? It seems to me `NativeArray` is JS array, which is not fixed size. It implements `push` using its `js_push` members, beside other. Fixed-length representation is `NativeJavaArray`.
Comment: @Suma you are correct. The non-implementation of `.add()` must be some design decision that may be obscure, but it's plain as day that they didn't want that behavior for the class.
Answer: You can use the following code instead of add():
NativeArray array;
array.put(array.size(), array, result);


Anyone else having Provisioning Profile Problems in iOS?

Question: Since the Apple Developer Site outage, we are unable to add new devices to a new or existing provisioning profile and have the app install without error to those new devices. Devices added before the recent outage work just fine with new and existing profiles, but any device added since about Saturday August 3 2013 fails, from the same file!
We have built new profiles and modified existing ones without luck. I have submitted a bug to Apple, but no response.
We distribute through TestFlight to testers, and the install works great on old devices prior to that date. However, devices added since, download the file and seem to fail at the point where the "install" takes place (ie, signature check and decryption.)
TestFlight correctly recognizes the new (and all old) devices as being added to the profile, and the installs show up properly in TestFlight on all devices as available.
My guess is that keys are being corrupted when new devices are being added to the portal.
I am looking to see if anyone else has had this problem, and if they have any kind of workaround for the issue? I have tried new profiles, new builds, new devices! Nothing works
Thanks in advance
Comment: Some hours ago, I added a new device and created a new Ad Hoc Distribution profile to test an app on a non-dev device. The app installed and runs fine. But I don't use TestFlight.
Comment: I can add and distribute through Ad Hoc just fine as well. I'd say TestFlight would be the one to look into.
Comment: So maybe the problem is with Development certificates (since we are distributing to other developers) and not using Ad-Hoc. I will test that theory. However, those always worked before. Thanks
Comment: But I do need to be clear here. It has to be distributed to a device you JUST added to your profile. It cannot have existed in the Portal before Saturday. CaptJack and Nero, is that the case for both of you? It is ONLY to newly added devices since Saturday. Devices already in the portal and profile work just fine BTW
Comment: Yep. As I said: New device, new Ad Hoc Distribution profile and the app runs on said newly added device; but without TestFlight. Basically I followed [this guide from Apple](http://developer.apple.com/library/ios/#documentation/IDEs/Conceptual/AppDistributionGuide/TestingYouriOSApp/TestingYouriOSApp.html) except for "distributing" the app over the air to the test-device.
Comment: Yeah, I did the same as Nero. New app, new device, new certificate, new Provisioning Profile, Ad Hoc Distribution, all today.
Comment: I added a new device just before the outage, it worked, then when Profiles came back up I added another device, that worked but the first stopped working - I think because Apple went to a backup from before I added the first device (it was about 12 hours before the outage) and the first device wasn't in the list any more. So I added the first device again and both work (AdHoc, via TestFlight).
Comment: Thank to both of you. Back to the drawing board. Trying now with AdHoc instead of developer profiles. Apple responded and said they were "aware of a problem". Maybe only hits some. Thanks again.
Comment: Ok, created a new AdHoc provisioning profile with the exact same results: Old devices work fine, new devices fail from the same file. I can't imagine how TestFlight could be the culprit here. We are trying manual install next.
Answer: So this problem just "went away." Apple did say they were having some problems, but the problem went away before I touched the Apple developer portal again, so not so sure.
TestFlight said they made no changes, but more research and we discovered as issue which I believe wad theirs:
Old devices still allowed the install, because they still contained old provisioning profiles from the same company (us) that covered more than one build. So any of those profiles already on the device, and the install worked fine.
New installs were not installing the provisioning profile correctly for some reason, so the installs failed because there were no old profiles. In some cases, they appeared to install an old profile that did not have the new keys, and that failed too.
We discovered that by installing a new profile by hand to new devices, all apps installed fine from TestFlight. As of last Monday though, the profiles were being properly installed again by TestFlight.
TestFlight says they changed nothing. I'm not so sure. but this problem has disappeared for the time being.
Thanks for all the answers.


How to select a Taxonomy term in a Pane's settings and send it as an argument to Views?

Question: I have a taxonomy vocabulary Help with several terms, representing different topics. I also have a Panel page where I would like to add Panes that contain all nodes with a certain Help term. My idea was to create a content View that accepts filtering on a provided Help term. Next, I would simply add this View to my Panel page and select the desired Help term from a list in the Pane's settings.
I more or less succeeded: my View has a relation Content: Taxonomy terms in node (where I selected the Help vocabulary) and a contextual filter Taxonomy term: name (where I set up an appropriate validation criterium Term name). This works fine, but I have to manually type the term name in my Pane's settings. That is not so efficient, because the term names might change in the future.
Is it possible to pick the desired term name from a list?
Answer: Maybe my initial request has a valid answer, but it is easier to forget about the contextual filter and only keep a relationship Content: Taxonomy terms in node to select the correct vocabulary. Next, filter on Taxonomy Term: Term and select the previously added relationship. Now you can select the required term from a list! Of course, you can duplicate the Views block as many times as needed and only override the taxonomy term. Finally, these blocks can be used in a Panel or elsewhere.


Unable to hide parts of my page, but the same code works on JSFiddle

Question: I'd like to use toggle() (or hide()) from jquery, but it doesn't work.
I know the syntax I use is not bad. It works on  jsFiddle, but I'm unable to make it work with the razor view.
Here is the code I wanted to use :

@Using Html.BeginForm(IsPost)
@Html.ValidationSummary(True)
@<fieldset>
    <legend>contact</legend>

@Html.Raw("Données personnelles : ")

        @Html.Raw("Nom : ")
        @Html.EditorFor(Function(model) model.nom)
        @Html.ValidationMessageFor(Function(model) model.nom)

        @Html.Raw("Prénom : ")
        @Html.EditorFor(Function(model) model.prenom)
        @Html.ValidationMessageFor(Function(model) model.prenom)

        @Html.Raw("Date de naissance : ")
        @Html.EditorFor(Function(model) model.dateNaissance)
        @Html.ValidationMessageFor(Function(model) model.dateNaissance)

        <input type="submit" value="Create" />

</fieldset>
End Using

The html code that is generated is the following :

Données personnelles :

        Nom :
        <input class="text-box single-line" id="nom" name="nom" value="" type="text">

        Prénom :
        <input class="text-box single-line" id="prenom" name="prenom" value="" type="text">

        Date de naissance :
        <input class="text-box single-line" id="dateNaissance" name="dateNaissance" value="" type="text">

And here are the CSS related to those spans :
        /* Styles for validation helpers
        -----------------------------------------------------------*/
        .field-validation-error {
            color: #ff0000;
        }

        .field-validation-valid {
            display: none;
        }

        .input-validation-error {
            border: 1px solid #ff0000;
            background-color: #ffeeee;
        }

        .validation-summary-errors {
            font-weight: bold;
            color: #ff0000;
        }

        .validation-summary-valid {
            display: none;
        }

        /* Styles for editor and display helpers
        ----------------------------------------------------------*/
        .display-label,
        .editor-label {
            margin: 1em 0 0 0;
        }

        .display-field,
        .editor-field {
            margin: 0.5em 0 0 0;
            position:relative;
            left:5px;
        }

        .text-box {
            width: 30em;
        }

        .multiline
        {
            height: 6.5em;
            position:relative;
            left:5px;
        }

        .tri-state {
            width: 6em;
        }
        .display-field
        {
            font-size:1.5em;
        }

What can I do to bypass all that stuff to make some parts of the page hidden?
Comment: Just put your script in [document.ready](http://api.jquery.com/ready/)
Comment: @ai.farfa: No, you don't. You just have to make sure your script runs *after* the DOM elements it needs to manipulate. This is easily done just by putting the script at the end of the page.
Comment: basic usage of jquery You need to wait DOM element ready `$(document).ready`
Answer: If your code really is as quoted, the reason it works on jsfiddle and not in your code is that jsfiddle is including your script after the HTML, but your code is running the script before the elements exist in the DOM.
You have two choices:

Put your script at the end of the page, just before the closing  tag. I'd recommend this, as do the YUI team.
Use jQuery's ready function (people frequently use the confusing shortcut for it, which is just passing a function into the jQuery function, which is usually aliased as $) to schedule your code to run on "DOM ready".
Answer:

Comment: @patxy Only if you pass it a function, not if you pass it a selector.
Comment: @patxy: This is one of the confusing bits of jQuery's API. If you pass a function into `$()`, it's a shortcut for `$(document).ready(...)`. The `$()` function is way overloaded (not only does it do completely unrelated things depending on whether you pass it a function or a string, it even does completely unrelated things depending on the *content* of strings you pass it).
Comment: ok thx, it does work like that. Weerd that it worked on jsFiddle. I though that toggle was the function
Answer: I don't see the need to use Javascript (or jQuery) for this. If you want the elements with the class hidden to be hidden initially, just use a CSS declaration:
.hidden {
    display: none;
}

Comment: I use it because this view has to be used in different contexts. So, in function of the action that called the view, some fields don't have to be displayed


What if value for select option is not specified in html select tag

Question: Recently, I mistakenly didn't specified the value for a select tag in a form of my project. But It was working properly and getting the correct values. Does that mean If I don't specify the value of a option then it assumes the Placeholder/What I am showing for that option as the value.

    <select class="form-control" name="category">
        <option>Action</option>
        <option>Horror</option>
        <option>Adventure</option>
        <option>Comedy</option>
    </select>

Comment: Could you please add some code, so that we can replicate it.
Answer: basically you're right, seeing MDN docs at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select

Each  element should have a value attribute containing the
  data value to submit to the server when that option is selected; if no
  value attribute is included, the value defaults to the text contained
  inside the element. You can include a selected attribute on an
   element to make it selected by default when the page first
  loads.

so yeah you're right, it assumes what you're showing in the html tag as the value
Comment: Thanks...I understand it now
Answer: the answer from w3schools
Note: If the value attribute is not specified, the content will be passed as a value instead.
https://www.w3schools.com/tags/att_option_value.asp
Answer: If you assign no value to each options, the text will be sent to the form action. The reason why we specify values is because it's easier to work with. You could say the text inbetween the option tags is meant to be shown to the users and the value attribute is meant for the application behind when submitting the form.
Example:
<select>
<option value="Pixel">   Google Pixel 4XL</option>
<option value="G8X">     LG G8X ThinQ Dual Screen</option>
<option value="Iphone">  Iphone 11 Pro Max</option>
</select>

Let's say I wanted to check if the selected option was G8X, then I wouldn't have to write something like this:
if (option == "LG G8X ThinQ Dual Screen")
{
   // do something
}


IIS 7, IPv4 address restriction when having multiple sites on the same server

Question: I have one server running IIS 7 with two diffrent sites on the same port (80). They have different host header.
On site 1 I would have no IP restrictions.
On site 2 I would like to alow only specified IP ranges.
How do I configure this in IIS? I found how to add IP address restrictions, but to me it seems like it is affecting both site 1 and site 2.
Answer: Not in the side - you do so on the BINDING of the site (to IIS).
In the Binding you tell the hsot header and the IP addresses to bind to.
Comment: What I wanted was to only allow specified external IP ranges to access my site. Found my answer when I installed IP and Domain restrictions
Answer: Why is it so that when you ask a question, you find the answer the next minute? :)
Anyway, I had not installed/activated IP and Domain restrictions.


How to put line in array

Question: i have a loop in this loop i want to populate my array photos:
   $scope.photos = [];
            var str = data.data.Photos;
            var res = str.split('|');
            angular.forEach(res, function (item) {
                var line = src: 'photos/'+item, desc: item;
                $scope.photos.push(line);
            });

i have  errors in the line var line = src: 'photos/'+item, desc: item;:
 Unexpected token

Comment: you forget parenthesis: `{}` around
Comment: do you want to do that? var line = { 'photos/'+item, desc: item};
Answer: It looks like you've got a colon after the src, that needs to be in curly brackets because it's an object.
var line = {
    src: 'photos/' + item,
    desc: item
};

Answer: Change
var line = src: 'photos/'+item, desc: item;

TO
var line = {
  src: 'photos/'+item, desc: item
};

Answer: angular.forEach(res, function (item) {
                // notice the object literals {}
                var line = { src: 'photos/'+item, desc: item };
                $scope.photos.push(line);
            });

How to put line in array


How exactly does knowing a variable's probability distribution help you when learning about data?

Question: I am an elementary/wanna-be statistician/data scientist from South Korea. I have been studying a variety of theories of mathematical statistics and different probability distributions. (I apologize for bad English if there is any!)
I am wondering how exactly these distributions help a curious data scientist derive any inference or make decisions when building a predictive model.
For example, if a variable of a dataset is estimated to follow Poisson distribution with a specific value of parameter lambda. What can it actually tell you? What kind of inference can I learn? What can it imply when I am looking into a couple of specific data points or areas?
Answer: The entirety of statistical inference is based upon assuming that a variable of interest:
1) Has a probability distribution; and
2) The parameters of the assumed probability distribution can be estimated form the data.
You never know the true probability distribution of a variable (except perhaps in contrived or very unusual circumstances).  If you did, though, you could make a wide variety of claims about real-world events or the randomness of real-world events.
For example, suppose you owned a grocery store and you know that the number of customers per hour followed a Poisson distribution with rate parameter 2.  With this information, you can conclude that, at any given hour of the day you will on average receive 2 customers.  95% of the time, you'll receive between 0 and 5 customers per hour.  If you ran a sale and observed 10 customers arrive per hour, you would have solid evidence that the sale was having its intended affect of increasing customer interest in your store.  In fact, observing 10 customers per hour is almost inconceivable for a Poisson process with mean = 2 (should occur less than 0.0001% of the time), so you would have rather strong evidence.
I'm not entirely certain if this addresses your question, however.  You specifically asked about how knowledge of the distribution could help you with respect to variables in a dataset.  This is kind of an odd question because, as a researcher we are almost never interested in understanding the distribution of data for their own sake.  Most of the time, we look at data to learn what it can tell us about a real-world "data-generating process."  We hypothesize that the data came from some "population-level" process, and we infer the properties of that process from observing data drawn from it.  Typically, the distributions of data are only indirectly useful; they can, for example, help us decide if an assumption of normality (which applies to the hypothesized data-generating process, not to the data themselves) is defensible.
Answer: Often finding the distribution that fits the data is not an endpoint, but a starting point. By knowing the distribution (whether it is "true" or just an approximation), you can say something about the likelihood of a new observation.
For example, you found your observations fits well to N(0,1). Next you observe x=3.1 (the value you've never observed), whose p(x)<1e-3 according to N(0,1).
Then you could say 1) x=3.1 is an outlier (inference based on N(0,1)), or 2) your N(0,1) "conjecture" was wrong, 3) you need more data to draw some conclusion, etc.
Without the distribution, you really can say nothing about how likely x=3.1 observation is.
For almost all cases y=f(x)+error. error will prevent you to find out the relation between x and y. Even worse, f is unknown as well. Hence what all you can say is about p(y|X_new), and this is possible only when you "know" the distribution.
(Note that there is no room for probability or distribution in  e.g. y=x+3 case where  everything is certain.)
You come up with a value, and see its likelihood with respect to some distribution. Then you can assess whether this value is "extreme" or not - "unlikely to happen" or not. To make some "judgement", you need distribution.


I'm unable to access content-length of response headers in app.use() middleware

Question: I am trying to access content-length of response headers in app.use() middleware:
const app = express();
app.use((req, res, next) => {

    //how to get content-length of res
    console.log("content-length", res);  //not able to access content-length
    next();

})

Comment: response.headers.get('content-length')
Answer: response.headers.get('content-length')

Comment: Your answer could be improved by adding more information on what the code does and how it helps the OP.
Answer: The Content-Length header is of course unknown until the response has been finished. You must therefore execute the code that accesses it in the finish event of the response object:
app.use(function(req, res, next) {
  res.on("finish", function() {
    console.log(res.get("content-length"));
  });
  next();
});


TMPro stopping rendering after sprite tag from dynamic SpriteAsset

Question: I am generating (or at least attempting to) a TMP_SpriteAsset at run time, and adding this to the list of fallbacks on the default SpriteAsset.
It is not possible to build the SpriteSheet at compile time, it has to be dynamic for this project.
To do this I am creating an empty TMP_SpriteAsset, along with empty texture and placing the sprites into the sheet as required.  I am creating a TMP_SpriteGlyph setting the properties, and then creating a TMP_SpriteCharacter with the unicode 0xFFFE and the glyph created previously.
Assigning a name to the character after it is created.
I then add the Character and then Glyph to spriteCharacterTable and spriteGlyphTable.
If at this point I attempt to use the sprites, they appear in the inspector and all values are correct as well as their bitmaps, co-ordinates and names, but TMPro cannot find them by name, and renders the unknown sprite question mark.
OK, so I call UpdateLookupTables() on my Sprite Asset after adding them, which is mentioned in the docs, however now, the text is only rendered up to the first sprite! at which point it stops, no text or sprites rendered after this point, nothing in the Log or Error log.  It just stops!
Inspecting the SpriteAsset and the glyphs and characters are all there as before!
I assume I am missing some key somewhere, anyone able to help?
Unity: 2019.4.26
TMPro: 2.1.4
Comment: I have noticed if I mangle the name of a sprite so it doesn't match those in the table, then it will again render the missing sprite image, It still will not render past one it finds, it will however render from from en existing SpriteAsset, but only if it is before one of the dynamically added sprites.
Answer: In my case I had missed the metrics property of the Glyph!
I discovered this by reading through the private UpgradeSpriteAsset method of TMP_SpriteAsset.
I had created my glyph and only set the index, sprite, scale, and glyphRect properties, which will it seems allow it to appear in the inspector, but will cause it to not render, and even abort the rendering (I suspect no check the metrics property before trying to access somewhere in TMPro.


Why is Cricket called Cricket?

Question: My daughter and I were playing softball and on the next field were a bunch of guys playing cricket.  She asked me Why is Cricket called Cricket?  I had no idea and figured this was a good place to find out.
Comment: Not sure if this is on-topic here, cf. http://sports.stackexchange.com/questions/28/where-did-the-term-soccer-originate (maybe EL&U would be a better fit).
Answer: According to Wiktionary and BBC News, the game and the word might originally be from Belgium (and "There is no way to relate the term to any existing English word"):

Perhaps from a Flemish dialect of Dutch met 'with' de 'the' krik ketsen 'to ricochet', i.e. "to chase a ball with a crook".

The Online Etymology Dictionary explains it this way:

1590s, apparently from O.Fr. criquet "goal post, stick," perhaps from M.Du./M.Flem. cricke "stick, staff," perhaps from the same root as crutch.

Why is Cricket called Cricket?


Prevent other applications from writing to SD card

Question: Is there any way of using Java or C++ to prevent all applications from writing to the SD card while my application is performing a write operation? Maybe some Linux system call which can do it?
Answer: No.
You cannot prevent from all applications to write to SDCARD. (Applications have been given equal privileged in Android in un-rooted phone)
Yes if the phone is rooted you can perform this action.
Answer: I don't think you can prevent other applications from writing, but you can prevent them from writing to your file using File.SetWritable(). If that's not secure enough, and if the file isn't too big, you could write it to internal storage and then move it to SD.


str_replace by 2 array's created by sql

Question: I already know how to use string replace by creating an array manually:
array('value1','value2','value3','value4');
But how do I use str_replace by values from a Database?

$original_string = (fruit_1+fruit_2+fruit_3);
table1 database values: fruit_1 fruit_2 fruit_3
table2 database values: 237 9388 2377

output what i want: (237+9388+2377)
The normal str_replace procedure i already know:
$replaced_string =  str_replace($searchwords, $replacewords, $original_string );
How do i get all the values from the database and process them by str_replace?
Can this be done by creating an array or so?
I use PDO to get values from the database.
Thank you!!!
Martijn
Answer: str_replace can take array arguments as well, so you can do this:
$original_string = '(fruit_1+fruit_2+fruit_3)';
$find = explode(' ', 'fruit_1 fruit_2 fruit_3');
$replace = explode(' ', '237 9388 2377');

$new_string = str_replace($find, $replace, $original_string);
// gives (237+9388+2377)

str_replace by 2 array's created by sql


Configure two webservers on the same LAN

Question: I am trying to setup the network for a small business using a network configuration I am new to.  The business has one public IP(135.x.x.x) and wants to use separate machines for its website (www.example.com on 192.168.1.50) and sharepoint site (sharepoint.example.com on 192.168.1.75).  The DC is on 192.168.1.10
I have added DNS Host A records for the sites pointing to the private IP address of the hosting machine.  From inside the LAN, all users can access the web and sharepoint sites.  But from an external PC, the websites return a 401 error.
Not sure whether my problem is topology, DNS, firewalls, or if the concept is simply not possible with only one public IP.
Comment: If possible, get a second public IP, and do 1-to-1 forwarding for both sites on the firewall.
Comment: How is external traffic getting to the websites?  Is this internal or external DNS where you've specified the internal number?
Comment: Please don't cross-post... http://superuser.com/questions/654536/configure-two-webservers-on-the-same-lan
Answer: If you want to access the site publicly, you must use the public IP address, and the firewall must allow that port through to your private web server. If you wish to use Sharepoint as well, which (IIRC) runs on the same port as a web server, you must have a second public IP or you must force the clients to specify a different port number (e.g. http://mysharepointsite.net:81/ (not a valid URL) )
Comment: This may lead to issues with your internal machines not being able to get to the resources required unless you're careful with how you NAT the addresses on the firewall, so please take the time to read up on your firewall thoroughly before trying to implement.
Comment: What he said.  You could port forward through your firewall, perhaps, but you'll need to put one or other server on a nonstandard port.
Comment: Or the OP could use a proxy to direct the traffic appropriately.
Comment: @John Thanks.  Although the machines have individual IP addresses, it hadn't clicked that they were all still using the same public IP:Port combination.  Port forwarding meant that only one of the private IPs could ever serve a site on HTTP(80).  The problem was resolved by assigning unique ports and forwarding those to the respective private IP address.
Answer: I Did something similar with a corporate Intranet, and a Zimbra Mail server. I setup Apache with name based virtual hosts, and used mod_proxy present the sites residing on different web servers. This way, you can have www.example.com pointing at the company website, and sharepoint.example.com pointing at sharepoint. Both would be accessed on port 80 or 443 as required.
mod_proxy documentation is here: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html


Pegar string antes com regex

Question: Estou precisando fazer uma regex pra uma aplicação do qual preciso remover uma determinada combinação de carácteres de dentro de uma string. Explicando melhor o problema.
Eu tenho uma string que retorna do banco de dados, algo mais ou menos assim:
EVENTDATE:10/10/2015|*EDITAR_EVENTDATE:IwCalendar|EVENTTIME_INI:12:00|EVENTTIME_END:13:00|RANKINGHC:0|ALERGIAS:0|QUAIS_ALERGIAS:|INFECCAO:0|DATA_INFEC:|SITIO:0|QUADROCLINICO:|ASPECTO:0| ...

Nessa string eu tenho valores como esse:
*EDITAR_EVENTDATE:IwCalendar|
*EDITAR_TQT_DTULTTROCA:IwCalendar|
*EDITAR_GTT_DTULTTROCA:IwCalendar|

É um padrão, eu preciso remover tudo o que começa com * e tenha o valor IwCalendar e o pipe | no final da string, ou seja, remover os ditos cujos.
Preciso fazer algo genérico pois existem dezenas de campos como esse.
Desde já agradeço pela força!!!
Bom dia à todos.
Answer: Ewerton,
Você pode fazer assim.
var stringTeste = "EVENTDATE:10/10/2015|*EDITAR_EVENTDATE:IwCalendar|EVENTTIME_INI:12:00|EVENTTIME_END:13:00|RANKINGHC:0|ALERGIAS:0|QUAIS_ALERGIAS:|INFECCAO:0|DATA_INFEC:|SITIO:0|QUADROCLINICO:|ASPECTO:0|*EDITAR_EVENTDATEEND:IwCalendar|";

var expressaoRegular = /\*.*?IwCalendar\|/gm;
var resultado = stringTeste.match(expressaoRegular);
console.log(resultado);

var resultado2 = stringTeste.replace(expressaoRegular, " ");

console.log(resultado2);

Aqui um exemplo no jsFiddle
http://jsfiddle.net/1b7s1yv8/1/

Pegar string antes com regex


How do I use the data- attribute to pass values with jQuery?

Question: I'd like to know more about using data-* attributes with HTML and its use within jQuery. I'm simply trying to retrieve data-attribute-name="a value" with .data() and or .attr() both are logging as 'undefined' with the following methods below. How do I use the data- attribute to pass values with jQuery?
HTML

    Beach

JS
$( ".als-item" ).click(function(e) {
e.preventDefault();

var data = $('.als-item').data('data-loc-subject');
var attrmethod = $('.als-item').attr('data-loc-subject');
    console.log(data);
    console.log(attrmethod);
});

jsFiddle
Comment: Note that [`.data`](http://api.jquery.com/data/) *already* takes the "data-" into account, and applies some other "tricks". Also, inside the click, `$(this)..` is sufficient. Please post a minimal http://jsfiddle.net test-case to reproduce the behavior.
Comment: The second one should work, the first one, not so much. If none work you would probably have to post the HTML as well for us to spot the problem.
Comment: Just did. Still have undefined... Hmm
Comment: You're targeting the wrong element, posted an answer.
Answer: You don't need to prefix the data name with the word data.
$( ".als-item > a" ).click(function(e) {
    e.preventDefault();

    var data = $('.als-item').data('loc-subject');
    var attrmethod = $('.als-item').attr('data-loc-subject');
        console.log(data);
        console.log(attrmethod);
});

http://jsfiddle.net/thinkingmedia/c6kYT/
The Difference Between The Two
You can hard code data value into the DOM using data attributes. For example;
Something
console.log($("a").data("john"));
// will output "smith"

That works because jQuery treats data differently from attributes. It will first check if the DOM element contains an attribute called data-john, and if it does return that value. If it does not contain that attribute it will look at internal data attached to the DOM element. If that data exists it will return that value.
When you set data using jQuery it will not update the attributes of the DOM element. It will attach the data to the DOM element internally. Therefore $("a").data("house","on fire"); will store the string "on fire" in the DOM element under a label "house". If you use the DOM inspector to look at the HTML. There will be no new attribute assigned to that element called data-house.
That is different from using the jQuery.attr() methods. Which directly modify a DOM element's attributes.
EDIT:
Something to note is that in order to access the data attributes of some HTML element, you must select the element via some selector (id,class,etc). You cannot pass "this" to any method attribute on the element and use that argument to access the data. It will produce an undefined.

HTML

    <button onclick="somefunc1(this)" id="mybutton"
        data-loc-subject="test value">My Button</button>

JS
function somefunc1(button) {
  // this alert prints "undefined"
  alert($(this).data('loc-subject'));
  // this will print "test value"
  alert($('#mybutton').data('loc-subject'));
}

Plunker
Comment: Also, `data()` only retrieves the attribute the first time if the internal `data` object does not have that key, after that it uses the internal value. This is important as anything that updates the actual attribute will not update the internal `data` object, so consistency is key.
Comment: Can you explain more regarding internal data and internal value?
Also, seems like .data() could replace my use of JS's getElementById() ?
Answer: The "data-" attribute prefix should be stripped off in your .data() call, so assuming:
ohai

it would be retrieved via:
console.log($(".als-item").data("loc-subject"));

Answer:

You can find any element attribute using
$("#someID").attr('attr1') [or] $("#someID").attr('data-attr-1');

to target based on if the element has the attribute, you can do:
$("[attr1]") or $("[attr1='this is attr 1']") , which will return the element (not the attribute value)
Answer:
set the data attribute as per your condition

 Edit

    function onEdit(obj) {
     console.log(this.getAttribute("data-lan")); //my-data
    }


Pigeonhole Principle to solve question straightforward

Question: A store wants to celebrate its anniversary and will give a $200 shopping certicate to the first customer to enter the store whose birthday is the same as that of two other previously admitted customers.
Also, there are extra prizes of $5,000 that will be for the first two customers that have consecutive birthday dates.
(a) What is the greatest possible number of customers that will enter the store before the $200 winner is announced?
(b) What is the greatest possible number of customers that will enter before the winners for the $5000 is announced?
For part a, I got 732 customers, and I applied the Pigeonhole principle. But for part b, I am thinking that it will be infinite because I don't know how many customers will enter the store.
Answer: (a) It may indeed happen that there are $2\times 366=732$ customers before the $733$rd enters and wins.
(b) is a bit ambiguous: Are 1 March and 28 February consecutive? Are 31 December and 1 January consecutive? If we arrange the $366$ dates on a circle, we can pick at most $183$ of them with gaps between, so the answer should be $183$ (and the $184$th wins together with some other customer).
Comment: Lets say that the year has 366 days, just in case. I am also assuming that Dec 31st and Jan 1st are consecutive.
Comment: Dont you have to add 1 more to the 183 for Dec 31 and Jan 1?
Comment: Another thing.. if the first customer is on Dec 31, next Dec 30, and so on.. There would be 366 customer before there is a winner. Right?
This question of very ambiguous!!!! I totally agree!
I think you are assuming id everything goes right, 183 will be least customers to enter.
But if they keep coming up randomly there are changes that we won't have a winner, and so it could be infinitely, since we are looking for the greatest possible number of customers.


When is half normal distribution useful?

Question: Julian Faraway, in his book on linear model with R, used half normal plot to find hat(a value in hat matrix) with too large value.
That's the only example where I saw half normal distribution is used. But other than that, I can't come up with real application of it though I guess it might be useful for approximating some positive numbers whose mean is near zero.
What are real applications of it?
Comment: Because the square root of a $\chi^2(1)$ variable is half normal, most applications involving chi squared values with 1 degree of freedom can be interpreted as applications of a half-normal model.
Comment: The half normal is used in the EGARCH specification for asymmetric volatility modelling.
Answer: In Bayesian statistics the half normal,with a sufficiently large variation parameter, can be used as a noninformative prior distribution on the SD of a standard distribution. This is suggested in, for example:
Gelman, A. (2006). Prior distributions for variance parameters in hierarchical models. Bayesian analysis, 1, 515-534.
Comment: It's true that you use it, but if you do it's typically NOT noninformative, since then you could also use a more typical/easier noninformative prior like gamma or the uniform. The half-t makes more sense as a weakly informative prior, which has a distinct tendency but wide enough tails to let itself be overwhelmed by the data in the face of strong evidence.
Comment: i have came across a function that uses a single value as a paramter for the half normal distribution in a Baysian Market Media Mix context - https://stats.stackexchange.com/questions/599740/choosing-parameters-for-half-normal-distribution-used-a-vague-prior-distribution?noredirect=1#comment1111020_599740 - and i simply cannot figure out how that is supposed to work. Maybe you can explain?
Comment: @Nneka Often that's actually a half-normal *centered at zero*. Then the half-normal can be defined by either it's SD (would it have been a full normal) or the mean or median of the half-normal.
Comment: @RasmusBååth does that mean that i can actually define the  half-normal centered at zero if i only have the mean? How could i do that ?
Comment: also here https://www.quora.com/How-do-I-find-the-log-likelihood-function-of-the-half-normal-distribution-centred-at-zero it says that the mean of a half normal distribution centred at zero is the min(X)?
Answer: In quality control, there is something called a moving-range statistic which is the absolute value of successive differences.  The half-normal serves as the basis of the chart as discussed in the following article:
http://www.tandfonline.com/doi/abs/10.1080/08982119508904612#preview


Migração pro Heroku

Question: Estou migrando o DB do meu app pro Heroku, o deploy funcionou:
$ git push heroku master

Ao tentar migrar a base de dados de acordo com o comando $ heroku run rake db:migrate não funciona e retorna o seguinte erro:

$ : No such file or directory

No log do heroku tem a seguinte entrada:

> $ heroku logs
> $ : No such file or directory00:00 app[web.1]: /usr/bin/env: ruby

Como eu resolvo isso?
Answer: O comando abaixo localmente deve resolver o seu problema:

rake rails:update:bin

Então tente fazer o deploy novamente.
Fonte: https://stackoverflow.com/a/23100542
Comment: valeu.  o problema mesmo era o ruby nã estar declarado no env. brigadão mesmo
Comment: Poderia marcar a resposta como aceita?

Migração pro Heroku


Errors in estimates of intercept and slope in least squares method

Question: We want to find the line $y = mx + c$ that best "fits" the list of points $$(x_1, y_1), (x_2, y_2), ... (x_i, y_i), ... (x_n, y_n).$$ For each point there is no uncertiainty in $x$ and each $y_i$ has uncertainty $\sigma_i$
By minimizing the squares differences
$$[y_i - (mx_i + c)]^2$$
At first for $m$ and then for $c$ and then making a system we can find $m$ and $c.$
This I understand.
My doubt is how can we find uncertainties for $m$ and $c?$
My textbook just says that we can sum the partial derivatives of $m$ with respect to each $y_i$ multiplied by $\sigma_i^2$ (the uncertainty of the given $y_i)$ and performs the calculation in just one line.
Could anyone explain in more detail how to calculate such errors? I think seeing an example with 3 points would make me understand the concept without the trouble of too much notation.
Here is the calculation of my book that gives me trouble:
$$Var[m] = \sum (\frac{dm}{dY_i})^2*\sigma_{Y_i}^2 =$$
$$= (x_i/\sigma_(Y_i)^2- \overline x / \sigma_{Y_i}^2 )^2 * \frac{1}{Var[x]^2}*\frac{1}{\sum\frac{1}{\sigma_{Y_i}^2}} =$$
$$= \frac{1}{Var[x]*\sum\frac{1}{\sigma_{Y_i}^2}}$$
At the start of the second line my book uses $x_i$ outside of any summation symbol, I think that is an error.
Comment: Can you evaluate $(\frac{dm}{dY_i})^2$?
Comment: @BruceET no that's exactly the problem, the derivative of $m = cov(x,y) / var(x) = \overline xy - \overline x * \overline y / ( \overline x^2 - (\overline x)^2 )$ is giving me trouble. In my calculation I get the summation of derivatives of an expression that itself  contains summations. I cannot go forward in that calculation
Answer: Let $X$ denote the matrix with 1s in the first column and $x_i$ in the second column. Then $(m,c) = (X^TX)^{-1}X^Ty$. Let $r$ denote the first row of $(X^TX)^{-1}X^T$, then
$$m=r^T y = \sum_i r_i y_i.$$
Assuming the uncertainties of $y_i$ are uncorrelated, you get $$\sigma^2(m)=\sum_i r_i^2 \sigma^2(y_i).$$
You can do the same for $c$ using the second row of $(X^TX)^{-1}X^T$.
Comment: What does (m, c) represent? I did not study this topic in relation to matrixes so it is very hard for me to follow, could you please explicitly point out how those matrixes represent (or do the same job as) partial derivatives?
Comment: $(m,c)$ is a vector whose first component is $m$; the first displayed equation shows the relation between $m$ and $y$ and makes it trivial to compute partial derivatives.
Answer: I could be wrong, but I doubt that a demonstration with $n = 3$ will
do much for your intuition. In that case, by the time we estimate the slope and
intercept, we do not have a good estimate of variability.
Maybe it will help to show several regressions with $n = 20.$
Model. Suppose
$x_i = i,$ for $i = 1, 2, \dots, 20.$ That is the $x$'s are just the
integers from $1$ through $20.$ If the true y-intercept is $\beta_0 = 4$
and the true slope is $\beta_1 = 1.5,$ then the regression model is
$$Y_i = \beta_0 + \beta_1 + e_i,$$
where the errors are independently $e_i \sim \mathsf{Norm}(\mu=0,\, \sigma=2).$
Then we can generate the $Y_i$ in R statistical software, according to this known model, as follows.
set.seed(622);  n= 20;  b0 = 4;  b1 = 1.5;  sg = 2;  x = 1:n
y = b0 + b1*x + rnorm(n, 0, sg)
plot(x, y, pch=19);  abline(a = b0, b=b1, col="green3")

The 20 points $(x_i, Y_i)$ are plotted below along with the known linear
relationship $Y_i = 4 + 1.5x_i$ and the variability of the points shows
the effect of the normal errors $e_i$.

Regression line. How accurately can the regression line (least squares line)
recover the information about our model? In R, we find the estimated y-intercept
$\hat\beta_0 = 3.519$ and the estimated slope $\hat\beta_1 = 1.551,$ as follows:
lm(y ~ x)

Call:
lm(formula = y ~ x)

Coefficients:
(Intercept)            x
      3.519        1.551

The figure below shows the same data points and true model (green) as above,
along with the regression line (dashed red). The regression line is not a
perfect copy of the true model, but it is close enough to be useful. Of course,
a different experiment using the same model would have different random errors $e_i$, so another experiment would give a slightly different regression line.

Distribution of estimates of slope $\beta_1.$ Essentially, your question
asks for the distribution of the estimates of the y-intercept and slope.
For simplicity, we focus just on the slope. We repeat the regression procedure
100,000 times. Each time we use $n=20,\, \beta_0 = 4,\, \beta_1 = 1.5,$ and $\sigma=2.$
However, on each iteration we simulate new new errors $e_i,$ in order to try to
understand the variability in the distribution of $\hat\beta_1.$
 set.seed(622);  m = 10^5;  n = 20;  x = 1:n;  b0 = 4;  b1=1.5;  sg = 2
 b1.hat = replicate(m, lm(b0 + b1*x + rnorm(n,0,sg) ~ x)$coef[2])
 mean(b1.hat);  sd(b1.hat)
 ## 1.499939    # Expected(b1.hat) aprx 1.5
 ## 0.07764731  # SD(b1.hat)
 hist(b1.hat, prob=T, col="skyblue2", main="Distribution of Slope Estimates")

The simulation suggests that $E(\hat\beta_1) = \beta_1 = 1.5.$
According to statistical theory, $$SD(\hat\beta_1) = \sigma/\sqrt{(n-1)S_x^2}
= 2/\sqrt{665} = 0.07756,$$ which is well-approximated (by 0.07765) in
the simulation.
The histogram seems to be approximately normal in shape.
More precisely,
$$\frac{\hat\beta_2-\beta_0}{S_{Y|x}/\sqrt{(n-1)S_x^2}}\sim
\mathsf{T}(\nu = n-2),$$
Student's t distribution with $n-2$ degrees of freedom,
where $S_{Y|x}$ is an estimate of $\sigma = 2$ (using $x$'s and $Y$'s). So the exact distribution of
$\hat \beta_1$ is based on a t distribution that is nearly normal. In practical applications, the t distribution can be used to make a 95% confidence interval for the unknown true slope $\beta_1.$
Comment: Thanks a lot for illustrating with an example, but I still do not get the connection of the error on the slope and the partial derivatives.
Comment: The partial derivatives with respect to $\beta_0$ and $\beta_1$ are used to derive the least squares line. Maybe you could show the _exact probability relationship_ for which you seek an intuitive justification. What is "intuitive" depends on one's mathematical level, and we have no clue about that from your Question.
Comment: Excuse me for not including the exact equation before, I did not include it because I thought my book made an error in it. Now it is at the bottom of the question, I seek explanation on that equation in particular.


Select first element of srcset with python selenium

Question: Using selenium in Python, I have been able to successfully access some url's of an image I want to download. However, the image link is stored within a srcset image attribute. When I use get_attribute('srcset'), it returns a string with the 4 links. I just want the one. How would I go about doing this? Could I possibly just crop the string afterwards?
Here's the site that I am scraping from:
https://www.politicsanddesign.com/
Here is my code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
import pyautogui
import time

chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(ChromeDriverManager().install(), options = chrome_options)
driver.get('https://www.politicsanddesign.com/')
img_url = driver.find_element(By.XPATH, "//div[@class = 'responsive-image-wrapper']/img").get_attribute("srcset")
driver.get(img_url)

And here is what the img_url object looks like:
//images.ctfassets.net/00vgtve3ank7/6f38yjnNcU1d6dw0jt1Uhk/70dfbf208b22f7b1c08b7421f910bb36/2020_HOUSE_VA-04_D-MCEACHIN..jpg?w=400&fm=jpg&q=80 400w, //images.ctfassets.net/00vgtve3ank7/6f38yjnNcU1d6dw0jt1Uhk/70dfbf208b22f7b1c08b7421f910bb36/2020_HOUSE_VA-04_D-MCEACHIN..jpg?w=800&fm=jpg&q=80 800w, //images.ctfassets.net/00vgtve3ank7/6f38yjnNcU1d6dw0jt1Uhk/70dfbf208b22f7b1c08b7421f910bb36/2020_HOUSE_VA-04_D-MCEACHIN..jpg?w=1200&fm=jpg&q=80 1200w, //images.ctfassets.net/00vgtve3ank7/6f38yjnNcU1d6dw0jt1Uhk/70dfbf208b22f7b1c08b7421f910bb36/2020_HOUSE_VA-04_D-MCEACHIN..jpg?w=1800&fm=jpg&q=80 1800w

But I'd like it to just be:
//images.ctfassets.net/00vgtve3ank7/6f38yjnNcU1d6dw0jt1Uhk/70dfbf208b22f7b1c08b7421f910bb36/2020_HOUSE_VA-04_D-MCEACHIN..jpg?w=400&fm=jpg&q=80

Answer: The image seems to have an attribute called currentSrc which hold only the current value.
img_url = driver.find_element(By.XPATH, "//div[@class = 'responsive-image-wrapper']/img").get_attribute("currentSrc")
driver.get(img_url)

Answer: You can simply split the value extracted from that web element.
As following:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
import pyautogui
import time

chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(ChromeDriverManager().install(), options = chrome_options)
driver.get('https://www.politicsanddesign.com/')
img_url = driver.find_element(By.XPATH, "//div[@class = 'responsive-image-wrapper']/img").get_attribute("srcset")
img_urls = img_url.split(",")

Now img_urls is a list containing 3 URLs, so you can use it as following:
driver.get(img_urls[0]) #open the first URL
driver.get(img_urls[1]) #open the second URL
driver.get(img_urls[2]) #open the third URL

Answer: My inefficient solution:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
import pyautogui
import time

# WILL NEED TO EVENTUALLY FIGURE OUT HOW TO WRAP ALL OF THIS INTO A FUNCTION OR LOOP TO DO IT FOR ALL DIV OBJECTS
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(ChromeDriverManager().install(), options = chrome_options)
driver.get('https://www.politicsanddesign.com/')
img_url = driver.find_element(By.XPATH, "//div[@class = 'responsive-image-wrapper']/img").get_attribute("srcset")
driver.get(img_url)
img_url2 = 'https:' + img_url.split(' 400w',1)[0]
driver.get(img_url2)


A problem about diffeomorphism of two components of the boundary of a manifold.

Question: My geometry professor said that the following statement is true:
Let $M$ be a compact smooth manifold such that $\partial M = M_0 \cup M_1$. Suppose that there exist a smooth function $f:M \to \mathbb R$ such that $f^{-1}(i) = M_i$ for $i=0,1$. If the derivative of the function $f$ is not null at every point of $M$ then $M_0$ and $M_1$ are diffeomorphic.
I have two questions:
1) Is this result really true?    I didn't find any reference where it's stated.
2) If it's true, how to i prove it?
Thank you in advance.
Comment: I think what you described is a cobordism, and $f$ is a Morse function since it has no critical points. I searched around and found this article (http://www.maths.ed.ac.uk/~aar/surgery/exoticspheres.pdf) that states "Prop 3.1: a cobordism with Morse number zero is a product cobordism", I understand this as if $\exists f\colon M\to \mathbb{R}$ with no critical points then $M\cong M_0 \times [0,1]$. Maybe you could add the tags "Morse theory" and "cobordism" so people who understand the topic more could give a better answer for your question.
Comment: Silly example: take the disjoint union of the closed unit ball in $\mathbb{R}^3$ and a solid torus, and let $f$ be radius squared $-1$ on the unit ball and constantly $1$ on the solid torus. Did I misunderstand the statement or perhaps some small changes could fix the statement? This looks like a result in Morse theory, but I'm not really familiar with the topic...
Comment: Sorry, I thought you meant $\neg$(null everywhere). How about a pair of pants(https://en.wikipedia.org/wiki/Pair_of_pants_(mathematics)) embedded in $\mathbb{R}^3$, arranged so that the boundaries are at height $0$ and $1$ respectively, with $f$ being the height function? Also to annoy you with more silly examples we could take e.g. $M_0$ to be $\emptyset$ and $M$ some manifold with non-empty boundary. Then we just arrange so that $0$ is not in the image of $f$.
Comment: @Qidi Perhaps one should assume M to be connected.
Comment: Well, but in your example the derivative is zero on the torus.
Comment: In the picture of wiki, In the pants case, there is a point where the derivative of the height is zero. It's in the middle of the picture where the legs join.
Comment: I agree the not null everywhere was a little bit unclear, i changed it. Thanks.
Answer: A statement that you can adapt to your situation is:
Theorem: Let $f:M\rightarrow \mathbb{R}$ be a Morse function on a smooth manifold. Assume that $a<b$ are given such that  $f^{-1}([a,b])$ is compact and that there are no critical values $c$ with $a\leq c\leq  b$. Then $f^{-1}(a)$ and $f^{-1}(b)$ are diffeomorphic.
The keyword is Morse theory. This is the first thing (varying conditions like compactness) one proves in this direction. A standard and good reference is Milnor's aptly named Morse theory.


CSS changes not taking effect in customized styles folder

Question: I am trying to size the banner in a Jackson theme on my site to fit to the 960px wrapper size have in customized folder in sites/all/themes/mytheme/styles/mytheme.css but no matter what I do the length won't change, only the height which makes no sense at all.
I have tried flushing the cache several times but still no changes take effect.
The code in jackson styles.css is
#banner-wrap {
   background: transparent url(../images/main-sprite.png) repeat-x scroll center -90px;
   height: 133px;
   overflow: hidden;
   width: 100%;
}

I have successfully changed the height but if I change width from 100% to 960px it does nothing.
Comment: Try changing the CSS using Firebug, Chrome developer tools, etc.  If it doesn't take effect there, either, you know your CSS is wrong.
Comment: You have to change it in Jackson theme style.css  not in separate folder style.css
Comment: Either do what Bala said or try and use !important when you change the width.

  .banner-wrap {
    like you have it now ....;
    width:960px !important;
  }
Comment: It is working now - I realized the image was what needed to be changed to be correct dimension for 100% width. BUT NOW the banner image not showing up on forum page but will ask that question separately. Thanks to all.
Comment: So much confusion on CSS — based on questions to SE — can be avoided with a basic CSS understanding of inheritance, precedence and specificity. https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
Answer: Make the changes to the style.css file which is in Jackson theme folder. Not under mytheme

Use
#banner-wrap {
background: transparent url(../images/main-sprite.png) repeat-x scroll center -90px !important;
height: 133px !important;
overflow: hidden !important;
width: 100% !important;
}

Add this in to style.css file
Flush the cache once.
Comment: actually I now have it working - my image was wrong dimension! BUT anyway I added that exact code in mytheme folder copied from jackson style.css.
Comment: Thank you but I think it is important to add to mytheme because I changed the height dimension.
Comment: so your image path should be something like: `../../images/main-sprite.png`
Comment: I just reloaded the image with correct dimension and placed in sites/default/files and chmoded to 700 and apache chown and now it works except on forum pg and one of views result pg.
Answer: Keep the 100% width in Jackson theme and make sure the image file is same width as the container.
Answer: As you theme's css file uses the image. It is better you should put the image in the theme's images folder itself so that you can give corresponding path such as ../images/main-sprite.png. If you place image file under sites/default/files folder then relative path will change every-time you visit different URL. That is the reason why you are not able to get the image on view and forum page. Image path should be accessible from css folder so better to keep the image under jackson_theme_path/images/main-sprite.png. This should solve the problem.
Comment: Interesting- I will see if you are right!


Problema ao desserializar json com $

Question: Segue código json:
{
  "_id": {
    "$oid": "5b0f4a926724c71d945299f9"
  },
  "_class": "notificador.domain.entity.mongodb.WebhookNotification",
  "externalId": "EVE-XXXXXXXXXXXX",
  "resourceId": "TRA-XXXXXXXXXXXX",
  "accountId": "MPA-XXXXXXXXXXXX",
  "channelId": "APP-XXXXXXXXXXXX",
  "event": "TRANSFER.FAILED",
  "url": "{{url}}",
  "token": "{{token}}",
  "resource": {
    "createdAt": "2018-05-29T15:16:03.000-03",
    "amount": 0,
    "entries": [],
    "ownId": "00",
    "_links": {
      "self": {
        "href": "https://api.moip.com.br/v2/transfers/TRA-XXXXXXXXXXXX"
      }
    },
    "fee": 0,
    "cancellationDetails": {
      "cancelledBy": "BANK",
      "description": "CPF/CNPJ nao pertence ao titular da conta",
      "code": 5
    },
    "id": "TRA-XXXXXXXXXXXX",
    "transferInstrument": {
      "method": "BANK_ACCOUNT",
      "bankAccount": {
        "id": "BKA-XXXXXXXXXXXX",
        "agencyNumber": "0000",
        "holder": {
          "taxDocument": {
            "number": "{{NUMBER}}",
            "type": "CPF"
          },
          "fullname": "{{NAME}}"
        },
        "accountNumber": "000000",
        "accountCheckNumber": "0",
        "bankName": "XX",
        "type": "CHECKING",
        "bankNumber": "000"
      }
    },
    "events": [
      {
        "createdAt": "2018-05-29T15:16:03.000-03",
        "description": "Requested",
        "type": "TRANSFER.REQUESTED"
      },
      {
        "createdAt": "2018-05-30T00:00:00.000-03",
        "description": "Failed",
        "type": "TRANSFER.FAILED"
      }
    ],
    "updatedAt": "2018-05-30T00:00:00.000-03",
    "status": "FAILED"
  },
  "status": "SENT",
  "response": {
    "headers": {},
    "status": 200
  },
  "createdAt": {
    "$date": "2018-05-31T01:06:26.909Z"
  },
  "updatedAt": {
    "$date": "2018-05-31T01:06:27.231Z"
  },
  "webhookToFire": {
    "$ref": "webhook_to_fire",
    "$id": {
      "$oid": "5b0f4a926724c71d945299f8"
    }
  }
}

Segue código para desserializar:
return JsonConvert.DeserializeObject<Root>(json);

Recebo erro:

Newtonsoft.Json.JsonSerializationException: 'Additional content found
  in JSON reference object. A JSON reference object should only have a
  $ref property. Path 'webhookToFire.$id', line 77, position 14.'

O problema está no campo $ref. Como eu posso resolver ?
Update
Segue Classes:
public partial class Root
{
    [JsonProperty("_id")]
    public Id Id { get; set; }

    [JsonProperty("_class")]
    public string Class { get; set; }

    [JsonProperty("externalId")]
    public string ExternalId { get; set; }

    [JsonProperty("resourceId")]
    public string ResourceId { get; set; }

    [JsonProperty("accountId")]
    public string AccountId { get; set; }

    [JsonProperty("channelId")]
    public string ChannelId { get; set; }

    [JsonProperty("event")]
    public string Event { get; set; }

    [JsonProperty("url")]
    public string Url { get; set; }

    [JsonProperty("token")]
    public string Token { get; set; }

    [JsonProperty("resource")]
    public Resource Resource { get; set; }

    [JsonProperty("status")]
    public string Status { get; set; }

    [JsonProperty("response")]
    public Response Response { get; set; }

    [JsonProperty("createdAt")]
    public AtedAt CreatedAt { get; set; }

    [JsonProperty("updatedAt")]
    public UpdatedAt UpdatedAt { get; set; }

    [JsonProperty("webhookToFire")]
    public WebhookToFire WebhookToFire { get; set; }
}

public partial class Createdat
{
    [JsonProperty("$date")]
    public DateTimeOffset Date { get; set; }
}

public partial class Id
{
    [JsonProperty("$oid")]
    public string Oid { get; set; }
}

public partial class Resource
{
    [JsonProperty("createdAt")]
    public string CreatedAt { get; set; }

    [JsonProperty("amount")]
    public long Amount { get; set; }

    [JsonProperty("entries")]
    public List<object> Entries { get; set; }

    [JsonProperty("ownId")]
    public string OwnId { get; set; }

    [JsonProperty("_links")]
    public Links Links { get; set; }

    [JsonProperty("fee")]
    public long Fee { get; set; }

    [JsonProperty("cancellationDetails")]
    public CancellationDetails CancellationDetails { get; set; }

    [JsonProperty("id")]
    public string Id { get; set; }

    [JsonProperty("transferInstrument")]
    public TransferInstrument TransferInstrument { get; set; }

    [JsonProperty("events")]
    public List<Event> Events { get; set; }

    [JsonProperty("updatedAt")]
    public string UpdatedAt { get; set; }

    [JsonProperty("status")]
    public string Status { get; set; }
}

public partial class CancellationDetails
{
    [JsonProperty("cancelledBy")]
    public string CancelledBy { get; set; }

    [JsonProperty("description")]
    public string Description { get; set; }

    [JsonProperty("code")]
    public long Code { get; set; }
}

public partial class Event
{
    [JsonProperty("createdAt")]
    public string CreatedAt { get; set; }

    [JsonProperty("description")]
    public string Description { get; set; }

    [JsonProperty("type")]
    public string Type { get; set; }
}

public partial class Links
{
    [JsonProperty("self")]
    public Self Self { get; set; }
}

public partial class Self
{
    [JsonProperty("href")]
    public Uri Href { get; set; }
}

public partial class TransferInstrument
{
    [JsonProperty("method")]
    public string Method { get; set; }

    [JsonProperty("bankAccount")]
    public BankAccount BankAccount { get; set; }
}

public partial class BankAccount
{
    [JsonProperty("id")]
    public string Id { get; set; }

    [JsonProperty("agencyNumber")]
    public string AgencyNumber { get; set; }

    [JsonProperty("holder")]
    public Holder Holder { get; set; }

    [JsonProperty("accountNumber")]
    public string AccountNumber { get; set; }

    [JsonProperty("accountCheckNumber")]
    [JsonConverter(typeof(ParseStringConverter))]
    public long AccountCheckNumber { get; set; }

    [JsonProperty("bankName")]
    public string BankName { get; set; }

    [JsonProperty("type")]
    public string Type { get; set; }

    [JsonProperty("bankNumber")]
    public string BankNumber { get; set; }
}

public partial class Holder
{
    [JsonProperty("taxDocument")]
    public TaxDocument TaxDocument { get; set; }

    [JsonProperty("fullname")]
    public string Fullname { get; set; }
}

public partial class TaxDocument
{
    [JsonProperty("number")]
    public string Number { get; set; }

    [JsonProperty("type")]
    public string Type { get; set; }
}

public partial class Response
{
    [JsonProperty("headers")]
    public Headers Headers { get; set; }

    [JsonProperty("status")]
    public long Status { get; set; }
}

public partial class Headers
{
}

public partial class WebhookToFire
{
    [JsonProperty("$ref")]
    public string Ref { get; set; }

    [JsonProperty("$id")]
    public Id Id { get; set; }
}

Comment: Não entendi ao certo o que você quer... Você deseja tirar o `$` dos atributos do seu `JSON`?
Comment: @EduardoRibeiro Do jeito que está no código json, não consegue desserializar. Me parace que tem que remover `$`.
Comment: Poste a classe `Root` que criou
Comment: @GuilhermeNascimento ok, aguarde.
Comment: Rapaz, eu estava tentando resolver em JS, até sonhei com isso a noite kkk Mas vejo que já resolveram seu problema, então fica para a próxima kkk Acho que nem iria resolver seu problema também.
Answer: Você precisa configurar na classes em suas propriedades JsonProperty (que pode definir por exemplo o nome da chave do JSON) da seguinte forma:
public class Rootobject
{
    [JsonProperty("_id")]
    public Id Id { get; set; }

    [JsonProperty("_class")]
    public string Class { get; set; }

    [JsonProperty("externalId")]
    public string ExternalId { get; set; }

    [JsonProperty("resourceId")]
    public string ResourceId { get; set; }

    [JsonProperty("accountId")]
    public string AccountId { get; set; }

    [JsonProperty("ChannelId")]
    public string channelId { get; set; }

    [JsonProperty("_event")]
    public string Event { get; set; }

    [JsonProperty("url")]
    public string Url { get; set; }

    [JsonProperty("Token")]
    public string Token { get; set; }

    [JsonProperty("Resource")]
    public Resource Resource { get; set; }

    [JsonProperty("Status")]
    public string Status { get; set; }

    [JsonProperty("response")]
    public Response Response { get; set; }

    [JsonProperty("createdAt")]
    public Createdat CreatedAt { get; set; }

    [JsonProperty("updatedAt")]
    public Updatedat UpdatedAt { get; set; }

    [JsonProperty("webhookToFire")]
    public Webhooktofire WebhookToFire { get; set; }
}

public class Id
{
    [JsonProperty("$oid")]
    public string Oid { get; set; }
}

public class Resource
{
    [JsonProperty("createdAt")]
    public DateTime CreatedAt { get; set; }

    [JsonProperty("amount")]
    public int Amount { get; set; }

    [JsonProperty("entries")]
    public object[] Entries { get; set; }

    [JsonProperty("ownId")]
    public string OwnId { get; set; }

    [JsonProperty("_links")]
    public Links Links { get; set; }

    [JsonProperty("fee")]
    public int Fee { get; set; }

    [JsonProperty("cancellationDetails")]
    public Cancellationdetails CancellationDetails { get; set; }

    [JsonProperty("id")]
    public string Id { get; set; }

    [JsonProperty("transferInstrument")]
    public Transferinstrument TransferInstrument { get; set; }

    [JsonProperty("events")]
    public Event[] Events { get; set; }

    [JsonProperty("UpdatedAt")]
    public DateTime updatedAt { get; set; }

    [JsonProperty("status")]
    public string Status { get; set; }
}

public class Links
{
    [JsonProperty("self")]
    public Self Self { get; set; }
}

public class Self
{
    [JsonProperty("href")]
    public string Href { get; set; }
}

public class Cancellationdetails
{
    [JsonProperty("cancelledBy")]
    public string CancelledBy { get; set; }

    [JsonProperty("description")]
    public string Description { get; set; }

    [JsonProperty("code")]
    public int Code { get; set; }
}

public class Transferinstrument
{
    [JsonProperty("method")]
    public string Method { get; set; }

    [JsonProperty("bankAccount")]
    public Bankaccount BankAccount { get; set; }
}

public class Bankaccount
{
    [JsonProperty("id")]
    public string Id { get; set; }

    [JsonProperty("agencyNumber")]
    public string AgencyNumber { get; set; }

    [JsonProperty("holder")]
    public Holder Holder { get; set; }

    [JsonProperty("accountNumber")]
    public string AccountNumber { get; set; }

    [JsonProperty("accountCheckNumber")]
    public string AccountCheckNumber { get; set; }

    [JsonProperty("bankName")]
    public string BankName { get; set; }

    [JsonProperty("type")]
    public string Type { get; set; }

    [JsonProperty("bankNumber")]
    public string BankNumber { get; set; }
}

public class Holder
{
    [JsonProperty("taxDocument")]
    public Taxdocument TaxDocument { get; set; }

    [JsonProperty("fullname")]
    public string Fullname { get; set; }
}

public class Taxdocument
{
    [JsonProperty("number")]
    public string Number { get; set; }

    [JsonProperty("type")]
    public string Type { get; set; }
}

public class Event
{
    [JsonProperty("createdAt")]
    public DateTime CreatedAt { get; set; }

    [JsonProperty("description")]
    public string Description { get; set; }

    [JsonProperty("type")]
    public string Type { get; set; }
}

public class Response
{
    [JsonProperty("headers")]
    public Headers Headers { get; set; }

    [JsonProperty("status")]
    public int Status { get; set; }
}

public class Headers
{
}

public class Createdat
{
    [JsonProperty("$date")]
    public DateTime Date { get; set; }
}

public class Updatedat
{
    [JsonProperty("$date")]
    public DateTime Date { get; set; }
}

public class Webhooktofire
{
    [JsonProperty("$ref")]
    public string Ref { get; set; }

    [JsonProperty("$id")]
    public Id Id { get; set; }
}

Depois disso também configure uma opção nos settings(JsonSerializerSettings) para ignorar os metadados que o JSON.NET faz em chaves com o nome de ref trate como propriedade normal, exemplo:
var settings = new JsonSerializerSettings();
settings.MetadataPropertyHandling = MetadataPropertyHandling.Ignore;

var result = JsonConvert
      .DeserializeObject<Rootobject>(System.IO.File.ReadAllText("./json1.json"), settings);

Referencia:

MetadataPropertyHandling
Can not deserialize JSON containing $ref keys
Comment: Cara, você é muito bom nisso , resolveu meu problema
Comment: Eu tava tentando fazer desse jeito: `PreserveReferencesHandling.None` e não funcionou.
Comment: Tem que ignorar ... vai aproveitando porque para versão 3 do net core isso vai mudar ... @MatheusMiranda
Comment: Tem como configurar direto pelo `[JsonProperty()]` ? Acho que não neh ?
Comment: @MatheusMiranda não tem essa configuração pelo visto, eu pelo menos não encontrei
Comment: Sua resposta vai ajudar muito pra quem vai encontrar esse tipo de problema `$`.
Comment: @MatheusMiranda se for a resposta da sua pergunta não esqueça de votar
Comment: Sim eu tinha esquecido

Problema ao desserializar json com $


Pass URL as $_GET variable?

Question: I currently have my own URL Shortening service.
How would I go about writing the .htaccess file so that if you go to http://www.xxxxx.com/shorturl it'll treat the shorturl as the shortened url (instead of a directory) and pass it on to the decoder.php file as a $_GET variable?
Answer: Try the following in a .htaccess file in the web root of your server, it's a pretty standard use of mod_rewrite. If it already exists with some other Rewrite rules just tack the block on to the end of your .htaccess file without the RewriteEngine On bit.
<IfModule mod_rewrite.c>
    # Turn on the rewrite engine
    RewriteEngine On

    # If the page doesn't really exist, run it through decoder.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule /?([A-Za-z0-9_-]+)/?$ decoder.php?id=$1 [QSA,L]
</IfModule>

Comment: hmph...no luck. Let's just say that the shortened URL is http://www.xxxx.com/hEkr

Would it get passed through as http://www.xxxx.com/decoder.php?id=hEkr
Comment: @Jason: Yes, that's correct. You'll need to change the GET parameter name to what your `decoder.php` is expecting.
Answer: You are looking for mod_rewrite. Information abounds at your favourite search engine.
Answer: Try this: https://stackoverflow.com/a/15642716/2131877
there you will see how to endoce url before you send that as a $_GET parameter, because the special symbols of link =&:// has to be encoded before they are passed.

Pass URL as $_GET variable?


Variational Bayes: Understanding Mean field approximation

Question: I am looking at the mean field approximation as used in Variational Bayes inference and I looked at this section on wikipedia with the factorised approximation as described here: https://en.wikipedia.org/wiki/Variational_Bayesian_methods#Factorized_approximation
I can understand the approximation we make which is that the parameters are independent a-posteriori but what I do not understand is the update that follows. For example, the derivation of $\ln q(\mu)$ that follows takes the expectation wrt to the other variables. This is stated as a fact here (https://en.wikipedia.org/wiki/Variational_Bayesian_methods#Mathematical_derivation_of_the_mean-field_approximation). Where the "In practice" section says that using calculus of variations we can show that. I could not derive it myself and neither could I find any proof for it in any of the books I own.
Can someone explain me why the log posterior in this factorized approximation is given as an expectation of the log joint model with the expectation taken wrt to the other parameters?
Answer: Taking the equation from Wikipedia
$D_{KL}(Q||P) = \sum_\limits{z}Q(Z)\log\frac{Q(Z)}{P(Z,X)} +\log P(X)$
What we want is to minimize KL distance wrt $Q$ distribution.
Since $P(X)$ is independent of $Q$ we need to care only about the first term.
Substituting the factored approximation, $Q=\prod\limits_{i=1}^M q(Z_i|X)$
$$\sum_\limits{z}Q(Z)\log\frac{Q(Z)}{P(Z,X)} = \sum_\limits{z}Q(Z)\log\{ \prod\limits_{i=1}^M q(Z_i|X)\}-\sum_\limits{z}Q(Z)\log P(Z,X)\\$$
Considering only terms dependent only on a particular factor $q(z_j)$
$$= \sum\limits_{z_j}q(z_j|X)\log q(z_j|X)-\sum_\limits{z_j}q(z_j|X) \left\lbrace \sum\limits_{z_{i\neq j}}\left(\prod\limits_{i\neq j}q(z_i|X)\right)\log P(Z,X)\right\rbrace+ \text{const}$$
In the above equation the terms inside the curly braces is an expectation of the function $\log P(Z,X)$. Where $\mathbb{E}_{i\neq j}$ denotes expectation under $Q(Z)$ distribution wrt all variables except $z_j$. This is where the expectation wrt other variables of log joint model comes into equation. Defining $ \log\tilde{P}(Z_j,X)  \triangleq \mathbb{E}_{i\neq j}\left[\log P(Z,X)\right]$ (Note that once you do the expectation it is a function of $z_j$).
$$\begin{equation}= \sum\limits_{z_j}q(z_j|X)\log q(z_j|X)-\sum_\limits{z_j}q(z_j|X)\mathbb{E}_{i\neq j}\left[\log P(Z,X)\right]+ \text{const}
\end{equation}$$
$$\begin{equation}
=\sum\limits_{z_j}q(z_j|X)\left\lbrace \log q(z_j|X)-\log\tilde{P}(Z_j,X) \right\rbrace+\text{const}\\
=\sum\limits_{z_j}q(z_j|X)\log \left(\frac{q(z_j|X)}{\tilde P(Zj,X)}\right)+\text{const}
\end{equation}$$
Now if we make $\tilde{P}(Z_j,X)$ a probability mass function by including a normalization constant, (such that $\tilde{P}(Z_j,X)$ sums to 1 over all possible $Z_j$), this normalizing constant can be absorbed in to the constant term.
That will make this again a KL distance between $q(Z_j)$ and the the new distribution which is proportional to $\tilde{P}(Z_j,X)$. If the two distributions are equal, KL distance becomes zero and gives the minimum of our original objective.
Therefore, in order to minimize $D_{KL}(Q||P)$ wrt each $q(z_j)$ we want
$
\begin{equation}
q(z_j|X) \propto \tilde{P}(Z_j,X)
\end{equation}$
Since $\tilde{P}(Z_j,X) = \exp\{\mathbb{E}_{i\neq j}\left[\log P(Z,X)\right]\}$
$q(Z_j|X) = \dfrac{\exp\{\mathbb{E}_{i\neq j}\left[\log P(Z,X)\right]\}}{\sum\limits_{Z_j}\exp\{\mathbb{E}_{i\neq j}\left[\log P(Z,X)\right]\}}$
Comment: This is a great answer and paired with this video, has really helped clear the fog: https://www.youtube.com/watch?v=OsunRTEh1pw&index=5&list=PLdk2fd27CQzSd1sQ3kBYL4vtv6GjXvPsE
Comment: Refer to Bishop's Machine Learning text book for more information. (Chapter 10)


Exception: ROM is missing for ms_pacman, see https://github.com/openai/atari-py#roms for instructions

Question: I am totally new to OpenAi gym, I have just installed gym and then try to make environment for
env = gym.make('MsPacman-v0') so I am getting the following error:
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-21-e04adf623175> in <module>
----> 1 env = gym.make('MsPacman-v0')

~\Anaconda3\envs\env_project\lib\site-packages\gym\envs\registration.py in make(id, **kwargs)

~\Anaconda3\envs\env_project\lib\site-packages\gym\envs\registration.py in make(self, path, **kwargs)

~\Anaconda3\envs\env_project\lib\site-packages\gym\envs\registration.py in make(self, **kwargs)

~\Anaconda3\envs\env_project\lib\site-packages\gym\envs\atari\atari_env.py in __init__(self, game,
mode, difficulty, obs_type, frameskip, repeat_action_probability, full_action_space)

~\Anaconda3\envs\env_project\lib\site-packages\atari_py\games.py in get_game_path(game_name)
 18     path = os.path.join(_games_dir, game_name) + ".bin"
 19     if not os.path.exists(path):
---> 20         raise Exception('ROM is missing for %s, see https://github.com/openai/atari-py#roms
for instructions' % (game_name,))
 21     return path
 22

Exception: ROM is missing for ms_pacman, see https://github.com/openai/atari-py#roms for instructions

After this I also tried to find the solution on the web and download the ROMs then hit the command python -m atari_py.import_roms <path where ROMs downloaded>, after running this command I am also getting following error
(env_project) C:\Users\ME>python -m atari_py.import_roms C:\Users\ME\Downloads\roms_folder\

copying adventure.bin from HC ROMS/BY ALPHABET (PAL)/A-G/Adventure (PAL).bin to
C:\Users\ME\Anaconda3\envs\env_project\lib\site-packages\atari_py\atari_roms\adventure.bin
Traceback (most recent call last):
File "C:\Users\ME\Anaconda3\envs\env_project\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\ME\Anaconda3\envs\env_project\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\ME\Anaconda3\envs\env_project\lib\site-packages\atari_py\import_roms.py", line 93,
in <module>
main()
File "C:\Users\ME\Anaconda3\envs\env_project\lib\site-packages\atari_py\import_roms.py", line 89,
in main
import_roms(args.dirpath)
File "C:\Users\ME\Anaconda3\envs\env_project\lib\site-packages\atari_py\import_roms.py", line 78,
in import_roms
_check_zipfile(f, save_if_matches)
File "C:\Users\ME\Anaconda3\envs\env_project\lib\site-packages\atari_py\import_roms.py", line 23,
in _check_zipfile
process_f(innerf)
File "C:\Users\ME\Anaconda3\envs\env_project\lib\site-packages\atari_py\import_roms.py", line 67,
in save_if_matches
f.seek(0)
io.UnsupportedOperation: seek

I don't know what I am doing wrong. Thank in advance.
Answer: This script should fix the issue
import urllib.request
urllib.request.urlretrieve('http://www.atarimania.com/roms/Roms.rar','Roms.rar')
!pip install unrar
!unrar x Roms.rar
!mkdir rars
!mv HC\ ROMS.zip   rars
!mv ROMS.zip  rars
!python -m atari_py.import_roms rars

Comment: is this a Python script or something to put in a Jupyer notebook code cell? It does not work natively in Python for me.
Answer: After downloading ROMs it will be available as Roms.rar in Downloads folder, it contains 2 zip files inside HC ROMS.zip and ROMS.zip I had to extract Roms.rar again extracted ROMS.zip. And then run the command.

python -m atari_py.import_roms C:\Users\ME\Downloads\Roms\ROMS
Answer: This is probably due to a bug in ZipFile.seek() in Python 3.7.0: Python issue #34035.
You need to upgrade to the latest Python 3.7.x release.
Also note that, since gym 0.21, you can install gym and get all the ROMs automatically by running the following commands:
pip install "gym[atari,accept-rom-license]"

Details:
The accept-rom-license option will install the AutoROM package, which gives you the AutoROM command. It will also run it automatically with the --accept-license option. Alternatively, you could pip install autorom and run the AutoROM command manually. If you don't give it any options, this is what it outputs, so be warned. My feeling is that it's okay to use them for research and educational purposes, but I'm not a lawyer:
AutoROM will download the Atari 2600 ROMs.
They will be installed to:
    [...]/site-packages/AutoROM/roms

Existing ROMs will be overwritten.

I own a license to these Atari 2600 ROMs.
I agree to not distribute these ROMs and wish to proceed: [Y/n]:

Run AutoROM --help for more options.
Answer: You do not need to download ROM files yourself if you are using atari_py nor if you are using the ale-py (which you are not) but something to have in mind. All ROM files are in directory <drive>\<content root>\venv\Lib\site-packages\atari_py\atari_roms and they are automatically uploaded when you import atari_py (given it is a working and compatible version)
You should also test if GYM is working for non-atari games as gym (depending on version) imports the games in a different way: (example for GYM 0.18.0, where when it searches for Atari ROM it first goes to Atari in GYM and then it is redirected to atari_py library - so you need to have both)

I just had an issue like this myself. I am using atari_py 0.2.6 (as newer versions of it do not work), Python 3.7 (as atari_py is compatible only with 3.7 and lower of Python), gym 0.18 (as otherwise it is having issues accessing ROM files and loading games, the new GYM version 0.20 (uses games v5) and above uses ale-py and it has a different format for rendering as well - https://brosa.ca/blog/ale-release-v0.7 so games v0 - v4 will not work on it as they have been depicted (or they at least did not work for me)
Since your code is looking for the ROM file in atari_py you deff have gym 0.18.0 (lower than 0.20.0 certainly) as the new GYM version uses Ale-py.
(I am not saying your issue is with directory but if you cannot work out where it searches for the ROM files and if it actually exists I advise you to try bellow)
One option you can do is import the library so it is in your directory that your code is in (copy the atari_py folder from github and insert in your directory so it is in content root):

, next you can change (so it can find the directory of the folder the code is executed in):

My advise is to carefully check your versions and compatibility and see if it searches in the right directory for the ROM files and your program should work. Having in mind the directory for imported atari_py 0.2.6 is <drive>\<content root>\venv\Lib\site-packages\atari_py\atari_roms
Answer: import gym is not enough to install if you want to use atari. You must do: pip install "gym[atari,accept-rom-license]"


How to hide RDLC Table Column if no data is present in all the Rows with Expression?

Question: I would like to hide the entire column including the header if all the rows under that is null or of no values with expression in an RDLC Report.
I have tried the expression
<code>"=IIF(IsNothing(Fields!de_projectactivityidname.Value), True, False)"
</code>
inside the "Visibility" of the Column property.
I would like to do this without any report parameters.
any help is appreciated.
Vinu
Answer: I think you were on the right track, but likely the field is never going to be null/nothing.  Instead, it's likely to be an empty string.
This should work:
<code>=IIF((Fields!de_projectactivityidname.Value = ""), True, False)
</code>


Como auditar registros guardando as alterações em JSON

Question: Estou utilizando uma função para auditar registros nos eventos insert, update, delete para uma tabela do PostGres 9.6.
Peguei o script no Git - audit-trigger
O script foi implementado e está funcionando perfeitamente, porém um dos resultados que ele me traz no log de auditoria é:
"id"=>"2", "ende"=>"Rua 2 de julho", "nome"=>"Amanda", "senha"=>"1234", "telefone"=>"069", "estaativo"=>"t", "ultimaalteracao"=>"2018-06-21 09:50:15.677835"

Como fazer para que o resultado seja um JSON:
{
    "id":2,
    "ende":"Rua 2 de julho",
    "nome":"Amanda",
    "senha":"1234",
    "telefone":"08799919991",
    "estaativo":true,
    "ultimaalteracao":"2018-06-21 09:50:15.677835"
}

Já tentei alterar o script obtido acima usando a função row_to_json, segue a alteração:
IF (TG_OP = 'UPDATE' AND TG_LEVEL = 'ROW') THEN
    --audit_row.row_data = hstore(OLD.*) - excluded_cols;
    audit_row.row_data = hstore(row_to_json(OLD)) - excluded_cols;
   -- audit_row.changed_fields =  (hstore(NEW.*) - audit_row.row_data) - excluded_cols;
    audit_row.changed_fields =  (hstore(row_to_json(NEW)) - audit_row.row_data) - excluded_cols;
    IF audit_row.changed_fields = hstore('') THEN
        -- All changed fields are ignored. Skip this update.
        RETURN NULL;
    END IF;
ELSIF (TG_OP = 'DELETE' AND TG_LEVEL = 'ROW') THEN
    --audit_row.row_data = hstore(OLD.*) - excluded_cols;
    audit_row.row_data = hstore(row_to_json(OLD)) - excluded_cols;
ELSIF (TG_OP = 'INSERT' AND TG_LEVEL = 'ROW') THEN
    --audit_row.row_data = hstore(NEW.*) - excluded_cols;
    audit_row.row_data = hstore(row_to_json(NEW)) - excluded_cols;
ELSIF (TG_LEVEL = 'STATEMENT' AND TG_OP IN ('INSERT','UPDATE','DELETE','TRUNCATE')) THEN
    audit_row.statement_only = 't';
ELSE
    RAISE EXCEPTION '[audit.if_modified_func] - Trigger func added as trigger for unhandled case: %, %',TG_OP, TG_LEVEL;
    RETURN NULL;
END IF;
INSERT INTO audit.logged_actions VALUES (audit_row.*);
RETURN NULL;

O erro obtido é:
Answer: Este campo do log de auditoria certamente é do tipo hstore.
Você pode usar a função hstore_to_json() para fazer a conversão de um campo do tipo hstore para JSON, veja só:
SELECT hstore_to_json('"id"=>"2", "ende"=>"Rua 2 de julho", "nome"=>"Amanda", "senha"=>"1234", "telefone"=>"069", "estaativo"=>"t", "ultimaalteracao"=>"2018-06-21 09:50:15.677835"')

Exemplo completo:
CREATE TABLE tb_foobar
(
    id BIGINT PRIMARY KEY,
    ende TEXT,
    nome TEXT,
    senha TEXT,
    telefone TEXT,
    estaativo BOOLEAN,
    ultimaalteracao TIMESTAMP
);

CREATE TABLE tb_log
(
    id BIGINT PRIMARY KEY,
    registro hstore
);

-- POPULANDO A TABELA tb_foobar
INSERT INTO tb_foobar ( id, ende, nome, senha, telefone, estaativo, ultimaalteracao ) VALUES
( 1, 'Casa do Chapeu, 87', 'MARIA SILVA', '12345678', '(11) 9999-9090', true, NOW() ),
( 2, 'Rua sem Nome, 214', 'JOAO NINGUEM', '01010101', '(11) 9999-7744', false, NOW() ),
( 3, 'Fim do Mundo, 30', 'JESUS DE NAZARE', 'A1B2C3', '(11) 9999-3344', true, NOW() ),
( 4, 'Terra do Nunca, 21', 'MICHAEL JACKSON', '9876543', '(11) 9999-4567', false, NOW() ),
( 5, 'Rua da Ladainha, 10', 'FULANO DE TAL', '666777666', '(11) 9999-1234', true, NOW() );

-- POPULANDO A tb_log COM REGISTROS DO TIPO hstore
INSERT INTO tb_log ( id, registro ) (SELECT id, hstore(*) FROM tb_foobar);

-- CONVERTENDO REGISTROS PARA JSON
SELECT hstore_to_json(registro) FROM tb_log;

Comment: Só lembrando que o `hstore`, conforme link dado na resposta, é parte dos módulos adicionais (chamados também coletivamente de "contrib"), e para usá-lo é necessário instalar/compilar tais módulos (pacote `postgresql-contrib` no Ubuntu por ex.) e depois criar a extensão em seu banco com o comando `CREATE EXTENSION hstore;`