How to position header in certain position?

Question: Currently still doing my project and I'm trying to find out how to position headings in certain places. Figure 1 is my final goal for my headings to look like.
[Figure 1][1]
Currently this is what mine looks like (Figure 2), I am struggling to position the heading to a similar spot, every time I do, the paragraphs and the navbar move further down leaving a big white gap between the headings & paragraphs.
Also was wondering how would I level out the image with the text & navbar?
Thanks in advance, much appreciated.
[Figure 2][2]
Answer: I believe this is what you wanted:
preview
Basically, you could wrap the header (image + text) into a CSS flexbox, and the rest of the stuff into another flexbox. I edited the CSS file to reflect these changes. Hope this helps! Let me know if you have any other questions.
Here's a link to the jsfillde: https://jsfiddle.net/rzLbkw9m/
Here's the html file:
<!DOCTYPE html>

    <meta charset="UTF-8">
    <link href="holiday.css" rel="stylesheet" type="text/CSS">

    <title>Task 4</title>

Holiday Time

Get away from it all

Destinations

Deals

Flights

Cruise

Extras

Money

                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec ultrices libero eu eros viverra, eget tristique ipsum commodo. Phasellus tempus a erat quis hendrerit. Quisque ipsum felis, vestibulum sed finibus vel, molestie id ante. Morbi metus leo, dictum nec pellentesque nec, condimentum quis magna. Praesent est turpis, pharetra non fermentum sed, elementum ac ante. Integer sodales metus id rutrum hendrerit. Phasellus vel dapibus massa, ut aliquet arcu. Ut consectetur feugiat neque, sed sagittis dui rutrum eget. Maecenas commodo mattis enim quis lacinia. Duis in ipsum vitae mi laoreet dignissim. Nullam consequat velit at magna commodo, in fringilla enim rutrum. Cras at augue sed nisl ultricies lobortis. Praesent rhoncus lectus facilisis, rhoncus purus et, luctus eros. Nunc eros nisi, finibus sit amet urna quis, posuere ultrices mauris.

                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc quis lorem vel neque bibendum iaculis vel id tellus. Nulla auctor elit vitae sollicitudin ultrices. Fusce molestie dictum neque, et dictum magna iaculis eget. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed volutpat, augue eget tincidunt feugiat, felis mi vulputate sem, eu mattis nisi quam sit amet est. Cras eu sem nec metus iaculis tempus sit amet non sapien. Aenean id odio semper purus dignissim elementum. Vestibulum faucibus mi ac odio hendrerit venenatis. Cras rhoncus diam magna, at placerat quam rutrum ut.

                Quisque fringilla sodales lorem eget rhoncus. Curabitur pulvinar blandit justo nec volutpat. Mauris bibendum lobortis quam et aliquam. Nulla dictum varius est, sed fringilla ante volutpat ac. Sed tempus dolor diam, ac porta ligula sagittis ac. Morbi vitae nisi porttitor, sollicitudin urna non, tempus justo. Donec vel vulputate est. Donec aliquet vitae velit eu interdum. Quisque et facilisis diam. Duis rutrum faucibus purus at tempus. Mauris auctor tincidunt mauris, quis porttitor magna aliquam molestie. Aliquam efficitur, ex sed finibus porta, tellus diam dictum arcu, ac egestas quam enim tristique velit. Integer volutpat tortor et tortor consequat tincidunt. Donec imperdiet libero vitae sapien commodo, eget pretium libero eleifend. Sed mi felis, porttitor vel blandit laoreet, pretium a felis. Duis in erat interdum, rutrum lectus viverra, pellentesque elit. Sed imperdiet massa ullamcorper mauris tempus, at euismod nibh convallis. In sapien lorem, lacinia eget viverra sit amet, suscipit in diam. Phasellus at sapien eu orci pellentesque eleifend suscipit eu diam. Vivamus quis nibh id sem placerat rutrum. Nunc pellentesque aliquet congue.

                Nam at eros elementum, venenatis nibh vel, volutpat mi. Donec varius sapien ipsum, sed sagittis ligula iaculis hendrerit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent pharetra ante eget purus rhoncus, ac pharetra eros fermentum. Etiam porta nec leo pretium gravida. Integer a nulla quam. In ullamcorper, nibh id efficitur porttitor, lacus mi semper nisi, id pulvinar ex leo at mi. Vestibulum placerat lacus vitae velit laoreet, in efficitur risus convallis. Nunc at sagittis dolor, eu gravida nunc. In hac habitasse platea dictumst. Mauris vitae lobortis ipsum, quis rhoncus mauris. Ut eget nibh sed dolor sollicitudin dictum efficitur ac ligula. Nullam ut nulla sit amet leo varius tincidunt.

 Contact: 0191 227 1111

Here's the css file:
/* header */
.header-container {
    display: flex;
    align-items: center;
    border: 1px solid lightblue;
}

.header-text {
    margin-left: 25px;
}

.header-text h1 {
    color: purple;
    font-size: 48px;
}

.header-text h3 {
    margin-left: 20px;
}

/* navbar */
.list-column {
    flex: 30%;
    align-self: flex-start;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}

li a {
    display: block;
    color: #000;
    padding: 8px 16px;
    text-decoration: none;
}

li a:first-of-type {
    padding-top: 2px;
}

/* main content */
.row {
    margin-top: 10px;
    display: flex;
    align-items: flex-start;
}

.paragraph {
    margin-bottom: 25px;
}

.intext-img {
    margin-top: 5px;
    margin-left: 10px;
    margin-bottom: 10px;
}

p {
    font-size: 18px;
    margin: 0px;
}

/* footer */
.footer {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    padding: 0.8rem;
    text-align: left;
    background-color: #64A3D6;
}

Answer: create a div around h1 and h3

.header{
position: relative;
top: 50%;
transform: translateY(-50%);
}

this will put the header in the middle of the area vertically. make sure the padding or margin is minimal


Invariant lifts of a closed curve on a surface of genus > 1.

Question: I am learning some things about surfaces of genus greater than $1$, and I am trying to answer this question :
Let $S$ be a compact and orientable surface of genus $g \geq 2$, and $c$ a closed curve on $S$. Let $\widehat{S}$ denote the universal covering space of $S$. Given a deck transformation $\widehat{f}: \widehat{S} \rightarrow \widehat{S}$, is it true that there exists only a finite number of lifts $\widehat{c}$ of $c$ to $\widehat{S}$ that are $\widehat{f}-$invariant ?
(by "lift", I mean the image of a  map $\widehat{c} : \mathbb{R} \rightarrow \widehat{S}$ that lifts the application $c : \mathbb{R}/\mathbb{Z} \rightarrow S$ defining the closed curve $c$).
I hope this is clear ! Thank you for any help :)
EDIT :
My attempts to answer that question : suppose that there exists a lift $\widehat{c}$ of $c$ which is $\widehat{f}-$invariant. Given another deck transformation $\widehat{g} : \widehat{S} \rightarrow \widehat{S}$, I would like to prove that the lift $\widehat{g}(\widehat{c})$ of $c$ is $\widehat{f}-$invariant if and only if $\widehat{g}$ and $\widehat{f}$ commute. It seems to be natural but I don't know how to prove that properly...
Any idea ?...
Comment: Yes, your intuition about $f$ and $g$ is correct. One way to prove this is to use hyperbolic geometry as Max suggested. Then use the fact that the centralizer of $f$ is a finite index extension of $$ (unless $f=e$ of course).
Comment: Thank you for your answer ! But how can I write my intuition about $f$ and $g$ properly ? Intuitively, I would like to say the following : if $\widehat{c}$ and $\widehat{g}(\widehat{c})$ correspond to the same geodesic of $\widehat{S}$, then they are homotopic, in the sense that there is a homotopy between $c$ and $c$ such that the path of a basepoint of $c$ under this homotopy is a non-trivial loop. And this seems to be impossible (but why ?) Is that true ? Thanks again !
Answer: First of all, you need to know that your surface $S$ admits a hyperbolic structure, i.e. is homeomorphic to the quotient $H^2/\Gamma$ of the hyperbolic plane $H^2$ by a group of isometries $\Gamma$ acting properly discontinuously and freely on $H^2$. See e.g. my answer here, although if you do not fix a conformal structure in advance, constructing a hyperbolic structure is easier, see for instance, here. In the same lectures by Aramayona you will find all the needed background material for what is written below.
Every oriented homotopically nontrivial loop $\alpha$ on $S$ represents a (unique up to conjugation) element $\gamma\in\Gamma$. The latter acts on $H^2$ as a hyperbolic isometry: It has exactly two fixed points on the boundary circle $S^1$ of $H^2$. The loop $\alpha$ admits a lift $\tilde{\alpha}$ which is invariant under $\gamma$. The lift $\tilde{\alpha}$ has exactly two limit points in the boundary circle $S^1$: These are the fixed points of $\gamma$. I will use the notation $Fix(\gamma)$ for the fixed-point set of $\gamma$ in $S^1$.
Conversely, if $\gamma$ preserves a (not necessarily simple) parameterized arc $\tilde\beta\subset H^2$, then the limit (accumulation) points of $\tilde\beta$ in $S^1$ are exactly the two fixed points of $\gamma$. Therefore, for each $\gamma'\in \Gamma$, if $\gamma'(\tilde\alpha)$ is $\gamma$-invariant, then $\gamma'$ preserves the fixed-point set $Fix(\gamma)\subset S^1$: It either fixes $Fix(\gamma)$ pointwise or swaps the two fixed points. The latter cannot happen since $\Gamma$ is torsion-free.
Lemma. The stabilizer $\Delta$ of $Fix(\gamma)=\{x_1, x_2\}$ in $\Gamma$ is an infinite cyclic group.
Proof.  Let $L\subset H^2$ be the hyperbolic geodesic with the limit points $x_1, x_2$. Since there is a unique such geodesic, the line $L$ has to be invariant
 under $\Delta$. Therefore, $\Delta$ acts freely as a properly discontinuous  group of isometries of $L\cong {\mathbb R}$. The isometry group of ${\mathbb R}$ is the semidirect product of ${\mathbb R}$ (acting via translations) and ${\mathbb Z}_2$ (whose generator is the reflection $t\mapsto -t$). I will leave it to you as an exercise to show that every discrete infinite subgroup of ${\mathbb R}$ is isomorphic to ${\mathbb Z}$. Hence, $\Delta$ is isomorphic to ${\mathbb Z}$. qed
Therefore, every element $\gamma'\in \Gamma$ which sends $\tilde\alpha$ to a $\gamma$-invariant arc, belongs to the cyclic group $\Delta$. The latter contains $\langle \gamma\rangle$ as a finite index subgroup (since $\gamma\ne 1$). Therefore, the preimage of $\alpha$ in $H^2$ contains only finitely many $\gamma$-invariant arcs.
Comment: Thank you very much for this precise answer ! I think I have to learn a little bit of hyperbolic geometry, but this is clearer now. Thanks !


Typescript error TS2339: Property '__super__' does not exist on type '($element: any, options: any) => any'

Question: I have Javascript code inside typescript
$.fn.select2.amd.require([
    'select2/data/array',
    'select2/utils'
    ], function (ArrayData, Utils) {
      /* tslint:disable */
        function CustomData ($element, options) :any {
            CustomData.__super__.constructor.call(this, $element, options);
        }
      /* tslint:enable */
        Utils.Extend(CustomData, ArrayData);

        CustomData.prototype.query = function (params, callback) {
          var result =  ymaps.suggest(params.term).then(function (items) {
          var data = [];
          var output = {
            results : [],
            more : false
          };
            for (var index = 0; index < items.length; ++index) {
                data.push({
                  id: String(items[index]['displayName']),
                  text: items[index]['displayName'],
                })
            }
            output.results = data;
            callback(output);
          });
        };

        $("#basic").select2({
            width:"100%",
            closeOnSelect:false,
            dataAdapter: CustomData
        });
        $('#basic').on('select2:select', function (e) {
          console.log(e);
          $('span.select2-search.select2-search--dropdown > input').val($("#basic").val());
        });
    });

when i try ng build, it says
ERROR in src/app/car/car-create/car.component.ts(43,28): error TS2339: Property '__super__' does not exist on type '($element: any, options: any) => any'.
How to solve this problem.
I tried to declare var CustomData: any; and /* tslint:disable */ before class export line
Answer: have you tried casting the CustomData object to any ?
(<any>CustomData).__super__.someprop...

or you can also give the CustomData a function interface (haven't tried it)
Here is an additional example for the functions interface:
interface CustomDataFN {
    (this: any, $element: any, options: any): any;
    __super__: any;
}

var CustomData: CustomDataFN = <CustomDataFN>function ($element, options): any {
    CustomData.__super__.constructor.call(this, $element, options);
}

CustomData.prototype....

for sure you can declare the interface with custom properties and types I just put in any to prevent compile errors.


How to install latest stable Drupal version from drupal/recommended-project branch?

Question: I've forked drupal/recommended-project and run composer install from the default branch (8.8.x), it installed the latest dev version (8.8.6-dev). There's also a tag 8.8.5 (latest stable as of now) which has the same composer.json with the exception of these lines:
    "require-dev": {
        "drupal/core-dev": "^8.8"
    },

I've deleted these lines in branch 8.8.x hoping this would install the latest stable version but it installed the dev version anyway. I don't want to use tags because I forked the upstream and have my own changes.
How can I install the latest stable version of Drupal from the default branch (8.8.x)?
Answer: Instead of forking and running composer install, you should run composer create-project drupal/recommended-project <project_root_dir>. This will install the latest stable version of Drupal and you can of course add this to your version control system (don't forget to exclude all files that you don't have to track in your VCS).
When you use the composer.lock file from the GitHub repository directly, Composer installs the software versions as defined in the lock file (in this case the development versions).
Comment: Thank you. Yes, I know that `composer create-project` would work but in my case, I need a fork.
Comment: @csandanov – Simply create the project and then do your changes afterwards.
Answer: I use a different one, drupal-composer/drupal-project and it installs the latest stable version.

Note: That as of Drupal 8.8.0 drupal-composer/drupal-project
  has been deprecated as an "official" source.
Note 2: But the project it self is not deprecated drupal-composer/drupal-project has [not] been
  deprecated

If you look at its composer.json
Under require it has
"require": {
    "drupal/core": "^8.8.0",
},
"require-dev": {
    "drupal/core-dev": "^8.8.0"
},

while yours doesn't; thus, this is why yours fetches the dev version.
Comment: As a side note, as of Drupal 8.8.0 the drupal-composer/drupal-project has "officially" [been deprecated](https://www.drupal.org/docs/develop/using-composer/using-composer-to-install-drupal-and-manage-dependencies#drupal-composer-drupal-project). Though, it provides a lot of tools you probably want to include in your project.
Comment: @Watergate correct, he'll need to use `composer update` rather than `composer install` so it doesn't follow the lock file.
Comment: I used `drupal-composer/drupal-project` before but now prefer to follow the official project. By the way it is NOT deprecated https://github.com/drupal-composer/drupal-project/pull/550
Comment: I'm still doing new sites from `drupal-composer/drupal-project`; I have used `drupal/recommended-project`, but in the end it looks just like a fresh `drupal-composer/drupal-project` once I got a good baseline set up for a real site.
Comment: I don't think that only changing the requirement for "drupal/core" from "^8.8" into "^8.8.0" is going to make any difference, if you keep the original lock file (of drupal/recommended-project). In that lock file the version for "drupal/core" is set to "8.8.x-dev" (with commit "3db6f1077351e63a8ba1d0fb858f0d942f41b938").
Comment: @Watergate deprecated... what a shame, ugh `drupal/recommended-project` looks so barebones.


Reading data from European DTCO company card

Question: I need to be able to read card and company identification data from European digital tachograph company cards (smart cards). These are described within the document COMMISSION REGULATION (EC) No 1360/2002 but I have run into a problem. The data I need to be able to read is contained within the file EF Identification, which must be read with secure messaging and I therefore need to issue a Manage Secure Environment APDU command that requires a key identifier that identifies a key residing on the card.
I don't know where to find these key identifiers or the data that makes them up (described in an appendix of the document). I am waiting for feedback from our partners in Europe but thought I would take a chance an ask here in the hope that someone will have done this and be able to offer some advice.
The key identifier is made up of an equipment serial number, a date, a manufacturer code and a manufacturer specific type. This suggests a problem as I need to be able to access the data from any company card, regardless of manufacturer, issuer or holder. Not sure how I can get the data to compose the key.
I realise that this is pretty specialised information but have been stalled for over a week so am pretty desperate to find a solution so I can continue.
Answer: I don't know the standard, but I would assume that you read out EF Card_Certificate, recover the certificate content and extract the key identifier from that.
Assuming you have the root certificate (it is published here: http://dtc.jrc.it/erca_of_doc/EC_PK.zip), you will need to:

Read EF CA_Certificate
Follow the algorithm in Appendix 11, section 3.3.3
Extract the CA public key from the certificate content
Read EF Card_Certificate
Follow the algorithm in Appendix 11, section 3.3.3
The Key Identifier should now be byte 20-27 of the recovered certificate content.
Comment: @Steve Crane: I believe the root certificate is the one published by ECRA.
Comment: I wondered if that would be possible. I can already read the Card_Certificate and I'll dig through the specification and see if it contains the identifier I need.
Comment: @Steve Crane: I skimmed through the standard and added a few more pointers.
Comment: Thank you, this is most helpful. Trying to follow that standard is not too easy if you aren't familiar with working with smart cards, keys and certificates.
Comment: Making some progress but still struggling a little. When you said "Assuming you have the root certificate", does this mean we need to have a certificate from somewhere other than the card in order to complete the authentication process? I don't have such a certificate. How do you get one? As we are writing an application that needs one, do we need to request that some authority issue us with one?
Comment: Thanks, found it on the [European Commission - Digital Tachograph website](http://dtc.jrc.it).
Comment: Despite all the advice you have given I'm still struggling with this. I don't have enough understanding of the cryptographic code needed to follow the algorithm in Appendix 11, section 3.3.3. Most of the steps are simply retrieving segments of byte arrays and I can do that. The steps I can't work out how to do are, **open Sign with CA Public Key: Sr¡ = X.CA.PK [Sign]** and **check Hash(C¡) = H¡**. How to **open Sign** and **compute Hash**? The only colleague of mine with experience in this area doesn't know; says the document is confusing and worded strangely. I'm almost ready to give up!
Comment: For days now I have been Googling for sample code and trying to apply it but am at a loss. Nothing I try seems to work, undoubtedly because I don't fully understand it.
Comment: @Steve: It means use the CA public key to perform a raw RSA encryption of `Sign` (the first 128 bytes of X.C). Later calculate the SHA-1 hash of the full certificate and verify that it matches the H' extracted from the result of the decryption. If you need more help, I think you should make a new question (remember to note which programming language you are using). If you make a comment about the new question here, I will be sure to try to help.
Comment: @Steve: Ah, you already made a new question. I will take a look unless it has already been answered.
Comment: @Steve: I have made another better answer. I will wait a bit then delete this one.
Answer: I believe that you first have to obtain a certificate from a country CA. You can then perform the following algorithm (simplified from Appendix 11, section 4):

Select and read the card certificate (EF_CERTIFICATE)
Issue a Manage Security Environment command to select the Root CA public key
Issue a Verify Certificate with the country CA certificate
Issue a Manage Security Environment command to select the country CA public key
Issue a Verify Certificate with your certificate
Issue a Manage Security Environment command to select your public key
Issue an Internal authenticate command. Verify response.
Issue a Get Challenge command
Issue an External authenticate command
Calculate the session key
Select File EF_IDENTIFICATION
Perform a Read Binary command using secure messaging (you need the session key to calculate the checksum and decrypt the result).
Comment: Thank you for your help but it turns out, and we learned this only yesterday, that we have no need to do any of this. The application we have been commissioned to replace does not access the secure information on the card but uses an open non-application-related serial number (cardExtendedSerialNumber from EF ICC) to identify which card is in which reader and uses this with the user-entered application-specific card number to create a table that can be used to address the reader containing a specific card. We have been told to simply do the same.
Comment: @Steve: Ah, much simpler. Thank you for posting a follow-up.


Multi Label Semantic Segmentation - One class is way behind

Question: I'm trying to build a Multi-Label Semantic Segmentation model, but while training, when I'm looking at the validation set, I can see that one label is far far behind, and in the end, he is not getting good results.
I'm using a U-net model with resnet50 backbone, tried categorial-cross-entropy loss, dice-loss, jaccard loss, but couldn't find a way to leverage this class.
I tried to give this class more weight in the loss function, I even tried to give this class over 90% and still the states were low.
Someone have any Idea, method, a way of action, even tricks from his experience to help me with that issue? is it a common problem? or I need to check my basics?
Answer: When using multiple classes in segmentation, one must pay attention to the classes' representation in the data-set. The first thing to do would be to check the confusion matrix and see if the class that's falling behind gets confused with another class. If it is confused with a particular class then the issue is probably coming for the data set. However, if the class representation seem correct, you should check out the model itself.
I've worked with a similar U-net model for the same purpose and have used a manually weighted L2-loss and it seemed to do the trick. Maybe you can try that.
Another thing you can try out is to load encoder weights (for resnet50) pre-trained on ImageNet (They can be found online), this will ease your model recognition of the said class.
Hope this can help !


changing track color between 2 Slider handles

Question: I am using Script.aculo.us Slider.js to display dual sliders. It working perfectly.
what I want to do is to change the color to track only in between these two slider.
For example if 1st Slider is on value 5 and 2nd is on value 8. I want that the track fron 5-8 is green and the rest is gray. to simulate king of selected range.
Is it possible?
Answer: I have figured it out, it is possible by using 2 options properties
startSpan and endSpan.
Maybe it is useful for someone else I am pasting here sample HTML snippt and javascript

and javascript
new Control.Slider(this.options.handles, 'slider-week-track', {
                        range:$R(0,10, false),
                        sliderValue: [1,5],
                        values: [0,1,2,3,4,5,6,7,8,9,10],
                        restricted: true,
                        startSpan: 'span1',
                        endSpan: 'span2',
                        onChange:   function(val) {
                            //your code here
                        }
        });


On a 3-tier app, is necessary unit testing on the visual tier?

Question: In my app, dozens of PCs will be running the visual tier. The business tier will be located on the server, that also contains the database.
Unit testing is really necessary on my visual tier, that basically will contain calls to the business tier? Any particular case?
Answer: Testing for the sake of testing is never the right reason to test.
Answer: unit test are necessary on any tier you are deploying code. The integrity of all of your code should be upheld by unit tests regardless of the tier.
Answer: UI tests are seldom called unit tests because it is really difficult to test a unit of code. In the past we called them integration tests, sanity tests, functional tests or acceptance tests. Essentially they verify the system (not a unit of code) works after it was deployed. But this is debatable based on what you are trying to achieve.
Whether or not to automate the UI tests depends on several factors. The hourly rate of developers is often far more than that of QA. So one has to look at what value automated tests written by a developer provide to the whole organization. The hour a developer spends writing tests may be better spend adding value to the system. However, QA very seldom look at the system from a unit perspective, leaving them at a disadvantage.
However, developers has an intimiate knowledge of the system and therefore can increase quality a great deal if they write tests. Tests act as documentation for other developers and express intent. Finding issues sooner is cheaper and the most compelling motivation for a developer writing tests.
So you need to strike a balance between the two. Developing and maintaining any kind of UI tests are time consuming and complex, especially in distributed environments. UI tests are often unreliable and break easily. You have to consider provisioning the environment, seeding the database and so forth. You also need to consider whether you have enough resources to run automated tests. It also becomes expensive.
You can reduce costs by outsourcing it, or by doing it manually. The latter may be faster to repeat each time than going through the cycle of creating, maintaining, running and diagnosing automated UI tests.
That said, if your UI is stable, it is very advantageous to have a couple of acceptance tests to verify that the system is functional. Look at the 20% features that are used 80% of the time and those features in the UI that if not functional will render the system useless.  At least you'll know that the 20% everyone, including your boss or customer, cares about is working before giving to QA or a customer for testing.
Comment: "...on my visual tier, that basically will contain calls to the business tier..." implies some code will be deployed to the UI tier. as a result, it's good practice to develop integration tests for that code as well as leverage a mocking framework to develop true unit tests. he did not specify the technologies but an MVC app for example would have view logic in client side javascript and controllers on the web server that would require unit testing.


How can I decrypt ssl encrypted mongo wire protocol for inspection when I have ownership of all certificates involved?

Question: I have a standard MongoDB SSL environment where the mongo wire protocol is encrypted with SSL/TLS using RSA keys. I have packet captures of communication between the MongoDB server and a client taken via tcpdump. I have ownership of the certificates involved in the encryption.
I have a capture of the handshake, and DHE / ECDHE / PFS is not at play in this scenario.
How can I decrypt the information in the existing packet captures to inspect the contents of the mongo wire protocol portion of the packets?
Comment: If your cipher suites were configured properly for forward secrecy, then you shouldn't be able to.
Comment: If you don't have PFS active, then something like http://www.rtfm.com/ssldump/ could help.  There's no easy way to select a given packet/dump and decrypt it without some heavy coding though. Regardless of method, you also need the session keys, which means having a dump of the handshake.
Comment: @Hyppy Correct, I do have the handshake as well.
Comment: What was the chosen cipher suite in the ServerHello in the packet capture?
Answer: You almost certainly can't because of forward secrecy.
MongoDB, for some reason, has a hardcoded SSL cipher list of HIGH:!EXPORT:!aNULL@STRENGTH. What this results in depends on the version of OpenSSL it was built against, but on a modern system will result in ciphers that use forward secrecy being preferred over those that don't.
You can see the generated cipher list on the target system with:
openssl ciphers -v 'HIGH:!EXPORT:!aNULL@STRENGTH'

When the SSL/TLS connection uses forward secrecy, it is impossible to decrypt the session, even if you have the SSL certificate private key. This is the whole point of forward secrecy; it prevents past sessions from being decrypted even if an attacker (whether it be you or a criminal or the NSA) gains control of your private key.
Comment: `s_client` pointed at this specific instance is showing `New, TLSv1/SSLv3, Cipher is AES256-SHA` so I don't think forward secrecy is in play.
Comment: @Wesley In that case, find the server admin and beat him senseless until he fixes the problem.


How to prove Rubinstein's Bargaining Game with Random (instead of Alternating) Offers?

Question: Ariel Rubinstein introduced in Econometrica, 1982 the canonical model of bargaining, which I describe below.

Two Players $i,j\in N$ bargain over how to split \$1. Both Players have linear (discounted) utility functions $u_i=\delta^{t-1}x_i$ and $u_j=\delta^{t-1}x_j$. The bargaining procedure is as follows: one Player is chosen to make an offer $(x,1-x)$ to Player $j$, who then accepts or rejects. If he accepts, the game ends and Player $i$ gets $u_i=x$ and Player $j$ gets $u_j=\delta^{t-1}(1-x)$. If he rejects, he makes an offer $(1-y,y)$ to Player $i$, who then accepts or rejects. If he accepts, the game ends and Player $i$ gets $u_i=\delta^{t-1}(1-y)$ and Player $j$ gets $\delta^{t-1}y$. If he rejects, he makes an offer $(x^{\prime},1-x^{\prime})$ to Player $i$ and so on. The game ends whenever Players reach an agreement; if they never do so, they get $u_i=0$ and $u_j=0$.

The unique Stationary Subgame Perfect Equilibrium (SSPE) of this game is well-known and several explicit proofs can be found out there. Because of that, let me just remark that, in the unique SSPE of the game described above, an agreement is reached at $t=1$ and has the following form:
\begin{gather*}
x=\frac{1}{1+\delta}\\
1-x=\frac{\delta}{1+\delta}
\end{gather*}
Consider now the canonical Rubinstein bargaining model described above with a small tweak:

Following any rejection, Nature randomly chooses the identity of the next proponent.

Hoel analyses the game I am considering in Economics Letters, 1987 and claims that the unique SSPE is almost identical to the one of the Rubinstein canonical bargaining game. However, he does not provide an explicit form of the Equilibrium proposals nor he provides an explicit proof of his claim (I'm not blaming him; it's probably a fairly easy claim to show that I just can't see). Instead, he argues that his claim can be derived following the results in Shaked & Sutton in Econometrica, 1984 and in Hoel in Scandinavian Journal of Economics, 1986. Unfortunately, I have thoroughly tried to derive an explicit proof of his claim, but I haven't succeeded at all so far.
Therefore, my question is: could anyone please derive the Stationary Subgame Perfect Equilibrium of the tweaked Rubinstein game I am considering? (note: you don't need to check whether there exist non-stationary Subgame Perfect Equilibria).
EDIT: given the null success of my question so far, I link here a clarifying video of 15 minutes that explains how to solve the canonical Rubinstein model presented above. Then, my question could be re-phrased as follows: how do I need to change the proof in this video for my modified version of the Rubinstein Bargaining Game?
Thank you all very much in advanced for your time.
Comment: Is it enough for you to have a solution where both players have the same discount factor $\delta$? It can extended to different discount factors, but it makes writing the solution down a tad simpler.
Comment: Thank you very much for your comment. Yes: it is sufficient for me that both Players have the same discount factor $\delta$. I'm trying to analyse the random Proponent protocol in its simplest scenario: namely, with complete and perfect information and with a symmetric discount factor $\delta$. I've been stuck here for so long, that any help will be SUPER appreciated.
Answer: Suppose that the two players have the same discount factor and use stationary strategies.
At time $t$, when it's $i$'s turn to propose, she proposes $m_i$ to the receiver $j$. If the receiver accepts, she keeps $1-m_i$.
The receiver $j$ accepts $m_i$ if this value is not smaller than what she may get waiting one period: with probability $1/2$, she will be proposer and get a value $(1-m_j)$; with probability $1/2$, she will be again receiver and will be offered $m_i$ again. Discounting the expected value from the next period, she accepts an offer $m_i$ when
$$m_i \ge \delta \left( \frac{1}{2} (1-m_j) + \frac{1}{2} m_i \right)$$
Since the proposer $i$ offers the minimum amount $m_i$ necessary for acceptance, we get
$$m_i = \delta \left( \frac{1}{2} (1-m_j) + \frac{1}{2} m_i \right)$$
Switching identities, we obtain the second equation
$$m_j = \delta \left( \frac{1}{2} (1-m_i) + \frac{1}{2} m_j \right)$$
Solving the system, we find
$$m_i = \frac{\delta}{2} \quad \mbox{and} \quad m_j = \frac{2 - \delta}{2}$$
as equilibrium offers. The offers are accepted in the first period and the two players obtain
$$u_1 = 1 - m_i = \frac{2 - \delta}{2} \quad \mbox{and} \quad u_2 = \frac{\delta}{2}$$
Incidentally, you can check that these are the same values you obtain if you replace $\delta$ with $\delta/(2 - \delta)$ as claimed (without proof) in Hoel (1987).
Comment: Can I give you +1,000,000 points for this? You enlightened in a way you cannot imagine the path for my Thesis.


Problema ao tentar acessar meu notebook com meu Android pelo IPv4!

Question: Galera, eu estou com um baita problema e ele já me deu dor de cabeça. Eu fiz uma aplicação com o Magic Software e para rodar ela no meu Android tenho que configurar o Magic Studio da maneira certa (já feito), executar o projeto no servidor do Magic (feito e funcionando) e instalar o MagicDev.apk no android (disponível na pasta do Magic XPA e já feito), sendo que ao terminar de instalar, o aplicativo deve ser rodado e ao ser executado ele pede pra digitar a URL da aplicação do Magic, que é o seguinte:
    http://[IPv4_do_notebook]/MagicScripts/DevProps.txt,
mas ao tentar acessar isso, não é possível, fala que a aplicação não foi encontrada ou falhou na conexão. Vale notar o seguinte, eu tinha esse mesmo problema de acesso quando usava o XAMPP ou o Wamp, pois ao tentar acessar o localhost com o celular, o link não respondia, ficava carregando até dar a mensagem (colocava o Wamp online para isso, claro, e mudava as configurações nos arquivos.conf). Outra coisa importante é que fiz um aplicativo para Android no Android Studio em que uma das suas funções era acessar a internet e, embora o aplicativo instalado no Android de verdade não conseguisse se conectar ao link, o emulator acessava tranquilamente (o emulator roda dentro do pc, teria algo haver?) e conseguia fazer o que tinha que fazer, sendo que esse link dava em uma página que fiz usando o Wamp, ou seja, o emulator acessava meu IP, e o celular não consegue. Minha dúvida: isso é alguma configuração do notebook, do Android, do roteador da internet ou estou fazendo algo errado? Meu amigo criou uma página usando o Wamp, o configurou certo e colocou Online e da minha casa, com o IP dele, acessava a página (com meu notebook) de forma tranquila. Mais uma observação, meu notebook se conecta à internet com Wifi e o meu Android também, ou seja, eles não estão conectados à fonte de forma direta como o meu PC da sala está, e não sei se isso também importa. Vou mais tarde tentar roda a aplicação no meu PC da sala e ver se com ele dá para acessar pelo IPv4 dele, mas creio que também não funcionará. Enfim, alguém tem alguma ideia do que pode ser? Não gosto de ficar mexendo nas configurações do meu notebook com relação à internet e outras coisas sem saber o que estou fazendo de fato, tenho medo de deixar meu notebook vulnerável.
    Aqui nesse vídeo https://www.youtube.com/watch?v=1njzFq07t2U dá para ver o processo que estou descrevendo aqui, mas não está funcionando para mim.
Preciso urgentemente de ajuda, por favor!!!
Andei pesquisando nos fóruns em inglês e vi que talvez possa ser culpa do firewall. Alguém sabe?
Answer: Galera, já descobri, era culpa do firewall mesmo. Quando desliguei tudo funcionou como o esperado. Não posso ficar com ele desligado por questões de segurança, mas pelo que vi dá para configurá-lo para aceitar só o meu celular.
Não entendo o motivo dos votos negativos para minha pergunta, já que acho pertinente e pelo que vi, ninguém conseguiu responder, muito obrigado por isso. Votaram contra, mas esses bonitos não responderam nada, então criem vergonha na cara, seus gênios!!!!


How to approachfor fit, train and test the Customer Lapsing Machine learning model

Question: I was exploring the options to design the approach to train test and predict the customer lapsing model.
Description:
Lapsed => Customer didn't purchase an item in the financial year (ex: Customer A didn't purchase any item in 2010 => Customer A is lapsed in 2010)
Say, I have list of 500 customers and 9 years of the data which tells whether customer lapsed or not (from 2000 to 2009 and I have to predict for 2010)

Data Format

<code> Customer_id x1 x2 x3 lapsed_2001 lapsed_2002 ... lapsed_2009
   A          a  b  c   0           0               1
   B          p  q  r   1           0               0
</code>

I'm considering two options to model this

Option A:
      Use all of the 500 Customers data make lapsed_2008 as Predictor                        Training Variable to fit the model and train the model. Now Test using lapsed_2009 Variable.
Option B:Use 375 Customers data make lapsed_2009 variable as Training variable and test for the rest of 125 Customers

Can anyone please explain me which approach to be followed and why ?
Answer: You can use either of the approaches based on kind of data you have(I'm assuming you can get more data) -

If the variables about the customer are not changing significantly
with respect to time then you can use option A. e.g., age group,
gender or education or customer loyalty categories
Keep in mind that you will have to adjust time dependent factors like
income or purchase history, e.g., Bucket of renewal streak instead of
columns like less than 1yr, or 5+ years
If your model is to be based on just buying pattern across years
then you should use Option B
Option B is essentially survival analysis
In some business cases renewal/lapse data is not a best predictor for
future

Survival analysis using R -
http://dni-institute.in/blogs/survival-modeling-tutorial-using-r-part-1/
Churn prediction (if you have more customer data) -
https://josepcurtodiaz.gitbooks.io/customer-analytics-with-r/content/chapter9.html
Answer: I recommend using option A and modify your dataset a bit differently.
For each year, represent the customer as of that point in time to create positive and negative response cases. This would give you more data to train and cross-validate.
For example, if you're recording age as a demographic attribute then record age as of that particular year and update it if you have the same record showing up for another year with the age as of that year.


Why implicit function theorem fails for a composite function?

Question: Suppose I have $ax +b =c$. I can solve $\partial x/\partial c$ by IFT assuming that $a,b$ are constants and $x,c$ are variables: let $F= ax +b -c$. Then, $$\partial x/\partial c = -F_c/F_x =1/a$$
Now it's also true that $e^{ax +b}= e^c $, but when I apply IFT to $F'=e^{ax +b}- e^c$, I get the wrong derivative:
$$\partial x/\partial c = -F'_c/F'_x =\frac{e^c}{a e^{ax+b}} \neq 1/a$$
Can you tell me where am I making a mistake in the calculations?
A montone transformation of both sides of the original equality should not change the result.
Comment: But that is $\frac 1a$ since $e^c=e^{ax+b}$.
Comment: Note:  it's hard to follow what you have written since it is hard to tell which terms are variables and which are constant.  I guess $c$ is a variable  (since you are differentiating with respect to $c$). But what of $a$ and $b$?
Comment: a,b,c are constants. So your comment solves my question. I think it would be nice to have a one or two lines proof that a monotone transformation of both sides of the equality doesn't matter for applying IFT.
Comment: That does not make sense.  If $a,b,c$ are constant, then so is $x$ (as it is equal to $\frac {c-b}a$).  Hence all deriviatives of $x$ must vanish.
Comment: I mean I want to study the derivative of x(a,b,c) defined implicitly by an equality, and  a,b,c are parameters.
Comment: So...$a,b,c$ aren't constant?  This is all very vague.  Please edit your post for clarity.
Comment: In my comment I assumed that $a,b$ were constants and that $x, c$ were variables.  I don't see what else makes sense here.
Answer: So thanks to lulu's comment I solved my doubt.
Indeed $e^c = e^{ax + b}$ by my initial equality. So $-F'_c/F'_x = 1/a.$
A bit more generally, knowing that $$f(ax + b) = f(c),$$ we can compute $\partial x/ \partial c$ by applying IFT to $F' =f(ax + b) - f(c)$:
$$ \partial x/ \partial a = - \frac{-f'(c)}{f'(ax + b) a}= 1/a. $$
$f'(c) = f'(ax + b) $ follows by differentiating both sides of the first displayed equality.


Why doesn't the overlay background show?

Question: I created a fancybox gallery as block using the Views module and inserted that block into the node using the Insert Block module. Everything works fine, but the overlay background doesn't show.
How do I fix this?
Edit: The problem has been resolved: The 'Overlay helper' was disabled.
Answer: The problem has been resolved: The 'Overlay helper' was disabled.


Parse error in PHP? Error on line 4?

Question: I am not sure what my parse error is? The html file linked to this file does have the proper file associated with it. I complete the html file form and it shows the proper path to my php file but gives me a parse error on line 4?
<?php
    $month = $_GET["month"];
    $color = $_GET["color"]
    $colorFortune = color_fortune($color);
    $fortune = yourFortune($month);

function yourFortune($month)
{
    if (strtoupper($month) == "JANUARY") {
        return "all of your New Years resolutions will come true!";
    }
    elseif (strtoupper($month) == "FEBRUARY") {
        return "you will fall in love with a special someone!";
    }
    elseif (strtoupper($month) == "MARCH") {
        return "luck will shine upon you!";
    }
    elseif (strtoupper($month) == "APRIL") {
        return "a golden egg of opportunity will fall into your lap.";
    }
    elseif (strtoupper($month) == "MAY") {
        return "never fear! The end of something marks the start of something new.";
    }
    elseif (strtoupper($month) == "JUNE") {
        return "the sun will shine on you if you let it.";
    }
    elseif (strtoupper($month) == "JULY") {
        return "you can't steal second base and keep your foot on first.";
    }
    elseif (strtoupper($month) == "AUGUST") {
        return "you will be sharing great news with all the people you love.";
    }
    elseif (strtoupper($month) == "SEPTEMBER") {
        return "you have the power to write your own fortune.";
    }
    elseif (strtoupper($month) == "OCTOBER") {
        return "you will be successful in your work.";
    }
    elseif (strtoupper($month) == "NOVEMBER") {
        return "you will enjoy good health; you will be surrounded by luxury.";
    }
    elseif (strtoupper($month) == "DECEMBER") {
        return "you will make change for the better.";
    }
    else {
        return "Error: You didn't enter your birth month!";
    }
}

function color_fortune($color)
{
    if (strtoupper($color) == "RED") {
        return "Your ambitions will become real and ";
    }
    elseif (strtoupper($color) == "BLUE") {
        return "You will experience trust and loyalty in your life and ";
    }
    elseif (strtoupper($color) == "PINK") {
        return "You will experience unconditional love and ";
    }
    elseif (strtoupper($color) == "PURPLE") {
        return "Your creativity will shine through and ";
    }
    elseif (strtoupper($color) == "WHITE") {
        return "You will acheive a sense of wholeness in your life and ";
    }
    elseif (strtoupper($color) == "BLACK") {
        return "You will uncover a mystery of life and ";
    }
    elseif (strtoupper($color) == "ORANGE") {
        return "You will meet new people that will bring otimism to your life and ";
    }
    elseif (strtoupper($color) == "GREEN") {
        return "You will find a four leaf clover that will bring you luck, balance, growth, and ";
    }
    elseif (strtoupper($color) == "YELLOW") {
        return "You will learn new skills that will help you advance in your career ";
    }
    else {
        return "I don't know that color! But, ";
    }
}
?>

<!DOCTYPE html>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<title>Your Fortune</title>

<?php echo $colorFortune . $fortune; ?>

Comment: don't believe everything PHP says; it's not on *that* line.
Comment: Line 3: `$color = $_GET["color"]    //missing ;`
Comment: Thank you! That was a big part of the problem. I was staring at line 4 thinking what is wrong with this.
Answer: $color = $_GET["color"]

missing ;
Comment: I feel like a dumb dumb! Thank you!!!
Comment: Eh. Happens to everyone now and then.

Parse error in PHP? Error on line 4?


npm ERR! file WindowsPowerShell\v1.0 while npm node-sass on Windows 7

Question: Happen to encounter following error's while install node-sass using npm on Windows 7
12689 verbose stack Error: email@example.com postinstall: `node ./lib/index.js`
12689 verbose stack spawn C:\Windows\system32\cmd.exe;C:\ProgramData\Oracle\Java\javapath; ENOENT
12689 verbose stack     at exports._errnoException (util.js:1036:11)
12689 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
12689 verbose stack     at onErrorNT (internal/child_process.js:359:16)
12689 verbose stack     at _combinedTickCallback (internal/process/next_tick.js:74:11)
12689 verbose stack     at process._tickCallback (internal/process/next_tick.js:98:9)
12690 verbose pkgid firstname.lastname@example.com
12691 verbose cwd C:\Windows\System32
12692 error Windows_NT 6.1.7601
12693 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--global" "firstname.lastname@example.com"
12694 error node v6.6.0
12695 error npm  v3.10.3
12696 error file C:\Windows\system32\cmd.exe;C:\ProgramData\Oracle\Java\javapath;
12697 error path C:\Windows\system32\cmd.exe;C:\ProgramData\Oracle\Java\javapath;
12698 error code ELIFECYCLE
12699 error errno ENOENT
12700 error syscall spawn C:\Windows\system32\cmd.exe;C:\ProgramData\Oracle\Java\javapath;
12701 error email@example.com postinstall: `node ./lib/index.js`
12701 error spawn C:\Windows\system32\cmd.exe;C:\ProgramData\Oracle\Java\javapath; ENOENT
12702 error Failed at the email@example.com postinstall script 'node ./lib/index.js'.

Answer: Had to completely remove the ComSpec variable from Environment Variables to get this installed.
Reference from github ticket.


Comparing Statements and predicates using Truth Tables

Question: Consider the four statements:

$∃x$ $∀y$ $p(x, y)$
$∃y$ $∀x$ $p(x, y)$
$∀x$ $∃y$ $p(x, y)$
$∀y$ $∃x$ $p(x, y)$

which we call S1, S2, S3 and S4 respectively.

Does there exist a predicate p such that S1 and s4 are true, but S2 and s3 are false?
Does there exist a predicate p such that S2 and s3 are true, but S1 and s4 are false?
Does there exist a predicate p such that S3 and s4 are true, but S1 and s2 are false?
Does there exist a predicate p such that S4 is true, but s1, S2 and s3 are false?

Solution:
Consider the four predicates:

One can verify that:

if we take p to be p1, then S1 and S4 are true, but S2 and S3 are false
if we take p to be p2, then S2 and S3 are true, but S1 and S4 are false
if we take p to be p3, then S3 and S4 are true, but S1 and S2 are false
if we take p to be p4, then S4 is true, but S1, S2 and S3 are false

Here are my questions:

Is my diagram correct (I highlighted the different sections)?

What is the structure of p1? How do you READ this table? Where is the INPUT? Where is the OUTPUT?
How does p1 get fed into $∃x$ $∀y$ $p(x, y)$?
How can I come up with p1?
What is the significance of the row with #2 (highlighted in blue)?
Answer: You have to read the "matrix" : $p_1, p_2, p_3, p_4$ as interpretations for the predicate letter $p$ that is $T/F$ according to the values assigned to the variables $x$ and $y$ respectively, where the values of $x$ must be read on the left and the values of $y$ on top.
Consider e.g. $S_1 : ∃x ∀y p(x,y)$, and consider the matrix $p_1$.
Is it true that there is a value for $x$ such that $p(x,y)$ is $T$ for all values for $y$ ?

YES. Consider $p_1(0,y)$: it is $T$ for both values : $0,1$ for $y$.

Thus the predicate $p_1$ satisfy the formula $S_1$.
The same for $S_4$, and these results are consistent with the solution 1: "if we take $p$ to be $p_1$, then $S_1$ and $S_4$ are true, but $S_2$ and $S_3$ are false".

Note
In principle, the approach is the same IF we have to read the "matrix" in the other "direction" (as suggested by you : with the values for $x$ on top and the values for $y$ on the left) : but in that case, you can see that now the predicate $p_1$ does not satisfy the formula $S_1$.
But in the same way, you can verify that $p_2$ satisfy $S_1$.
Comment: Ohh so I have x and y both switched, thanks for clarifying that. Now what about the row 2? What's the significance?
Comment: @lucidgold - I presume that **you** have highlighted it ... It has no particular significance. The author of the test has decided to design 4 different models (the $p_i$s) based on a common domain of 6 couples...


Pattern in residual plot

Question:
I am still learning about regression and I am currently trying to perform some basic analysis on my experimental data but I do not know how to deal with or interpret this obvious linear line in my residual plot.
How should I go about dealing with this pattern in my analysis?
The data is from microbiological counts which have had a log transformation applied. I have also used a Gaussian distribution in my analysis as I assume I need a continuous distribution if I apply a log transformation.
Comment: It appears you did not actually take the log of the count, but rather the log of one plus the count.  Since you have plenty of small counts, your data are not suitable for ordinary least squares regression.  Have you considered a Poisson model?  Compare your plot to the one at https://stats.stackexchange.com/questions/25068/interpreting-plot-of-residuals-vs-fitted-values-from-poisson-regression.
Answer: I bet that line is from data points which have 0 counts.  I would recommend switching from linear regression to poisson regression and reassessing residuals after.

Pattern in residual plot


Prove that $K=\cup_{n=1}^\infty K_n$ is compact

Question: Considering $\mathbb{R}^2$ with the standard metric. Suppose that, for each integer $n\geq 1$, there is a compact set $K_n \subseteq \mathbb{R}^2$ and a point $x_n \in\mathbb{R}^2$ such that:

$K_n \subseteq B(x_n, 2^{-n})$
the sequence $(x_n)_{n=1}^\infty$ converges to a point $x \in K$

Prove that $K=\cup_{n=1}^\infty K_n$ is compact.
I know that the infinite union of compact sets is not necessarily compact, so I would like to know where that fails and why the fact that the sequence of the centres of the sets that bound each $K_n$ fixes that. I want to use the Heine-Borel theorem in $\mathbb{R}^n$ and therefore to prove that $K$ is closed and bounded, and have thought to say $K \subset B(x_1, ||x1-x||+1/2)$, but do not see why I can say that the set is closed.
Comment: The key here will be that the points converge to a point in the union. Without that, the union need not be compact.
Comment: That is what I fail to understand, why is it so important that (as far as we know) only one sequence converges to a point in the union? Is that general for any compact union?
Comment: A sequence which visits infinitely many $K_n$ will have a subsequence that converges to $x$. That's the idea here... any other sequence is already contained in a compact set $\bigcup_{n=1}^N K_n$ for some $N$, so has a convergent subsequence.
Answer:
I know that the infinite union of compact sets is not necessarily compact, so I would like to know where that fails and why the fact that the sequence of the centres of the sets that bound each $K_n$ fixes that.

Let's see. So why would an infinite sequence of compact sets not be compact? By the Heine Borel theorem,

That union could be unbounded, even though each set is bounded. That's very clear, take say $\mathbb R = \cup_{n \geq 1} [-n,n]$. What you see is that $\mathbb R$ is unbounded basically because even though each set is unbounded, there is a point in each set that lies outside any particular fixed bound you give me. For example, you give me $74$ but then $[-75,75]$ is in the union.

The best way of phrasing the above is that $\cup_{i=1}^{\infty} K_i$ won't be compact if there exists a sequence $y_i \in \cup_{i=1}^{\infty} K_i$ such that $\|y_i\| \to \infty$, because that's what you get by contradicting boundedness.

That union need not be closed, even though each set is closed. That's clear by taking $[0,1) = \cup_{i=1}^{\infty} [0,1-\frac 1{i}]$. The problem here is that if you take a sequence which doesn't converge in the union (or a limit point lying outside the union), then that sequence is something created out of an element in each set.

The best way of phrasing the above is that $\cup_{i=1}^{\infty} K_i$ won't be compact if there exists a sequence $y_i \in \cup_{i=1}^{\infty} K_i$ such that $y_i$ converges to a point outside $K$ (a limit point of $K$ lying outside $K$), because that's what you get by contradicting closedness.

So how do you work? You have two tasks :

Make sure that every sequence is bounded (by the same constant). This will make the whole set bounded.

Make sure that every sequence is converging to a point inside $K$. This will make the set closed.

But what about the structure of the given set does this?

The answer to both questions centers around the fact that $x_i \to x$, where $x_i$ are the centers of the balls.
Because this occurs, the maximal distance of $x_i$ from $x$ is something that is bounded i.e. $\sup_{x \geq 1} \|x_n-x\| = M < \infty$.
For boundedness, one can use the triangle inequality : if $y \in \cup_{i=1}^{\infty} K_i$, and say that it belongs to $K_j$, then
$$
\|x-y_j\| \leq \|x-x_j\|+ \|x_j-y_j\| \leq M+2^{-j} \leq M+\frac 12.
$$
I believe you attempted this argument, except that you probably assumed that $\sup_{x \geq 1} \|x_n-x\|  = \|x_1-x\|$ (because it feels like $x_1$ is the "furthest" from $x$). This need not be true, but the maximum I took is what is to be done, leading to the answer.

As for closedness, there's something very nice happening here. See, suppose that you have a "bad" sequence which converges outside $K$. As mentioned earlier, that bad sequence has to have elements from all the $K_i$, so that some kind of "overflow" occurs. What we're doing, by ensuring that $K_i \subset B(x_i,2^{-i})$, is that the possibility of that bad subsequence to go haywire is becoming smaller, because the sets $K_i$ are themselves becoming smaller.
So a bad sequence has to not converge, but it also has to somehow belong to each $K_i$ for some $i$. That makes that bad sequence's possibilities continuously shrink : and because your $K_i$s are going to shrink to a point (which is $x$), it turns out that bad subsequence can only go to $x$!
Let's see how. Suppose that $y_i \in \cup_{i=1}^{\infty}$ is any sequence. Then, it is possible to see that one of the following is true :

Either, there is some $M>0$ such that $y_i \in \cup_{i=1}^{M} K_i$ for all $i$, OR

There is a subsequence of $\{y_n\}_{n \geq 1}$, call it $y_{n_k}, k \geq 1$ such that $y_{n_j} \in K_j$ for all $j \geq 1$.

In the first case, obviously $\cup_{i=1}^{M} K_i$ is compact, so $\{y_i\}$ will converge to a point within that set itself, if it converges somewhere.
On the other hand, if we have the subsequence $y_{n_j} \in K_j$ for all $j \geq 1$, then keep in mind that $y_{n_j}$ will converge to the same point as the original sequence $y_n$.
However, because of what I said earlier, we are well within our rights to expect that $x$ is the limit of the $y_{n_j}$, and knowing that, we simply execute the triangle inequality :
$$
0 \leq \|x-y_{n_j}\| \leq \|x-x_{n_j}\| - \|x_{n_j} - y_{n_j}\|\leq \|x-x_{n_j}\|+2^{-n_j}.
$$
By the squeeze theorem, $\|x-y_{n_j}\| \to 0$, so $y_{n_j} \to x$. Thus, $y_n$ is a convergent sequence, which has a subsequence that converges to $x$. The only possibility left is that $y_n$ converges to $x$ as well, an easy exercise.
And since we assumed that $x \in K$, as part of the second point, we are able to handle the "bad" sequences by forcing them all to go to the exceptional point $x$.
Note that if $x \in K$ then the bad sequences won't have a limit point and one can get a counterexample. This hopefully explains the question, the principle behind solving it, and how it's actually done, modulo basic some details I leave readers to fill in.
Comment: Wow, this is extremely thorough and precise. Thank you for the detailed explanation.
Comment: @AlexA.G. You're welcome!
Answer: Let $\left\{y_m\right\}$ be a sequence in $K$. If every $K_n$ contains only finitely some $y_m$'s, then choose a $y_{m_1}$ belonging to some $K_{n_1}$. Suppose that we have determined $y_{m_1},y_{m_2},\cdots,y_{m_k}$, as $m_1<m_2<\cdots<m_k$ and $n_1<n_2<\cdots<n_k$. Now, since $\left\{y_m\right\}$ lies in infinitely some $K_n$'s, there must be infinitely some $K_n$'s that do not contain $y_1,y_2,\cdots,y_{m_k}$, to which some of $y_m$'s belong. Therefore, we are able to choose a $y_{m_{k+1}}$ from the $y_m$'s, with $m_{k+1}>m_k$, belonging to a $K_{n_{k+1}}$, with $n_{k+1}>n_k$. Therefore we constructed a subsequence $\left\{y_{m_k}\right\}$of $\left\{y_m\right\}$ converging to $x$.
The other case is quite simple. If a subsequence of $\left\{y_m\right\}$ is contained in a single $K_n$, then it has a convergent subsequence.
Now since every sequence in $K$ has a convergent subsequence, $K$ is compact.


When do you cross the finish line in Alpine Skiing - when your skis cross or when your head crosses?

Question: I'm watching the women's slalom event in the 2022 Winter Olympics, and every single skier has bent over to put their head forward as they cross the finish line. It is similar to how a runner in a track and field event will lean their body forward as they cross the finish line.
Why do these skiers do that? Are the rules different for alpine skiing and cross country skiing events? I know that for cross country skiing events, it's when the front tip of their ski touches the finish line that matters. So cross country skiers will push their leg forward as they cross the finish line.
Answer: It does appear that the timing specifications for cross-country and alpine are slightly different.
My understanding is that photo finish systems (line-scan camera system) are currently only used as backup systems for FIS alpine events.  These would note when any part of the skier crossed the finish line.
But today photocells are specified as the primary system, with both targeted below the knee.
From the FIS timing booklet (alpine)

The cells must be mounted so that both beams are triggered at a height
that is lower than the knee of racers at the finish. It is recommended
that the lowermost photocell be connected to Timing System A.

This information could be out of date for the 2022 Olympics, but the 2022 US Ski & Snowboard Advanced Timing Study Guide suggests that it hasn't changed yet.

Photo Finish timing has been approved for use at FIS events for backup
purposes only.

It's hard for me to tell specifically what the purpose of the skiers position is at the finish, but I wonder if they are leaning down and trying to trip the cell with their hand rather than with their leg.  On some finishes I watched, the arm was down very low compared with someone just trying to lean forward and trip with helmet or chest.
Also, I believe cross-country events are currently timed from the boot, not the ski tip.
Timing Booklet
Cross-Country
Nordic Combined (Cross-Country)

Electronic timing
The following electronic timing technologies can be used to identify the official finish
times:

Electronic timing system based on photocells. The measuring point of the light or
photo barrier must be at a height of 25 cm above the snow surface.
Photo finish system. The measuring point will be the toe of the first boot meeting
the finish line
Comment: I think you're right - it seems like the skiers are trying to extend their hand(s) forward as low as possible as they cross the finish line.
Comment: Interesting enough, ski cross has its own rules. In a photo finish in Semifinal 2 of the Women's Ski Cross event, three skiers stretched their hands out (above their knees) as they crossed the finish line. The announcers said it's whatever body part crosses the finish line first.


SQL 2005 Express DB Backups on Windows Server 2003 SBE

Question: Is there a way to schedule a job on Windows Server 2003 [small business edition] that will create a backup of a SQL 2005 Express DB?
I'm not sure if there is a native job/process for this on SQL Express or not.  If there is not, how would I go about creating one?
Answer: I use expressmaint - works like a champ
Comment: I would vote you up on this, that looks great.  Just don't have the rep to do so yet...
Comment: We wrote an application to assist in backups for our customers using sql 2005 express, but expressmaint looks like it does basically the same things. Or you can just do the stored procedure calls built into MSSQL
Answer: I believe Quest Software's freeware version of Toad has the ability to manage SQL jobs on SQL Server express.
Another option would be to script out the task using sqlcmd and schedule it using the Windows task manager.
Answer: I was using expressmaint for a while then when I upgraded to SQL Express 2008 I had to switch to SalBackupAndFTP. It lets you schedule backups, etc, and supports SQL Express 2005/08, oh and its free.
(BTW the ftp part is optional, it also lets you save to disk)
Answer: To elaborate on the second part of boxelephant's answer, here's a sample script you could save as a bat file and run via Windows scheduler.
sqlcmd -E -S .\sqlexpress -Q "BACKUP DATABASE [MyDatabaseName] TO  DISK = N'c:\Backups\MyDatabaseName.bak'
WITH NOFORMAT, NOINIT,  NAME = N'My Database-Full Database Backup'
, SKIP, NOREWIND, NOUNLOAD,  STATS = 10"

This just logs into the local sqlexpress instance using a trusted connection and creates a full backup of MyDatabaseName and saves it to disk.  You'd probably want to tweak the script to incorporate some sort of date/time stamp in the bak file name so you don't overwrite the previous backup.
The sqlcmd syntax can be found here: http://msdn.microsoft.com/en-us/library/ms162773.aspx
I've never used either of the third-party solutions mentioned, but if one meets your needs, it's likely easier to use one of them than rolling your own from scratch.  OTOH, this is still pretty easy if all you need is a super lightweight backup plan.
Comment: This is exactly what I do. Works well enough.
Answer: Microsoft SQL Server Management Studio Express allows for backups, among all the other things it can do.
Comment: I don't think you can have that run as a scheduled job/task on the express versions.  For the regular version of SQL I believe Management Studio would be a heck of a start.
Comment: Yep, you can do a one-off backup but you can't schedule.


Moving a distance at a position vector

Question: I have a problem set in which the problem states from vector $a = 4i+3j+8k$ move lets say $2$ metres in the direction of the vector $r = 1i + 2j +5k$. What is your final position?
I know how to add vetors and however I am not sure how to deal with it when they you must move a certain number of meters in the direction of another vector.
Must I multiply the vector by the $2$?
Thanks.
Answer: Assuming you are always dealing in meters, then you need to normalize the vector $\mathbf{r}$ and multiply it by $2$. Then normalized vector is found by
$$\mathbf{n}=\frac{\mathbf{r}}{||\mathbf{r}||}$$
Where $||\mathbf{r}||=\sqrt{1^2+2^2+5^2}$.
Normalizing the vector gives you the unit vector in the direction of $\mathbf{r}$ . Then you add $\mathbf{a}+\mathbf{r}$.

Moving a distance at a position vector


How to find Krull dimension of $k[[x,y]][x^{-1},y^{-1}]$ where $k$ is a field?

Question: I don't know how to find Krull dimension of $k[[x,y]][x^{-1},y^{-1}],$ where $k$ is a field?
Comment: Please always make the body of your questions contain the actual question. Have you ever seen a book whose first sentence starts in the title?
Answer: Since you know that $dim(A)=dim(k[[x,y]])=2$, here is how to compute the dimension of $B=k[[x,y]][x^{-1},y^{-1}]=k[[x,y]][\frac {1}{xy}]=A[\frac {1}{f}]$, where we put $f=x\cdot y$
We are lucky to be in the happy situation where $A$ is a local ring  with maximal ideal $\mathfrak m=(x,y)$, so that all maximal chains of primes of $A$ are of the form $0\subsetneq \mathfrak p\subsetneq \mathfrak m$.
Since the primes of $B$ correspond to the primes of $A$ not containing $f$, the maximal chains in $B$ will thus correspond to chains in $A$ of  the form $0\subsetneq \mathfrak p$ with $f\notin \mathfrak p$.
Such $\mathfrak p$ do exist: for example $\mathfrak p=(x+y)$.
Conclusion  $$   \dim  ( k[[x,y]][x^{-1},y^{-1}])=1                 $$
Comment: Great! thank you, dear Georges Elencwajg.
Comment: I have learned a lot from you :)
Comment: Dear @ehsanno, thanks a lot: no words could be more appreciated by a teacher.
Answer: Your ring is the localization at the multiplicative set generated by $xy$ of the completion of $k[x,y]$ at the maximal ideal $(x,y)$.
Do you know how the procedures of localization and completion interact with Krull dimension?
Comment: Dear @ehsanno, since $k[[x,y]]_{xy}$ contains $x,y$ and $\frac {1}{xy}$, it also contains $x\cdot \frac {1}{xy}=\frac {1}{y}$ and similarly it contains $\frac {1}{x}$. The other inclusion follows from $\frac {1}{xy}=\frac {1}{x}\cdot \frac {1}{y}$
Comment: Dear Mariano Suárez-Alvarez: yes, thanks. I thought about that. In fact, $\text{dim}k[[x,y]]=2.$ So based on your words and my knowledge, $\text{dim}k[[x,y]]_{xy} \leq 2.$ Am I right? what is it exactly, then? and is it obvious that $k[[x,y]]_{xy} \cong k[[x,y]][x^{-1},y^{-1}]?$
Comment: Dear @Georges Elencwajg: Oops! yes, that's right!


Binding click event handlers in a loop causing problems in jQuery

Question: I am trying to run the following code:
I pass parameter to a function, but it always has the value of the last object run through the loop. I read some articles about it on stackoverflow, but I couldn't find out how to make it run in my solution.
The object is a JSON object returned from the server. All it's values are correct.
for(var i = 0;i<parents.length;i++){
            var row        = $(document.createElement("tr"));
            var colName    = $(document.createElement("td"));

            var aDisplayCol = $(document.createElement("a"));

            var parentId = parents[i]['PARENT_ID'];

            aDisplayCol.attr("href","#").html(parents[i]['NAME']);
            aDisplayCol.bind('click',function(){ alert(parentId);});

            colName.append(aDisplayCol);

            row.append(colName);
            $('#pages tbody').append(row);

}
Thanks
Answer: It is a scope problem. By the time the event handler function is executed, the value of parentId has changed and is not longer what you expected.
This can be solved making the original event handler function be returned by another function which, in turn, is passed the value of parentId as argument:
function getEventHandlerFunction(id){
    return function() {
        alert(id);  // variable found in the closure with the expected value
    };
}

aDisplayCol.bind('click', getEventHandlerFunction(parentId));

Answer: Perhaps there's a problem with using parentId in the callback.
Try alert(parents[i]['PARENT_ID']);.
EDIT: Let's see if we can get around our scope issues with .data().
aDisplayCol.data("parentId",parents[i]['PARENT_ID']);
aDisplayCol.click(function() {
   alert($(this).data('parentId'));
});

Comment: Nope, that's not causing it. Actually, I discovered yesterday that the .click function can't handle the following:

aDisplayCol.click(function(){ whatever(target,dest, parents[i]['PARENT_ID']); return false; });

I assume it is a bug. Passing a variable instead works fine.
Comment: Nah I don't think it's a bug. I think it's a scope issue. I don't think `i` exists within the scope of the click handler.
Comment: you forgot to close the parenthesis at .data
Comment: using .data worked! AWESOME :D thanks. It is a closure problem.
Answer: You can avoid the clouseres problems with the eventData parameter of the bind function
like this
var message = 'Spoon!';
$('#foo').bind('click', {msg: message}, function(event) {
    alert(event.data.msg);
});
message = 'Not in the face!';
$('#bar').bind('click', {msg: message}, function(event) {
    alert(event.data.msg);
});

this is from the jquery bind api documentation http://api.jquery.com/bind/#passing-event-data


Find the expected payoff for different strategies

Question: I have recorded on a continuous scale (between 0 and 15) the strategy some players used in a video game and their associate payoff (also interval-ratio) in this game, so I have lots of couples of values like (2.34,12), etc.
I would now like to have an idea of what strategy brings the highest payoff in the game, or what would be the expected payoff for each strategy. It is difficult to see a clear relationship between strategy and payoff on a visual inspection. A 2D scatter plot gives this:

but there are lots of points stacked up on this plot. A 3D histogram gives a better idea of the distribution:

So I tried to do a loess regression on this data. Here is the smooth curve computed by loess:

but the R² of this regression is very low, 0.09.
Do you see a regression that would be best suited for this kind of data or should I stick with Loess regression?
Comment: This sounds like a game theory problem.
Comment: I imagine there are more variables involved than strategy that affect the payoff.
Comment: @Glen_b For now I only have the strategy as variable
Answer: Since strategy is continuous, you might start by considering a smooth regression relationship between payoff and strategy, perhaps something like a loess curve.
However, you might wish to consider whether leaving out an important predictor could mislead you. Firstly, it can make relationships much noisier than they would otherwise be, and secondly, it can bias your estimates of the relationships with the variables you do have, even changing their sign
Comment: I've edited my post with data distribution and results from Loess regression. Do you still think it's the most adapted regression?
Comment: Now I see your data, a single curve - of any kind - is not remotely suitable; there's a clear suggestion of an important, missing variable, making the marginal relationship uninterpretable. What do you mean "most adapted regression"?
Comment: I mean either try to fit the data to a predefined non-linear function, or use another type of smoothing like smoothing spline? Also, I have no idea as to what "span" smoothness parameter use for my loess smoothing. thanks
Comment: Actually there is no missing variable in this specific dataset. It's just that if players play strategy "6" for example, they have half a chance to win 9, and half a chance to win 0. that's how I got this kind of distribution. Now is it possible to have an idea from this data what strategy brings the highest payoff on average?
Comment: Yes so to make it more clear I'm not trying to get the best fit, I just want to have an idea from my data of what strategy brings the highest payoff on average.
Comment: if something has two possible outcomes with known probability for each, you can calculate (rather than estimate) the conditional mean at each value of strategy. Just find the exact conditional mean as a function of strategy and optimize that.
Comment: I don't know the exact probabilities of each outcome unfortunately... Thus my need to estimate the conditional payoffs from the data. So a loess smoothing curve is not suitable for estimating this?
Comment: One of the problems with it being really suitable is that it ignores what it sees as "outliers", which is usually fine, but you really don't want it to do here. Another is that the loess curve doesn't account for the known variance structure of a binomial outcome, for example. It might do okay with some tweaking; a modified weighted local regression might do okay, but you're probably better seeing if this can be transformed into a binomial glm (by rescaling the known endpoints to 0-1), fitting a smooth function, and then transforming back.


Laravel, Vue:Object(…) is not a function

Question: I am new to Laravel and tried to handle some api calls. I am making a dashboard with an admin panel to handle users. Now I want to add some data to my endpoint but every time I want to import a function from another view it says: Object(…) is not a function. I looked thorugh stackoverflow and found this post here but it didn´t solve my problem...

TypeError: Object(...) is not a function
at resetStoreState (0.js:3252)
at new Store (0.js:2993)
at Module../resources/js/store.js (1.js:498)
at webpack_require (app.js:64)
at Module../resources/js/services/http_service.js (1.js:462)
at webpack_require (app.js:64)
at Module../resources/js/services/category_service.js (1.js:443)
at webpack_require (app.js:64)
at Module../node_modules/babel-loader/lib/index.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/views/Categories.vue?vue&type=script&lang=js& (1.js:14)
at webpack_require (app.js:64)

My code:


Count distinct rows via a pair of known values

Question: I wasn't even sure how to phrase this question. I'll give example content and wanted output, I'm looking for a query to do this.
Let's say I have table called "flagged" with this content:
content_id | user_id
1          | 1
1          | 2
1          | 3
2          | 1
2          | 3
2          | 4
3          | 2
3          | 3
4          | 1
4          | 2
5          | 1
6          | 1
6          | 4

And I have a a-symmetrical relationship between content_ids:
master_content_id | slave_content_id
1                 | 2
3                 | 4
5                 | 6

For each "master" content_id (1, 3 and 5), I want to count how many distinct users have flagged either the master or the slave content, but count someone who flagged both as a single flag - which means that in the above example, content_id=1 was counted by user_id=1 (as content_id=1 and content_id=2), by user_id=2 (as content_id=1), by user_id=3 (as content_id=1 and content_id=2), and by user_id=4 (as content_id=2!)
An example of the output of the query I want to make is:
content_id | user_count
1          | 4          # users 1, 2, 3, 4
3          | 3          # users 1, 2, 3
5          | 2          # users 1, 4

I can't assume that the related content_ids are always a consecutive odd/even (i.e. 66 can be the master of the slave 58)
I am using MySQL and don't mind using its extensions to SQL (but rather the query be ANSI, or at least portable to the most databases)
Comment: There are some really great answers here. There are literally a million ways to do anything in SQL
Answer: The query below worked for me.
I'm using a sub-query with a UNION ALL to treat your mapped contents equal to the direct contents.
SELECT master_content_id AS content_id,
       COUNT(DISTINCT user_id) AS user_count
FROM (
  SELECT master_content_id, slave_content_id
    FROM relationship
  UNION ALL
  SELECT master_content_id, master_content_id
    FROM relationship
) r
JOIN flagged f ON ( f.content_id = r.slave_content_id )
GROUP BY master_content_id

Result:
content_id  user_count
         1           4
         3           3
         5           2

Answer: I think something like this will work for you (although GROUP_CONCAT is MySQL specific, similar concatenation can be achieved in other RDBMS)
SELECT  COALESCE(Master_Content_ID, Content_ID) AS Content_ID,
        COUNT(DISTINCT User_ID) AS Users,
        CONCAT('#Users ', GROUP_CONCAT(DISTINCT User_ID ORDER BY User_ID)) AS UserList
FROM    Flagged
        LEFT JOIN MasterContent
            ON Content_ID = Slave_Content_ID
GROUP BY COALESCE(Master_Content_ID, Content_ID)

Sample SQL Fiddle here: http://www.sqlfiddle.com/#!2/d09be/2
Output:
CONTENT_ID  USERS   USERLIST
1           4       #Users 1,2,3,4
3           3       #Users 1,2,3
5           2       #Users 1,4

Comment: Didn't know about SQL Fiddle and about GROUP_CONCAT. I don't actually need the userlist, that was just a comment, but it's still good to learn something new :)
Answer: From the samples given, does this do the job (I don't have MySQL available to test)?
SELECT
    ms.master_content_id,
    (SELECT COUNT(DISTINCT f.user_id) FROM flagged f WHERE
                      f.content_id = ms.slave_content_id OR
                      f.content_id = ms.master_content_id)
FROM
    master_slave ms

It would be better not to have the DISTINCT, but I can't see a way around it.
Comment: I ended up using something very similar to this - Instead of an inner query, I did:
SELECT ms.master_content_id, COUNT(DISTINCT f.user_id)
FROM master_slave ms
JOIN flagged f ON f.content_id IN (ms.master_content_id, ms.Slave_content_id)
GROUP BY ms.master_content_id
Answer: SELECT master_content_id      AS content_id
     , COUNT(*)               AS user_count
     , GROUP_CONCAT(user_id)  AS flagging_users
FROM
  ( SELECT r.master_content_id
         , f.user_id
    FROM relationship AS r
      JOIN flagged AS f
        ON f.content_id = r.master_content_id
  UNION
    SELECT r.master_content_id
         , f.user_id
    FROM relationship AS r
      JOIN flagged AS f
        ON f.content_id = r.slave_content_id
  ) AS un
GROUP BY master_content_id


Zero mutual information

Question: I have two random variables X and Y=X+N. What should be the condition such that I(X; Y)=0? Can anyone direct me towards the relevant references?
Comment: Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
Answer: Just use the definition
$$
\operatorname{I}(X;Y) =
  \int_{\mathcal Y} \int_{\mathcal X}
      {p_{(X,Y)}(x,y) \log{ \left(\frac{p_{(X,Y)}(x,y)}{p_X(x)\,p_Y(y)} \right) }
  } \; dx \,dy
$$
For it to be zero, you either need $p_{(X,Y)}(x, y)$ to be always zero, but then it wouldn't be a proper distribution, or the log part would need to be equal to zero. Recall that $\log(1) = 0$, so you need $p_{(X,Y)}(x, y) = p_X(x) \, p_Y(y)$, i.e. $X$ and $Y$ would need to be independent.
Comment: Is there any condition that we can apply to the noise distribution, which will make the X and Y independent? Probably amount of power/entropy in the noise distribution?

Zero mutual information


significance of PCA with EWMA

Question: I am evaluating a PCA on a set of 45 financial time series where EWMA (exponentially weighted moving averages) has been applied.
A small intro. An EWMA statistic has a form
$$
\hat{y}_t = \sum_s \lambda^s y(x_{t-s}) \big/\sum_s \lambda^s
$$
You can check here for more description.
First, I compute the EWMA mean and standard deviation, and I standardize the time series, which I will call $r_t$. The $\lambda$ I use is 0.95, and is obtained (as typically done) by minimizing the error
$$
\sum_i ((r^i_{t+1} - \mu^i_t(\lambda))^2 - \sigma_t^{i,2}(\lambda))^2
$$
After this I compute the covariance matrix of $\{r_t^i\}_i$, again using EWMA. Once I'm there, I want to compute a PCA, to understand a bit more what is going on. Now, I understand that the Marchenko-Pastur theorem is typically used to select the statistically significant eigenvalues. My question is, what is the number of data that we have to assume in the context of that theorem?
I would naively use $\lambda^{-1}$ (or some more sophisticated similar calculation) as the number of data points in each time series. The problem with that is that the limit of the distribution under the null hypothesis is 56.8, which is higher than the highest eigenvalue (this situation repeats at all times).
The obvious conclusion would be that those eigenvalues are not significant. However, if the correlation between the first eigenvectors at different times is quite high (say > 0.9). This would be an indication that they actually represent some long-term feature in the data. The alternative conclusion is that my estimation for the number of data in the time series is incorrect. But then, how much should it be?
Answer:
I would naively use $\lambda^{-1}$ (or some more sophisticated similar calculation) as the number of data points

With $\lambda^{-1} = 1/0.95 \approx 1.05$ you are using approximately 1.05 datapoints? That is extremely low.
If you compute $$\left(1+\sqrt{\frac{45}{1.05}} \right)^2 \approx 56.8$$ then you are extremely underestimating the number of datapoints.

You could determine a cut-off $\lambda$ by simulations.
Repeatedly generate $45$ columns with data. Perform the EWMA smoothening and then compute the correlation matrix and eigenvalues. Then see the distribution of those eigenvalues and whether the smoothening has a large effect on te effective number of datapoints.
Below is an example where we have 45 columns of 200 points and we changed the $\lambda$ variable
The red curve that we added follows the relation
$$\lambda_+ = \left(1 + \sqrt{\frac{m}{n(1-\lambda)}} \right)^2$$
So it seems like the moving average reduces the effective number of points approximately by a factor $1-\lambda$.

<code>sim = function(n = 100, m = 45, q = 0.95) {
  ### generate data
  x = matrix(rnorm(m*n),n)
  y = x*0

  ### compute moving average
  filt = q^c(0:(n-1))
  for (i in 1:m) {
    for (j in 1:n) {
      y[j,i] = sum(filt[j:1]*x[1:j,i])/sum(filt[j:1])
    }
  }

  ### standardize
  mu = rep(1,n) %*% t(apply(y,2,mean))
  sig = rep(1,n) %*% t(apply(y,2,var)^0.5)
  y = (y - mu)/sig

  mu = rep(1,n) %*% t(apply(x,2,mean))
  sig = rep(1,n) %*% t(apply(x,2,var)^0.5)
  x = (x - mu)/sig

  ### compute eigenvalues

  ev_x = eigen(t(x) %*% x/n)
  ev_y = eigen(t(y) %*% y/n)

  return(list(x=max(ev_x$values),y = max(ev_y$values)))
}

set.seed(1)
m = 45
n = 200
q = seq(0,1,0.005)

values = sapply(q, FUN = function(qs) sim(n=n, q = qs))
boundary = (1+sqrt(m/n))^2

plot(c(0,1),boundary*c(1,1), type = "l", lty = 2,
     ylim = c(0,max(as.numeric(values))),
     xlab = expression(lambda),
     ylab = "sampled eigenvalue maximum")
points(q,as.numeric(values[2,]),
       pch = 21, col = 1, bg = 0, cex = 0.7)

lines(q, (1+sqrt( m/(n*(1-q)) ))^2, col = 2)

</code>
Comment: why is underestimating? i.e. wrt what? At each time only the 6% of the previous time is taken into account. Thanks for the advice of trying with synthetic data, I will try
Comment: @Chuse an estimate of 1.05 for the number of points is extremely low. Also, you would expect that somehow the number of data points should be involved and not just the parameter $\lambda^{-1}$.
Comment: If I pick $\lambda\sim0.95$ then the data is practically the same as taking one single time (or row), i.e. $n=1$. So, I know it's a very low estimate, but to me it makes sense because the values of the correlation matrix are practically the same as having $n=1$.
Comment: The simulations I did suggest against my intuition, i.e. a higher $\lambda$ is equivalent to a higher $n$. I'm really confused
Comment: thanks, I reached to a very similar conclusion, but I think that $n$ doesn't enter into the formula, because it's irrelevant how large the table is. See my answer.
Answer: My naive solution was wrong. An "equivalent" number of rows $n*$ can be calculated as $$
\sum_{s\ge 0} \lambda^s = \frac1{1-\lambda}
$$
Using this, $n^*(\lambda=0.95)=20$, which is a more reasonable estimate. With it, the Marchenko-Pastur limit is 6.25, a result supported by simulations.
In general, the limit should be
$$
\lambda_+ = \left(1 + \sqrt{m(1-\lambda)}\right)^2
$$
Comment: In the case of $\lambda \to 0$ then $$\hat{y}_t = \sum_s \lambda^s x_{t-s} \big/\sum_s \lambda^s \to \sum_s I(s=0) x_{t-s} \big/\sum_s I(s=0)  = x_t$$ $\lambda^s\big/\sum_s \lambda^s \to I(s=0)$ approaches the indicator function for $\lambda \to 0$ and is equal to $1$ when $s=0$ and equal to $0$ elsewhere.
Comment: Do you also include the actual number of rows in the computation of the equivalent number of rows? The limit changes when you have a different amount of rows $n$ while keeping the columns $m$ and $\lambda$ the same.
Comment: I used much larger tables (to 10k rows) and the largest eigenvalue is still around 6
Comment: Is that for simulated data or for data where you might get larger eigenvalues because the null hypothesis is not true?
Comment: You happened to have this value of 6.25 by chance. The formula does not make sense. Try it out with some simulations varying the column length $n$ or varying the parameter $\lambda$. Something that clearly shows that your formula is wrong is when you consider $\lambda \to 0$. In that case your $\lambda_+$ approaches $(1+\sqrt{m})^2$ and is independent of $n$ which makes little sense. The smaller that $\lambda$ is, the more you will expect the value to approximate $(1+\sqrt{m/n})^2$ and you would expect a *decrease* of $\lambda_+$ (see my simulation where you get this decrease).
Comment: I think that in the case $\lambda\rightarrow0$, that is exactly when you have only the last point in the time series, and therefore $n^*=1$. The case in which $n^*= n$ is when $\lambda=1$. In the formula that doesn't work because it is assumed that the time series is kind of infinite. But is a limiting case, and for any practical application ($\lambda\sim0.99$ or below), it's ok. Do you agree?
Comment: *"you have only the last point in the time series"* You don't just have one time point right? We are using $\hat{y}_1, \hat{y}_2, \hat{y}_3, \dots, \hat{y}_n$ or not? (And indeed, for each of these $\hat{y}_i$ they relate only to the last time point $y_i$, but you have many different $i$ of them)
Comment: with "you have only the last point" I meant that $\hat{y}_t=x_t$. But is also the case that the correlation matrix will be just the covariance of data at time $t$, not before, and therefore $n^*=1$.
Comment: You are not computing a correlation matrix for an n by m matrix?

significance of PCA with EWMA


Using modals in Codeigniter

Question: I am creating a web app using codeigniter and Twitters CSS framework Bootstrap.
I am wondering how I go about implementing their modal system here with the 'views'. I want to be able to click a button in a view file and for it to link to a controller but the view to open in the modal. If that makes sense? Any ideas would be great.
Thanks
Comment: There's nothing fancy. Just follow their examples and use `` inside the modal buttons instead of the actual buttons.
Comment: that works but it doesnt show the modal on top of the current view. it just shows it on its own.
Comment: Review the javascript and jQuery requirements for using modals.
Answer: I am doing this on my current project, and I use jQuery's $.ajax to load the url into a modal element and then fade that into view.
In the controller, if I want modal markup to load, I use this:
if ($this->input->is_ajax_request())
{
    $this->load->view('some/view_modal', $data);
}
else
{
    $this->load->view('some/view', $data);
}

If your markup is simple enough, you can extract just the container element you need when you do the AJAX call, but for me I found it simpler to use two views.
In your case, you can simply pass the AJAX response data to the Bootstrap modal function.

Using modals in Codeigniter


Existence of bijections in $L$

Question: Let $A, B \in L$ (where $L$ is the class of constructible sets). Is the following true (and why)?

If there is a bijection $f \colon A \to B$, then there is a bijection $g \in L$ such that $g \colon A \to B$.
Comment: @Angelo Functions are sets.
Comment: @Angelo Everything is a set in ZF. Every function is a set of kuratowksi pairs.
Comment: @TomCollinge $f$ may not be in $L$.
Comment: The function $f$ is in $V$, i.e. in the class of all sets (in a model of ZF). On the other hand, $g$ is in $L$ which is the class of all constructible sets.
Comment: @TomCollinge No, we are talking about [link](https://en.wikipedia.org/wiki/Constructible_universe).
Comment: Why did you write $g\in L$? $L$ is the class of the constructible sets, but $g$ is not a set but a function.
Comment: I don't understand your question. What's the difference between $f$ and $g$ ?
Comment: Then what is your definition of $f$ ?
Comment: Are we talking about https://en.wikipedia.org/wiki/Constructible_set_(topology) ? in which case, what topology is involved ?
Comment: Not an area I'm familiar with. I'll be interested to see the answer. Hope you get one soon.
Answer: No. It is consistent with ZFC that the first ordinal that is uncountable in $L$, usually written $\omega_1^{(L)}$, is countable.  That is, $\omega_1^{(L)}<\omega_1$.  In this situation, there is a bijection from $\omega_1^{(L)}$ to $\omega$, but there is no such bijection in $L$.  (The phrase to look up for proofs of this consistency is "cardinal collapsing".)
Comment: I would write it as $\omega_1^L$. James Cummings prefers $(\omega_1)_L$. I do not remember seeing the $\omega_1^{(L)}$ notation, though.

Existence of bijections in $L$


Compacting too many if clauses using Java 8

Question: I have written following code block in Java:
public mainFunction() {

...

if (!functionA(data1, data2)) {
  return new Left<>(Reason.INVALID_RULE);
}

if (!functionB(data1, data2)) {
  return new Left<>(FAILURE.INVALID_ID);
}

 ...there are a few if clauses like above...
}

private boolean functionA(Data1 data1, Data2 data2) {
    if(StringUtils.isNotBlank(data1.getAttr1)) {
       data2.setAttr1(data1.getAttr1);
       return true;
    }
    return false;
}

private boolean functionA(Data1 data1, Data2 data2) {
    try{
       data2.setAttr1(Attr2Enum.fromValue(data1.getAttr1));
       return true;
    } catch (Exception e) {
    return false;
    }
}

Now, my question is can I compact them using Java8?
Comment: Different functions, different return values, I'm not sure we can make your code any more concise.
Comment: Don't call actions that modify the incoming objects "function". Don't use anti-patterns like `catch(Exception e) { return false; }`. If you clean up your code, the problem may already disappear.
Comment: @TimBiegeleisen return values and arguments are the same actually in all functions called from if clauses in mainFunction().
Comment: The return values are different.  (If they were the same, you wouldn't need to call the 2nd, 3rd, etc function.).  But I agree with Tim that there doesn't look like there is any scope for making this more concise.
Comment: Why would you not consider Chain of responsibility for this Design?
Comment: I would point out that `catch (Exception e) { return false; }` is a really bad idea.  It is going to *hide* bugs.
Comment: @AnupamAlok - I think it is unlikely to make the code more concise ... overall.  But if you think it would help, write an Answer, showing how to applying CoR to the OP's example.  (So that we can >>see<< if it is more concise.)
Comment: It Completely depends on real use case. Give me a accurate situation and I will try to give you the most compact code as possible
Answer: There can me multiple ways to do it.
I tried to create a Validator interface which can do this kind of validation chaining.
Although its not a perfect solution but it may give you an idea to start with. Its a much generic solution (can be more generic with ? super and ? extends - you can try on your own)
Code:
package pecs;

import javafx.util.Pair;

public class Chaining {

    public static void main(String[] args) {
        Validation<Integer, String, Message> validation = (a, b, c) -> {
            return new Pair(a > 30, new Message("a should not be greater than 30"));
        };
        Validation<Integer, String, Message> validation2 = (a, b, c) -> {
            return new Pair(a > 20, new Message("a should not be greater than 20"));
        };
        Validation<Integer, String, Message> validation3 = (a, b, c) -> {
            return new Pair(a > 10, new Message("a should not be greater than 10"));
        };
        Validation<Integer, String, Message> validation4 = (a, b, c) -> {
            return new Pair(a > 5, new Message("a should not be greater than 5"));
        };

        //One way to call
        Validation<Integer, String, Message> validator = validation
                .and(validation2)
                .and(validation3)
                .and(validation4);

        System.out.println(validator.validate(4, "A00", 0));
        System.out.println(validator.validate(9, "A00", 0));
        System.out.println(validator.validate(11, "A00", 0));
        System.out.println(validator.validate(21, "A00", 0));
        System.out.println(validator.validate(31, "A00", 0));

        //Another way to call
        Pair<Boolean, Message> pair = validation
                .and(validation2)
                .and(validation3)
                .and(validation4)
                .validate(4, "String", 0);
        if(pair.getKey() == false) {
            System.out.println("All Validation successful");
        } else {
            System.out.println(pair);
        }

    }
}

The validator interface used in the code:
package pecs;

import javafx.util.Pair;
import java.util.Objects;

@FunctionalInterface
public interface Validation {
    Pair<Boolean, C> validate(A a, B b, int count);

    default Validation and(Validation other) {
        Objects.requireNonNull(other);
        return (a, b, c) -> {
//            System.out.println("c=" + c);
            Pair<Boolean, C> validate = validate(a, b, c+1);
            if (validate.getKey() == true) {
                return validate;
            } else {
                //Termination condition.
                if(c == 0) {
                    Pair<Boolean, C> pair = other.validate(a, b, c);
                    if(pair.getKey() == false) {
                        return new Pair<>(false, null);
                    } else {
                        return pair;
                    }
                } else {
                    return other.validate(a, b, c);
                }
            }
        };
    }
}

Please have a look and suggest if any improvements.
There are many other ways to do validation. Say for example, check this link:
https://dzone.com/articles/server-side-validator-using-functional-interfaces
Comment: Author never mentioned using JavaFX, so please, don't make them import JavaFX as it can lead to several issues.
Comment: Yes right, custom pair class can be created
Comment: OK ... so in the OP's actual example, it looks like you would have replace N `if` statements with code that makes N `Validation` objects. Plus a bunch of extra boilerplate to unpick the resulting pairs. I don't see how that is an actual improvement ... unless the `Validation` objects are being used in lots of places. (And even then ... there is a different problem ... which is having the declarations of the `Validation` objects separated from their use(s).)
Comment: @StephenC: Those validation objects can be reused and avoid code duplicacy. Removing and adding validation is easy. There are multiple such advantages. Boilerplate is everywhere, just that its hidden in libraries. Try using any existing validator implementation if you want to avoid boilerplate. Its code once and leave.
Answer: You can make a map of the type Map<BiPredicate<Data1, Data2>, Left<?>> using the Map.of function, where the predicates are aligned to the corresponding results, and then stream over the entrySet of the map.
Something like:
Map.<BiPredicate<Data1, Data2>of( (data1,data2)->{return
!functionA(data1, data2)},  new Left<>(Reason.INVALID_RULE))

etc..., then
.entrySet().stream()

then .map or .forEach over the entries.