Bootstrap with Main Left Navbar causes content nav menu to have same vertical size

Question: I have a Bootstrap based site with a navbar vertically aligned on the left of the screen. On some of the pages I want the page content to have its own nav menu place horizontally across the top of its own content.
Problem: My problem is that using bootstrap classes for both navigation menus, the horizontal nav menu in the content area has the same height as the main vertical navigation menu. This pushes all the content not only below the content's nav menu, but below the much taller main navigation menu - when the content should be beside the main menu!
Question:
How do I get the content's nav menu to vertically size for its own content so the content area's full content will flow beside the main navigation menu?
Using the [F12] developer tools in IE, FireFox, and Chrome, I cannot see any reason why the heights of both navigation menus is synchronized, and thus I can find no why to break that synchronization.
The problem is replicable on JSFiddle: https://jsfiddle.net/zazm460q/2/
(I am developing for desktop apps, you may have to widen the Result pane to see the desktop layout rather than the mobile layout.)
Here is some simplified HTML showing the problem:

    My App Logo

      menu item a

          a.1

          a.2

          a.3

      menu item b

          b.1

          b.2

          b.3

      menu item c

          c.1

          c.2

          c.3

      menu item d

          d.1

          d.2

          d.3

      menu item e

          e.1

          e.2

          e.3

Tab A

Tab B

Tab C

Tab D

Tab-A Content Here

          AAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAA

Tab-B Content Here

          BBBBBBBBBBBBBB BBBBBBBBBB BBBBBBBBBBB BBBBBBBBB

Tab-C Content Here

          cccccc ccccccCCCCCCC CCCCCcccccc cccCCCCCCCCC CCCCCCCCcccc cccccc

Tab-D Content Here

          DDDDDDDDDDD ddddddddddddd DDDDDDDDDDDDD ddddddddddd DDDDDDDDddd

My App

And also some simplified CSS:
nav.navbar-left {
  width: 140px;
}

#body-content {
  margin-left: 150px;
}

footer {
  width: 100%;
  text-align: center;
}

Answer: One way you can solve this is to use the default Bootstrap Nav as both a vertical (sidebar nav) and horizontal (standard nav) Navigation at the same time.
Then create a new container/wrapper class for your content to offset the Sidebar.
Working Examples.
Tab Content within Columns Example: Use FullPage and reduce the Browser width.

body {
  padding-top: 50px;
}
@media screen and (min-width: 768px) {
  .sidebar-nav .navbar-nav.navbar-left {
    top: 50px;
    bottom: 0;
    left: 0;
    width: 200px;
    position: fixed;
    background: #222;
  }
  .sidebar-nav .navbar-nav.navbar-left > li {
    display: block;
    float: none;
  }
  .sidebar-nav .navbar-nav .dropdown-menu > li > a {
    color: #fff;
  }
  .sidebar-nav .navbar-nav .dropdown-menu > li > a:hover {
    color: #222;
  }
  .sidebar-nav .navbar-nav .open .dropdown-menu {
    position: static;
    float: none;
    margin-top: 0;
    background-color: transparent;
    border: 0;
    -webkit-box-shadow: none;
    box-shadow: none;
  }
  .main-content {
    margin-left: 200px;
  }
}
@media screen and (min-width: 992px) {
  .main-content .nav-tabs {
    width: 100%;
    border-bottom: 0;
  }
  .main-content .nav-tabs > li {
    float: none;
    display: table-cell;
    width: 1%;
  }
  .main-content .nav-tabs > li > a {
    margin: 0 0 5px 0;
    text-align: center;
    border-bottom: 1px solid #f3f3f3;
    padding: 20px 0;
    color: #222;
  }
  .main-content .nav-tabs > li > a:hover {
    border-bottom-color: #f3f3f3;
    background-color: #f3f3f3;
  }
  .main-content .nav-tabs > .active >a,
  .main-content .nav-tabs > .active >a:focus,
  .main-content .nav-tabs > .active >a:hover {
    border: 1px solid #f3f3f3;
    border-bottom-color: #fff;
    background-color: #f3f3f3;
  }
}
.main-content .nav-tabs > li > a {
  border-radius: 0;
}
.content {
  padding: 20px 0;
}
.tab-inner-content {
  padding: 0 20px;
}
<link href=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css rel=stylesheet>

<button class="collapsed navbar-toggle"data-target=#bs-nav data-toggle=collapse type=button>Toggle navigation   </button> Brand

One
Two
Three
Dropdown One

One
Two
Three

Four
Dropdown Two

One
Two
Three

Dropdown Three

One
Two
Three

Dropdown Four

One
Two
Three

One
Two
Three

Tab 1
Tab 2
Tab 3
Tab 4
Tab 5
Tab 6

Tab 1

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Tab 2

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Tab 3

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Tab 4

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Tab 5

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Tab 6

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Full Width Tab Content: Use FullPage and reduce the Browser width.

body {
  padding-top: 50px;
}
@media screen and (min-width: 768px) {
  .sidebar-nav .navbar-nav.navbar-left {
    top: 50px;
    bottom: 0;
    left: 0;
    width: 200px;
    position: fixed;
    background: #222;
  }
  .sidebar-nav .navbar-nav.navbar-left > li {
    display: block;
    float: none;
  }
  .sidebar-nav .navbar-nav .dropdown-menu > li > a {
    color: #fff;
  }
  .sidebar-nav .navbar-nav .dropdown-menu > li > a:hover {
    color: #222;
  }
  .sidebar-nav .navbar-nav .open .dropdown-menu {
    position: static;
    float: none;
    margin-top: 0;
    background-color: transparent;
    border: 0;
    -webkit-box-shadow: none;
    box-shadow: none;
  }
  .main-content {
    margin-left: 200px;
  }
  .main-content .nav-tabs {
    width: 100%;
    border-bottom: 0;
  }
  .main-content .nav-tabs > li {
    float: none;
    display: table-cell;
    width: 1%;
  }
  .main-content .nav-tabs > li > a {
    margin: 0 0 5px 0;
    text-align: center;
    border-bottom: 1px solid #f3f3f3;
    padding: 20px 0;
    color: #222;
  }
  .main-content .nav-tabs > li > a:hover {
    border-bottom-color: #f3f3f3;
    background-color: #f3f3f3;
  }
  .main-content .nav-tabs > .active >a,
  .main-content .nav-tabs > .active >a:focus,
  .main-content .nav-tabs > .active >a:hover {
    border: 1px solid #f3f3f3;
    border-bottom-color: #fff;
    background-color: #f3f3f3;
  }
}
.main-content .nav-tabs > li > a {
  border-radius: 0;
}
@media (max-width: 767px) {
  .nav-content {
    padding: 20px 0;
  }
}
.tab-inner-content {
  padding: 0 20px;
}
<link href=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css rel=stylesheet>

<button class="collapsed navbar-toggle"data-target=#bs-nav data-toggle=collapse type=button>Toggle navigation   </button> Brand

One
Two
Three
Dropdown One

One
Two
Three

Four
Dropdown Two

One
Two
Three

Dropdown Three

One
Two
Three

Dropdown Four

One
Two
Three

One
Two
Three

Tab 1
Tab 2
Tab 3
Tab 4
Tab 5
Tab 6

Tab 1

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Tab 2

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Tab 3

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Tab 4

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Tab 5

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Tab 6

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


What are Effective Regression Techniques for Linguistic Analysis of Linked Data?

Question: Cross-post from MathOverflow where it was suggested that I might get better results here.
I am in the early stages of a problem that involves parsing a large number ($\approx 5 \times 10^9$) of documents (web pages) and estimating values from them. In particular I need to identify pages that offer downloads of pirated files and estimate their traffic. Whereas some websites make their traffic statistics public, many do not. I am left with a sparse data set with which to fill in a large number of blanks. The good news is that flagged pages are verified by a human, who extracts any page view data they can find. This means I don't have to worry about writing software to recognize or collect that data when it's present. My hopes are to apply my techniques from this problem to many others if I'm successful.
As you can see this is actually a two-part question. There is a classification stage, where I estimate whether a site is likely to yield a pirated file, and an estimation stage, where I use regression techniques to estimate how many views the page might have.
My (naive) approach would be to extract n-gram count vectors from each document (n-word-gram, not n-character-gram), which gives me a mapping from a symbolic set into a (high dimensional) integer set. It's a lot of dimensions, but I've done it before with some success. I could use this n-gram "profile" to apply logistic regression or angle comparison for classification, then linear regression for estimation. There are some really sophisticated machine learning algorithms out there, but I'm not sure what sort of performance evaluation techniques I could use on them in the estimation phase.
However, I'm sure there's a better way to do this. I can't imagine how a linguistic profile of a web page has much correlation at all with its traffic. I believe that site traffic has a lot more to do with the pages that link to it, and I could imagine using graph theory to model the propagation of page views. However, unless the site is flagged for viewing that data won't be collected. Only a small amount of pages will have their page views recorded. I could perhaps write a regular expression to match common phrases used when expressing "how many views" they got, but I'm not willing to commit time writing some sort of complex classification algorithm for that particular feature.
I'm also sure there's a large number of other measurements I could extract from a web page that I'm not thinking of. Really it's a problem of converting web page content and link topology into meaningful variables that can be used in regression analysis. So my questions to you are these:

What techniques have proven effective for classification of documents?
Where would I even begin to learn about modeling and estimating internet traffic?

I'm sorry if these are not rigorous enough questions, but at this stage I need more of a lay of the land than advice on a particular theorem. These subjects are not my primary area of expertise.
Comment: @gung MathOverflow is an SE 1.0 site, so it's not technically affiliated with the Exchange any longer.  So, there's no migration path, but I think both sides probably feel the same way about cross posting.
Comment: SE strongly discourages cross-posting. If you have a question on one SE site, & you come to believe it would fit better at another, you should ping the site moderators to *migrate* the question for you.
Comment: But in the meantime, instead of waiting for the other site's admins to do that, it's perfectly acceptable to cross post and then just be sure to notify the other site's admins to close the original... or better yet, leave both open so both communities can benefit from a well-asked question at virtually no cost for keeping a second copy of the question open.
Comment: See http://meta.stackexchange.com/questions/119193/are-there-any-popular-so-engine-powered-sites-not-belonging-to-se-network-except on MSO and others.
Comment: duly noted.  Thanks for clarifying that guys.  As this question was edited by gung earlier I'm going to assume he/she is a moderator and we are good.  If more action is needed on my part, please message me and I'll take care of it.
Comment: Thanks @jonsca, I had no idea about any of that (I spend 99% of my time on CV & 1% on SO & ~0 elsewhere). I was thinking it was math.SE; I didn't even know about MSO!
Comment: @AxelMagnuson, I'm not a moderator. You can tell because they have a small rhombus / diamond after their usernames. However, my comment about cross-posting was just FYI, there's nothing for you to do at this point that I know of. The mods will tell you if you need to do anything specific.
Comment: This crosspost was fine. However, you should have posted a link to this question in your MO question or as a comment, to avoid possible duplication of effort. I did that for you.
Comment: @gung FWIW, I hadn't realized, but I guess MO is considering coming back to SE http://meta.mathoverflow.net/discussion/1416/1/mathoverflow-20/
Answer: Both questions are hard, I'll give a shot at the first one.
A straightforward approach to classify documents is to compute their tf-idf. In short, you consider the text is a bag of words, i.e. that it has no linear structure, and you compute a score that says how much the word is specific of a document. I explain a little bit about how to do this here.
Once this is done, texts are often compared with the cosine similarity measure, which is the cosine of their tf-idf vectors. If they have a high similarity, they have similar specific words and you can guess they are about the same topic.
You can compute cosines, but you can do all sorts of geometric operations. In particular you can fit Support Vector Machines which give good results in text classifications.
Finally, a last idea would be to use keyword extraction tools, such as the Alchemy API to summarize your documents to 10-20 relevant keywords. You can then use standard classification techniques on this dataset of reduced dimension.
As a good primer on text classification, I suggest Introduction to Information Retrieval (free), and Mining the Social Web... not free but probably available from the best pirate sites ;-)
Comment: Thank you! I'm not marking this as answered only because I need the second part, but the advice you gave was exactly what I'm looking for. I'm particularly taken with tf-idf
Comment: Looks like no other takers.


O hibernate salva duas vezes a entidade executado dentro do dialog do primefaces

Question: Quando o botão salvar está na página ele funciona normalmente e salva a entidade mas eu abro um dialog para confirmar os dados para serem salvos e o hibernate salva duas vezes muito estranho o método para salvar fora do dialog funciona corretamente mas dentro executa duas vezes.

    <f:facet name="header"><h:outputText value="CONFIRMAR VENDA" style="font-family: sans-serif"/></f:facet>
    <h:form id="formfinalizarvenda">

<h:outputText value="Cliente" styleClass="text"/>

<h:outputText value="#{vendaMB.clienteMB.clienteDAO.cliente.nome}" styleClass="text"/>

<h:outputText value="Pagamento" styleClass="text"/>

<h:outputText value="#{vendaMB.meioPgtoMB.meioPgtoDAO.meiopgto.descricao}" styleClass="text"/>

<h:outputText value="Total da Venda" styleClass="text"/>

<h:outputText value="#{vendaMB.totalVenda}" styleClass="text"><f:convertNumber type="currency"/></h:outputText>

<h:outputText value="#{ivadd.itemvenda.produto.codigo}"/>

<h:outputText value="#{ivadd.itemvenda.produto.descricao}"/>

                <h:outputText value="#{ivadd.itemvenda.valor}">
                    <f:convertNumber type="currency"/>
                </h:outputText>

<h:outputText value="#{ivadd.itemvenda.quantidade}"/>

<h:outputText value="#{ivadd.total}"><f:convertNumber type="currency"/></h:outputText>

    </h:form>

Este é o dialog para exibir os dados para confirmação.
O link que abre o dialog:

public void confirmarVenda() {
    for (Meiopgto meiopgto : meioPgtoMB.getMeiopgtos()) {
        if (meiopgto.getIdmeiopgto().equals(idmeiopgto)) {
            meioPgtoMB.getMeioPgtoDAO().setMeiopgto(meiopgto);
            break;
        }
    }
    RequestContext.getCurrentInstance().update(Arrays.asList("formvenda", "dialogconfirmarvenda"));
}

Comment: @RonaldoSantos, como você deve ter visto no [tour], você pode aceitar uma resposta, não utilize a abordagem de "Resolvido" no título como normalmente é feito em fóruns. Nessa pergunta em questão, você poderia elaborar uma resposta dizendo como chegou na solução e depois aceitá-la.
Comment: Ronaldo, bem vindo ao Stack Overflow. Para que possamos auxiliá-lo adequadamente é importante que você forneça as informações relevantes do ponto de vista técnico. Isso incluí enxertos de código, markup, configurações e tudo mais que for necessário para reproduzir o seu problema. Dê uma lida em [Como criar um exemplo Mínimo, Completo e Verificável](http://pt.stackoverflow.com/help/mcve) e tome o tempo que precisar para atualizar a pergunta.
Comment: Ronaldo, poderia incluir o código do botão que abre o `Dialog`? A minha suposição é que o botão tem um `action` chamando o método `vendaMB.finalizarVenda()`, e além de abrir o `Dialog` ele salva as informações.
Comment: Não esqueca de fazer uma menção (@Nome), senão eu não sou notificado. A minha sugestão seria colocar um Breakpoint no método que é chamado duas vezes e olhar o stacktrace para ver como ele é chamado nessas duas vezes. Isso talvez dê uma dica do problema.
Comment: Ronaldo, eu queria que você colocasse um **Breakpoint** e debugasse no método que faz a chamada ao JPA. E se possivel incluir o stacktrace que aparece na perspectiva de Debug.
Comment: Algumas possibilidades (o problema de não ter um [MVCE](http://pt.stackoverflow.com/help/mcve) é não poder afirmar nada com precisão). Será que seu dialog não está dentro de um form e isso está disparando o evento duas vezes? Será que algum outro `listener` como `#{vendaMB.closeDialog()}` ou `#{vendaMB.finalizarVenda()}` não está chamando esse método?
Comment: @Anthony Accioly eu retirei o **binding="#{vendaMB.dialogconfirmarvenda}"** e funcionou - não sei por que - e valeu pela ajuda.
Answer: Eu resolvi o problema removendo o binding="#{vendaMB.dialogconfirmarvenda}" do Dialog


prenex normal form quantifiers predicates

Question: Are these if and only if equalities always true ?
1 - $\exists x \exists y \;(P(x) \;and \;Q(y))\Leftrightarrow \exists x P(x) \; and \;\exists y   \;Q(y)$
2- $\exists x \exists y \;(P(x) \;or \;Q(y))\Leftrightarrow \exists x P(x) \; or \;\exists y   \;Q(y)$
3- $\forall x \forall y \; (P(x) \;or \;Q(y)) \Leftrightarrow  \forall x P(x) \;or\; \forall y Q(y) $
4- $\forall x \forall y \; (P(x) \;and \;Q(y)) \Leftrightarrow  \forall x P(x) \;and\; \forall y Q(y) $
Answer: They all hold. (1): If $P(x_0)$ and $Q(y_0)$ are both true, then certainly $P(x_0)$ and
$Q(y_0)$ is. Similarly, if either of those holds, then $P(x_0)$ or $Q(y_0)$ is true.
For the universally quantified sentences, the same argument gets the right-to-left implications. For the left-to-right in 3, suppose I had $x_0, y_0$ so $P(x_0)$ and $Q(y_0)$ were both false. Then the left-hand side would fail as well. So, by the contrapositive, if I get the left-hand side I get at least one disjunct on the right. Think you can extend the argument to (4) now?
Comment: 3 is false I think
Comment: P(x2) true Q(y2) false,  P(x1) false Q(y1) true, then right hand side is false and left is true
Comment: For the left hand side you've only made two of the four possible pairings. Under a $\forall$ we need to be able to fix $x$ and then vary $y$ across all its values, and vice versa, so you also need to check $P(x_2)$ or $Q(y_1)$, as well as $P(x_1)$ or $Q(y_2)$. Only three of the four hold.
Comment: Sure, but I dont think there is a need to check for both cases if you have one false example
Comment: No, I agree with you that the right hand side is false, but I'm saying the left hand side is also false because there's a choice of $x$ and $y$ making $(P(x)$ or $Q(y))$ false.


How to send Array as Body to a Web Service in android with Volley library?

Question: I'm trying to send a data as an array to a web service and I using Volley library to do that, but in a part of my code I should send an Array as Body. So I'm using the below code for another part of my project then give a JSON object as a body but now I want to send a body as an array.
my array
[
  {
    "name": "a",
    "family": "f"
  },
  {
    "name": "b",
    "family": "f"
  },
  {
    "name": "c",
    "family": "f"
  }
]

String url = "";
            try {
                JSONObject jsonBody = new JSONObject();
                jsonBody.put("name", name);
                jsonBody.put("family", family);
                //request a json object response
                JsonObjectRequest jsonRequest = new JsonObjectRequest( Request.Method.POST, url, jsonBody, new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {

                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                    }
                }) {    //this is the part, that adds the header to the request
                    @Override
                    public Map<String, String> getHeaders() {
                        Map<String, String> params = new HashMap<String, String>();
                        params.put("Content-Type", "application/json; charset=utf-8");
                        return params;
                    }
                };
                // Add the request to the queue
                Volley.newRequestQueue(Activity_Goods_List.this).add(jsonRequest);
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), e.getMessage().toString(), Toast.LENGTH_LONG).show();
            }

Comment: I wanted to add this below your new question, posted as an answer, but that was removed before I could finish. Stack Overflow is not a discussion forum, it's a Q&A repository. That means every new problem must be asked in a new question. Also, it's important to mark any contribution that answers your question as "the" answer by clicking on the checkmark at its left. This helps the site quality by telling others what helped and that the question is taken care of. Also, it thanks the person who put in the work and time to help with site points.
Answer: Add your objects to array-like this
Let us assume you have a list of names and family
    JSONArray request=new JSONArray();
    for(int i=0; i<names.size; i++){
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("name", names.get(i));
        jsonBody.put("family", family.get(i));
        request.put(jsonBody);
    }
    // You'll have array ready here for your request

Answer: You can send as a json array. Encode the Array into JSON and sent to your backed. From your backend, you can parse JSON and retrieve back the array. You can't directly send the array, You have to follow data transfer formats like json or xml
Comment: thanks for your attention. dear I'm using Json format. but what I should do for that. you said I should send as json array but how to can do that
Comment: `JSONArray mJSONArray = new JSONArray(Arrays.asList(mStringArray));` or you can use Json Library like `Gson`


Convergence of $\sum^\infty_{n=0} \frac{\cos(n + \frac{1}{n^2})}{n \cdot \ln(n^2 + 1)}$ Is my idea correct?

Question: Convergence:
$$\sum^\infty_{n=0}\frac{\cos \left(n + \frac{1}{n^2} \right)}{n \cdot \ln \left( n^2 + 1 \right)}$$
Edit (I tried to follow the idea written by @Daniel Fischer):
$$\sum_{n=0}^{\infty} \frac{cos(n + \frac{1}{n^2})}{n\cdot ln(n^2 + 1)} = \sum_{n=0}^{\infty} \frac{cos(n)}{n \cdot ln(n^2 + 1)} + \sum_{n=0}^{\infty} \frac{cos(n + \frac{1}{n^2}) - cos(n)}{n \cdot ln(n^2 + 1)}$$
$\sum_{n=0}^{\infty} \frac{cos(n)}{n \cdot ln(n^2 + 1)}$ is convergent because of Dirichlet test and How can we sum up $\sin$ and $\cos$ series when the angles are in arithmetic progression?
$\sum_{n=0}^{\infty} \frac{cos(n + \frac{1}{n^2}) - cos(n)}{n \cdot ln(n^2 + 1)} = \sum_{n=0}^{\infty} \frac{-2 \left(sin \left( \frac{2n+\frac{1}{n^2}}{2} \right) \cdot sin \left( \frac{\frac{1}{n^2}}{2} \right) \right)}{n \cdot ln \left(n^2 + 1 \right)} = \sum_{n=0}^{\infty} \frac{-2 \left(sin \left( n+\frac{1}{2n^2} \right) \cdot sin \left( \frac{1}{2n^2} \right) \right)}{n \cdot ln \left(n^2 + 1 \right)}$
Then:
$$\sum_{n=0}^{\infty} \left| \frac{-2 \left(sin \left( n+\frac{1}{2n^2} \right) \cdot sin \left( \frac{1}{2n^2} \right) \right)}{n \cdot ln \left(n^2 + 1 \right)} \right| \leq \sum_{n=0}^{\infty} \left| 2 \cdot \frac{ \frac{1}{2n^2} }{n \cdot ln \left(n^2 + 1 \right)} \right| \leq \sum_{n=0}^{\infty} \left| \frac{ 1 }{n^3 \cdot ln \left(n^2 + 1 \right)} \right| $$
For $n \geq 3$:
$$\sum_{n=0}^{\infty} \left| \frac{ 1 }{n^3 \cdot ln \left(n^2 + 1 \right)} \right| \leq \sum_{n=0}^{\infty} \left| \frac{1}{n^2} \right|$$
Therefore we know that $\sum_{n=0}^{\infty} \frac{cos(n + \frac{1}{n^2}) - cos(n)}{n \cdot ln(n^2 + 1)}$ it is also convergent. Is that correct?
Comment: Write $$\cos\biggl(n + \frac{1}{n^2}\biggr) = \cos n + \biggl(\cos \biggl(n + \frac{1}{n^2}\biggr) - \cos n\biggr)\,.$$
Comment: @Daniel Fischel could you tell me if I did it correct? I tried to use your hint.
Comment: I see now (overlooked it yesterday) that you start your summation at $n = 0$, but the term for $n = 0$ is undefined. Start the summation at $n = 1$ (or later). Apart from that, everything is correct. At the end, the $n \geq 3$ is a little odd (I guess it comes from $\ln n \geqslant 1$ for $n \geqslant 3$, but here we could use $\ln (n^2+1) > 1$ for $n \geqslant 2$). Also that you use $\frac{1}{n^2}$ for the comparison rather than $\frac{1}{n^3}$ is a little odd. I have two ideas why you did that, a) you prefer to use a more "famous" series for comparison,
Comment: or b) you prefer to use a weaker result when that suffices. Both are valid and often useful strategies, but if not made explicit can lead to the question "Why did the author not use [whatever] here?". Depending on the background, it can be simpler/preferable to use the mean value theorem to estimate the difference of the cosines rather than the addition theorem plus $\lvert \sin x\rvert \leqslant \lvert x\rvert$ as you did. It's less to type at least. But the addition theorem may be available before differentiation, so that's (possibly) a more elementary way.
Answer: Continuing from the remark made in the comments,
$$\cos\biggl(n + \frac{1}{n^2}\biggr) = \cos n + \biggl(\cos \biggl(n + \frac{1}{n^2}\biggr) - \cos n\biggr).$$
The second term on the right decays like $1/n^2$, since cosine is Lipschitz continuous (prove this using the cosine sum identity). The partial sums of the first term on the right are uniformly bounded; to see this, it is convenient to remember cosine is the real part of the complex exponential,
$$ \cos n =  \operatorname{Re} e^{in}. $$
Thus the partial sum of cosine is just the real part of a nice geometric series,
$$ \sum_{n = 0}^m \cos n = \operatorname{Re} \sum_{n = 0}^m e^{in} = \operatorname{Re} \frac{1 - e^{i(m + 1)}}{1 - e^i}. $$
The right hand side has uniformly bounded modulus in $m$, so we are done.
Comment: @mymathc yes your solution is essentially equivalent to mine, you implicitly proved Lipschitz continuity of cosine in your solution.
Comment: I like that solution. Could you check mine? I will mark your answer as the correct one if everyting is ok.
Comment: Thank you, finally, that makes me happy :D


Hypothesis Testing Question: Average Given, no Level of Significance

Question: I ended up stuck on this review problem and I'm not quite sure where to go from where I got stuck.
The question is: A population distribution is known t have standard deviation 20. Determine the p-value of a test of the hypothesis that the population mean is equal to 50, if the average of 64 observations is 52.5.
std dev = 20
pop. mean = 50
n = 64 observations
avg = 52.5
z = absval(xbar - 50) / (20 / sqrt(64))
I plug in 52.5 for xbar, but I'm not sure where to go from here to obtain the p-value.
Is it p-value = P(z > 2.5/(20/8)), where 52.5 is xbar plugged in? The problem here is that I don't have a level of significance given, so I can't really look-up the z-distribution table. Can someone please give me an explanation for this?
Answer: You don't need a level of significance to simply find the $p$-value. All you need to do is compute the test statistic:
\begin{equation}
z_t = \frac{52.5-50}{\frac{20}{\sqrt{64}}}=1
\end{equation}
Since you are doing a two-tailed test, using $z_t=1$ yields a $p$-value of $0.3174$
Comment: Why is the p-value .3174 instead of .1587? I think I'm using a table that represents something else (one-tailed test, I think it was called?)? Could you please explain that, if you can? EDIT: Oh, never mind, you just multiplied it by 2 to get the two tails. Thank you for the quick answer.
Comment: You are correct in that $0.1587$ would be the $p$-value for a one-tailed test. Here, you are asked to test equality; the alternative hypothesis would be "not equal to", which is a two-tailed test. To compute the $p$-value for a two-tailed test, simply double what you see in your table.
Comment: Are you sure? I asked a TA and he said the value would be 1 - (z(t) = 1), which is 1 - .8413 and therefore .1587.
Comment: It's $0.1587$ if your alternative hypothesis is a one-tailed test. It's twice that if your alternative hypothesis is a two-tailed test -- I read the question as having a two-tailed alternative hypothesis.
Comment: Understood, I can see it now. There aren't any specifications of making it a one-tailed test.


If $(Y_1, Y_2)$ are bivariate Normal, why is it true that $Y_2 = \rho Y_1+(1-\rho^2)Z$ where $Z$ is a normal independent of $Y_1$?

Question: If $(Y_1, Y_2)$ are bivariate Normal with correlation $\rho$ and $Y_i$'s marginally $N(0,1)$, why is it true that we can express $Y_2 = \rho Y_1+(1-\rho^2)Z$ where $Z$ is a standard normal independent of $Y_1$?
Answer: 1) The normal distribution is stable: linear combinations of independent normal distributions are again normal. Proof: either explicit calculation of CDF, or just use characteristic functions.
2) A normal distribution is uniquely determined by it's mean and variance.
So, first verify that $Y_2$ is normally distributed like $N(0,1)$. Next verify that $\mbox{corr}(Y_1,Y_2)=\rho$. Then you're done.
Comment: Is there a standard way to derive this? The way I see it right now it seems to have popped out of thin air.
Comment: @user321627: Not really. It's more to do with the stability of the normal distribution. Another example is the Poisson distribution which can exhibit similar decompositions.


Please help me interpret these Wilcoxon signed-rank test results

Question: I have 4 sets of data points and for each I want to see how much these values vary from zero.
I used the tool for calculating the results of the test on this page but I'm having trouble understanding the results.
The results for my 4 sets of data points are:
<code>W+ = 3,       W- = 12,      N = 5,   p <= 0.3125     for 101 data points
W+ = 12,      W- = 3,       N = 5,   p <= 0.3125     for 101 data points
W+ = 451,     W- = 1089,    N = 55,  p <= 0.007618   for 297 data points
W+ = 950.50,  W- = 427.50,  N = 52,  p <= 0.01746    for 297 data points
</code>
Please could you tell me which values I should be looking at and what the mean in terms of the above results?
Do the low p values mean that the variance from zero is not significant?
Thanks.
Comment: @PeterFlom In fact the signed rank test tests whether a *univariate* (one-sample) median is different from zero, assuming symmetry under the null. When applied to *differences among pairs*, it's a paired test that satisfies the symmetry-in-differences by assuming the pairs have the same distributional shape. This is the same issue as we have with the sign test - it's *actually* a univariate test for a median of zero, but when applied to differences between pairs becomes a paired test. I'm guessing you already knew all that - but it might mislead people with less statistical background.
Comment: The Wilcoxon signed rank test you linked to is for paired data. You don't seem to have paired data. Are you trying to see if the mean is different from 0? Or the median? Or something else?
Comment: @Peter, my data is formed of pairs, so by one data point I mean one pair of values. For a pair (x, y) I have the actual value for X and y is always zero (the expected value). I want to know how significantly the x values vary from zero.
Answer: As you can read here, for example, the null hypothesis (or one version of it) for the signed-rank test is that the median difference is zero.
The p-value always means the probability that the observed test statistic (which is calculated based on your specific observations) would be as extreme as observed (or more extreme), if the null hypothesis were true.
So, a small p-value means that the observed result is highly unlikely if the null hypothesis were true. Consequently, we conclude (since we do observe this result) that the null hypothesis is unlikely to be true, and reject it.
Conclusion (disregarding other issues with your data and multiple testing correction): for the tests where the p-value is below a certain threshold (typically 0.05), we conclude that the median difference is significantly different from 0. For the others, we have no proof that it is significantly different (but it might still be in the population).
Comment: So, for my first two sets of results, where p=0.3125, the median difference is not significantly different from zero?
Comment: As per my last sentence: you do not have proof that it is, nor that it doesn't. The phrase typically used for this is "we cannot reject (at ... significance level)" that the median difference is zero.


UINavigationControllerDelegate method call crash when WYPopover used in project

Question: I'm working on an app that incorporates WYPopoverController and it works great in place where it should. I want to add custom animations between two controllers, instead of built in push / pop.
In navigation controller containing FROM and TO controllers I don't do anything related to the WYPopoverController, neither in controllers FROM and TO.
I've implemented navigation controller delegate, really simple and animator class that handles actual animation.
public class NavigationControllerDelegate: NSObject, UINavigationControllerDelegate {

let animator = Animator()

public func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {

    if operation == UINavigationControllerOperation.Pop {
        return self.animator
    }

    return nil
}
}

Animator class:
class Animator: NSObject, UIViewControllerAnimatedTransitioning {

public func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval {
    return 0.33
}

public func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
    let toVC = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)!
    let fromVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)!

    transitionContext.containerView().addSubview(toVC.view)
    toVC.view.alpha = 0

    UIView.animateWithDuration(self.transitionDuration(transitionContext), animations: { () -> Void in
        fromVC.view.transform = CGAffineTransformMakeScale(0.1, 0.1)
        toVC.view.alpha = 1
    }) { (finished) -> Void in
        fromVC.view.transform = CGAffineTransformIdentity
        transitionContext.completeTransition(!transitionContext.transitionWasCancelled())
    }
}
}

In the FROM controller I initialize navigation delegate
override public func viewDidLoad() {
    super.viewDidLoad()
    // ... some other code here
    self.navigationController?.delegate = NavigationControllerDelegate()
}

Everything compiles and runs up until the point when I tap the (collection) cell and want to move to TO controller. At that point app crashes with error:
    -[CALayer navigationController:animationControllerForOperation:fromViewController:toViewController:]: unrecognized selector sent to instance 0x7fc72e53e970
I've added a breakpoint and I end up inside sizzled_pushViewController:animated: method of UINavigationController. To be honest I have no idea how to approach the issue.
Answer: As it turns out, solution has nothing to do with the WYPopoverController whatsoever. Apparently setting navigation controller delegate from within its root controller is not the way it should be done. I manage to refactor my code to get rid of the aforementioned library, but it was still crashing with the very same exception.
-[CALayer navigationController:animationControllerForOperation:fromViewController:toViewController:]: unrecognized selector sent to instance 0x7fc72e53e970
At that point I was really confused. After some more digging and hair pulling I got working solution. I initialised navigation controller delegate in storyboard and all pieces fell into right place.
Comment: Same error. And indeed, the issue is in the navigation delegate. Looks like at some moment `WYPopoverController` triggers that method and refers to the delegate. In my case I set a controller to the delegate and once it was deallocated, the delegate still kept the reference.
Answer: The WYPopoverController is using Method Swizzling to Swizzle the pushViewController:animated for the UINavigationController
So basically when you see the [self sizzled_pushViewController:aViewController animated:aAnimated]; selector being called there, it means that your pushViewController:animated selector is actually called, as the method has been swizzled.
Now regarding your crash, it seems that instead of the selector navigationController:animationControllerForOperation:fromViewController:toViewController: being sent to the UINavigationController, it is being sent to the CALayer, which of course doesn't respond to that and the app crashes.
Why this is happening I cannot guess from what I see here, but what I said, hopefully will get you on the correct track
Comment: yes, I know that ;) I've done my homework before posting it here and on GitHub. I have no idea why the hell it's calling CALayer when delegate is set to object of my class...


Is the following intersection of a set and a $\sigma$-algebra also a $\sigma$-algebra

Question: Consider the statistical experiment of a dice roll. A probability space with $\left\{\Omega, \mathscr{F}, P\right\}$. Now $\Omega =\{1,2,3,4,5,6\}$, and $\mathscr{F}$ is the  $\sigma$-algebra containing all the subsets of $\Omega$, while $P$ is the associated probability measure. Suppose we know that the outcome of the experiment is contained in the set $B=\{2,4,6\}$, while we consider the possibility of $A=\{1,2,3\}$. Clearly $A\cap B=\{2\}$.
My book says that, since the sample space has shrunk, $\mathscr{F}$ will also shrink in this way: $\mathscr{F}\cap B=\left\{ A\cap B, A \in \mathscr{F}\right \}$ and asks me to check whether this is a  $\sigma$-algebra.

Shouldn't it be $ \mathscr{F}\cap B= \{ B, \{2\},\{4\},\{6\},\{2,4\},\{2,6\},\{4,6\},\emptyset \} $, so that every subset of $B$ is in $\mathscr{F}\cap B$?
If the above adjustment is made, is the resulting collection a  $\sigma$-algebra?

I am pretty sure that yes it is, since it contains all subsets of $B$ and therefore their complements and I can replicate those subsets, so that infinite countable unions are contained.
Any help or pointers are greatly appreciated.
Answer: If $\mathscr{F}$ is a sigma-algebra, and $B\in\mathscr{F}$ is any set, then the system
$$
\mathscr{F}\cap B:=\{A\cap B\mid A\in\mathscr{F}\}
$$
will always be a sigma-algebra (check this!) and is often called the trace sigma-algebra of $B$ or the induced sigma-algebra of $B$.
In your case where $\mathscr{F}=\mathcal{P}(\Omega)$ is the power set of $\Omega$, then
$$
\mathscr{F}\cap B=\mathcal{P}(\Omega)\cap B=\mathcal{P}(B).
$$
The last equality should be pretty obvious, but if it is not, then you can just prove it by showing two inclusions.
Comment: +1. One might mention explicitly at least once that in this context the notation $\mathscr{F}\cap B$ does not denote $\{x\mid x\in\mathscr{F},x\in B\}$ (most of the time, this would be the empty set) but the collection defined in this post after the symbol $:=$.
Comment: @option_select: Yes, exactly. One could have used $C$ instead of $A$ to avoid the possibility of confusion.
Comment: I would like to clarify the following: In this specific example $A=\{ 1,2,3 \}$ had a specific definition. I think that I was confused by the notation of reusing the $A$, since $A \cap B= \{ 2\}$ in the example. But here $A$ is used as an arbitrary set in $\mathscr{F}$, correct? Since with the specific $A$ and the specific $B$, $\mathscr{F} \cap B$ would just be $\{ 2\}$, right?
Comment: Great, thank you very much for your clarification.


Responsive UI-grid isn't working

Question: How to make Ui grid Responsive?? kindly help?

correct plz?
Answer: In general ui-grid won't do responsive - the nature of it's rendering cycle is that it needs to know how big it is going to be.  Having said that, the auto-resize plugin can do a lot of what you might want, or alternatively if your web-page has knowledge of when the size changed (perhaps you already have an event being triggered) then you could call the handleResize method whenever the size changes.

Responsive UI-grid isn't working


How to write validation mechanism for this situation- VB.NET?

Question: I have two bool checkboxes in the UI. At least one user is assigned to any of the fields. So when deleting the user, it has to check at least one user is checked with that fields or not.
Note: It's not mandatory that only single user is assigned to both check box fields. But for a checkbox, at least one user should be assigned.
If at least 1 user is available for that checkbox field, then we can give permission to delete the other user who is having the same fields.
Look at below code what I have tried:

When deleting the 2nd user having assigned with that field it gives me this message which is not correct validation. Because already 1 user is there, so we can delete the 2nd user.
If I write like countOfContractors < 1 and imagine only 1 user is having assigned with both fields, if I delete that user, 1<1 is false so it will be deleted. but it should not be deleted when 1 = 1.
Answer: You can try adding this to resolve the issue:
What with (countOfcontractors > 1)
Thanks


How to get a specific collection from a large json file

Question: I'm trying to get a specific collection from a large json file but i don't want to make all the object structure on the json file because i only need the "calls" and "puts" fields...
the jsonfile is this: https://query2.finance.yahoo.com/v7/finance/options/AEIS?formatted=true&lang=en-US&region=US&corsDomain=finance.yahoo.com
this is my class options... not posting getters and setters..
public class Option {

  public enum Type { PUT, CALL }
  @JsonIgnore
  public Type type;
  @JsonProperty("contractSymbol")
  private String contractSymbol;
  @JsonProperty("contractSize")
  private String contractSize;
  @JsonProperty("currency")
  private String currency;

  @JsonProperty("inTheMoney")
  private boolean inTheMoney;
  @JsonProperty("percentChange")
  private Field percentChange;
  @JsonProperty("strike")
  private Field strike;
  @JsonProperty("change")
  private Field change;
  @JsonProperty("impliedVolatility")
  private Field impliedVolatility;
  @JsonProperty("ask")
  private Field ask;
  @JsonProperty("bid")
  private Field bid;
  @JsonProperty("lastPrice")
  private Field lastPrice;

  @JsonProperty("volume")
  private LongFormatField volume;
  @JsonProperty("lastTradeDate")
  private LongFormatField lastTradeDate;
  @JsonProperty("expiration")
  private LongFormatField expiration;
  @JsonProperty("openInterest")
  private LongFormatField openInterest;
}

and i'm trying to get data like this...
List<Option> res = JSON_MAPPER.readValue(new URL(link), new TypeReference<List<Option>>() {});

for(Option o: res){
  o.type = Option.Type.CALL;
  System.out.println(o.toString());
}

Aaand this is the exception...
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
    at [Source: https://query2.finance.yahoo.com/v7/finance/options/AEIS?formatted=true&lang=en-US&region=US&corsDomain=finance.yahoo.com; line: 1, column: 16] (through reference chain: java.util.HashMap["optionChain"])

Answer: The problem is that the json return from the source begins with a object property, "optionChain", which Jackson try to deserialize it as HashMap, but you expect a List after deserialized.
As you mentioned you only need the "calls" and "puts" in the json, you can use ObjectMapper.readTree to get the whole JsonNode first, then find the node of "calls" by JsonNode.findValue, and finally deserialize the node. Following is an example:
String link = "https://query2.finance.yahoo" +
            ".com/v7/finance/options/AEIS?formatted=true&lang=en-US&region=US&corsDomain=finance.yahoo.com";
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(new URL(link));
JsonNode calls = jsonNode.findValue("calls");
List<Option> callOptions = mapper.readValue(calls.traverse(), new TypeReference<List<Option>>() {});


Log odds ratio - what happens if linearity fails?

Question: I haven't found much info on this by googling so i thought maybe someone where has some answers for me.
When it comes to binary logistic regression the model assumes that the log odds ratio has a linear relationship with the independent variables. I'm wondering, what would happen to the model if this assumption was not fulfilled and furthermore, how would one tackle this problem to solve it?
Answer: You get biased and inconsistent coefficient estimates, and biased standard errors. Bias in standard errors can be in both directions and the probability of types I and II errors could increase.
You can tackle non-linearity by introducing different functional forms of the predictor that had a non-linear relationship with Y. Common functional forms are quadratic, logarithmic, cubic, square roots, among others. You can also think about including splines and possibly interactions between two or more predictors. A last possibility is to use a different link function for the binary relationship, as functions such as probit and clog-log have slightly different shapes, albeit all of them following a synodal shape.
Comment: +1. You can also use different link functions.
Comment: Indeed. I'll edit the answer to reflect that.
Answer: If the functional relationship between the exposure and average response is not an S-shaped logistic curve, there are still reasons why we might consider an S-shaped logistic curve as a meaningful summary of those data.
As an example, we might have omitted a prognostic factor from a model, meaning that the true marginal relationship between the exposure and the outcome is not logistic, but a complicated semi-logistic function that averages up risks across several conditional logistic curves. This is the principal of non-collapsibility in logistic regression.
Basically, we can rarely ever be certain that the S-shaped logistic trend is, in fact, the "right" one... but it is a useful one! All models are wrong, some models are useful.
Kenji is right that when we try to approximate an S-shaped trend, and the data show strong distributional violations, there may be some sensitivity analyses to consider like testing for higher order polynomial effects. Another type of test to consider is breakpoints, adjusting for "knots" so that trends can change direction. These approaches are hybridized in splines and made even more general by using LOESS curves to explore general non-linear relationships between exposures and outcomes.
Nonetheless, you may revert to the original question: you may say "I want to summarize these data using a single logistic curve whose intercept represents log-odds of the outcome for exposure=0 and whose slope is the log-odds ratio as a measure of association between an exposure and an outcome." The desire then is to obtain a robust error estimate that is unbiased and consistent. The S-curve then is taken to summarize a first order trend in the data, which you can think of as a rule of thumb: does the risk tend to increase or decrease as the exposure goes up, and by how much? To do this, you need only to apply sandwich based standard errors. This can be done using Generalized Estimating Equations with working independence covariance structure, logistic link, and binomial variance structure.
Comment: @Kenji yes and no. If the true trend relating an outcome to a covariate is exponential, the linear term has a true coefficient of 0. However, we can draw a straight line through that exponential trend over a domain and interpolate it somewhat. That linear approximation can be expressed analytically. The misspecified GEE actually estimates that approximation without bias and consistently.
Comment: +1 for mentioning splines and LOESS. Robust errors deal with the SE's being messed up by the violation of functional form, but won't coefficients be biased as well?
Comment: Oh. Makes sense. Would that work for all functional forms apart from exponential?
Comment: My bad. I misread your answer. You are trying to approximate only the first order trend to know if risk increases or decreases. Now I get it.
Answer: The assumption that your target probability can be modelled as a linear combination of log-odds ratios scaled by your inputs is equivalent to assuming that it is a combination of independent pieces of Bernoulli evidence.  When that's not the case, you typically build a more complex model with cross terms.
Seeing the logistic function as some arbitrary sigmoid link function really hides the assumption you're making.


rotating for loop in a cyclic process in java

Question: Here is my question: my for loop should rotate in cyclic process and the when it reaches to the value 7, it should start form 1.
and my newcost value should always be in increasing value.
here is my code:
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.joda.time.DateTime;
import org.joda.time.Days;

public class PayCalculation {

    int cost,cost1=0;
    private String fromdate, todate, npersons, nrooms, rooms;
    long newcost;
    public String execute() throws Exception{

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

        Date date1 = dateFormat.parse(fromdate);
        //Date date2 = dateFormat.parse(todate);
        Calendar c = Calendar.getInstance();
        c.setTime(date1);
    //  c.setTime(date2);
        int dayOfWeek1 = c.get(Calendar.DAY_OF_WEEK);
       // int dayOfWeek2 = c.get(Calendar.DAY_OF_WEEK);
        Date past = dateFormat.parse(fromdate);
        Date today = dateFormat.parse(todate);
        int days = Days.daysBetween(new DateTime(past), new DateTime(today)).getDays();

        System.out.println(dayOfWeek1 + "  day of the week");

        System.out.println(days + " no of days");
        int i;
        for(i=0 ; i<=days ; i++){

            System.out.println(i);

            if(i==1 || i==7){

                System.out.println("sun or sat");
                cost1=1500;
            //  newcost=cost1;
            }
            if(i==2 || i==3 || i==4 || i== 5|| i==6){

                System.out.println(" other days");
                cost=1000;
        //  newcost=cost;
            }
            /*if(i==7){
                System.out.println("i==7");
                i=1;
            }
*/          newcost=0+cost+cost1;

            System.out.println(newcost+" new cost");

        }

        System.out.println(newcost);
        return "success";

    }

Comment: Whats your question ?
Comment: So, did any of the below answers help you?
Answer: I don't understand why i==1 and i==7 should refer to Sunday and Saturday because days is a number of days, and I don't see in your code where it is said that 1 is a Sunday. But anyway, assuming it's correct, you should do that :
for(i=1 ; i<=days ; i++){
    if(i==1 || (i>=7 && (i%8==0 || i%7==0))){
        System.out.println("sun or sat");
    }else{
        System.out.println(" other days");
    }
}

I'm not sure if it fits your needs though because I'm sorry to say that your question is a bit vague
Answer: You can use modulo math to get the day of week, like int weekday = (i % 7) + 1 (plus some offset for the current day). To increase the newCost in each iteration, use newcost += cost + cost1.
However, this will increase newCost by 2500 in each week after the first, because you do not reset cost and cost1 in the loop. Either add cost = 0 and cost1 = 0 to the top of your loop, or better, change your loop body to just newCost += (weekday==1 || weekday==7) ? 1500 : 1000.
for (int i = 0; i <= days; i++) {
    int weekday = ((dayOfWeek1 + i) % 7) + 1;
    newCost += (weekday == 1 || weekday == 7) ? 1500 : 1000;
}

Answer: Your code had some mistakes, anyways you can put in another counter that keeps track of number of days (preventing infinite loop) and reset i at each occurence of i=7 , the following code works :-
    int i;
    int dayscounter=days;
    for(i=0 ; i<=days && dayscounter>0 ; i++ ,dayscounter--){

   System.out.println(dayscounter+":"+i);
      if(i==2 || i==3 || i==4 || i== 5|| i==6){

            System.out.println(" other days");
            newcost+=1000;
        }
        else if(i==1 || i==7){

            System.out.println("sun or sat");
            newcost+=1500;

            if(i==7){
                i=0; //reset i counter

            }

        }

        System.out.println(newcost+" new cost");

    }

    System.out.println(newcost);

Also note there is no need for cost and cost1 variables , you can directly increment newcost , because anyways in each iteration only one of the values 1000 or 1500 will be added to the newcost
Answer: //mention this one in global level.

 List<Date> dates = new ArrayList<Date>();

//mention all this in local level.
  String str_date = fromdate;
        String end_date = todate;

        System.out.println(fromdate+ "from date");
        System.out.println(todate + "to date ");

        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        startDate = (Date) formatter.parse(str_date);
        endDate = (Date) formatter.parse(end_date);
        long interval = 24 * 1000 * 60 * 60;
        long endTime = endDate.getTime();
        long curTime = startDate.getTime();

     while (curTime <= endTime) {
            dates.add(new Date(curTime));
            curTime += interval;
        }

 //gettig this mon,tue,.... cost from database from the another class.

accost = crc.getAc(ac);/*this is the calling function to the other class to get  the   cost from mon  . . . . . sunday .*/
        mon = accost[0];
        tue = accost[1];
        wed = accost[2];
        thr = accost[3];
        fri = accost[4];
        sat = accost[5];
        sun = accost[6];

    for (int i = 0; i < dates.size(); i++) {
            Date lDate = (Date) dates.get(i);
            // System.out.println(i);
            // System.out.println(dates.size());
            System.out.println(lDate);

            Calendar c = Calendar.getInstance();
            c.setTime(lDate);

            int dayOfWeek1 = c.get(Calendar.DAY_OF_WEEK);

            System.out.println(dayOfWeek1 + " day of the week");

            int sundaycost = sun;
            int saturdaycost = sat;
            int moncost = mon;
            int tuecost = tue;
            int wedcost = wed;
            int thrcost = thr;
            int fricost = fri;

            if (dayOfWeek1 == 1) {

                cost = cost + sundaycost;
                System.out.println("weekend sunday");
                System.out.println(cost);

            }
            if (dayOfWeek1 == 7) {

                cost = cost + saturdaycost;
                System.out.println("weekend saturday");
                System.out.println(cost);
            }
            if (dayOfWeek1 == 2) {

                System.out.println("weekday monday");
                cost = cost + moncost;

            }
            if (dayOfWeek1 == 3) {

                System.out.println("weekday tuesday");
                cost = cost + tuecost;

            }
            if (dayOfWeek1 == 4) {

                System.out.println("weekday wednesday");
                cost = cost + wedcost;

            }
            if (dayOfWeek1 == 5) {

                System.out.println("weekday thrusday");
                cost = cost + thrcost;
            }
            if (dayOfWeek1 == 6) {
                System.out.println();
                System.out.println("weekday friday");
                cost = cost + fricost;
            }
        }


Minimum eigenvalue of product of two matrices

Question: Abstract description:
Let $\mathbf{A}$ and $\mathbf{B}$ be two $n \times n$ real matrices. Let $\sigma( \mathbf{A B} )$ denote the spectrum of $\mathbf{A B}$.
Assume that
(A1) $\mathbf{A}$ is symmetric and positive definite but not diagonal.
(A2) $\mathbf{B}$ is not symmetric but similar to a symmetric and positive semidefinite (but not positive definite) matrix.
(A3) $\sigma( \mathbf{A B} ) \subset \mathbb{R}$.
Question 1: Do (A1) and (A2) imply (A3)?
Question 2: Can we say something about $\min\sigma( \mathbf{A B} )$?

Detailed description and background:
Let $G$ be a simple graph of order $m$. That is, $G$ is undirected and without loops. $G$ can have vertices with zero degree. Let $H$ denote the graph resulting from G by adding loops to all vertices with zero degree. Let $\mathbf{I}_m$ denote the identity matrix of order $m$ and $\mathbf{O}_m$ the zero matrix of order $m$. Let $\mathbf{S}$ denote the adjacency matrix of $H$. Hence, $\mathbf{S}$ is an $m \times m$ symmetric matrix with nonnegative entries. Let $\mathbf{D}$ be the degree matrix of $H$. Hence, $\mathbf{D}$ is an $m \times m$ diagonal and positive definite matrix. Let $c \in ( -1, 1)$. Note that $\mathbf{I}_m - c \mathbf{D}^{-1} \mathbf{S}$ is nonsingular because $\mathbf{D}^{-1} \mathbf{S}$ is a right stochastic matrix that has spectral radius equal to $1$. Define $\mathbf{M} := ( \mathbf{I}_m - c \mathbf{D}^{-1} \mathbf{S} )^{-1}$.
Conjecture: $\min\sigma( \mathbf{M} + \mathbf{M}' - \mathbf{I}_m ) > 0$ or, equivalently, $\mathbf{M} + \mathbf{M}' - \mathbf{I}_m$ is positive definite.
So far, my thoughts on a proof of this conjecture are as follows:
(P1) $\mathbf{D}^{-1} = \mathbf{P}^{2}$ with $\mathbf{P}$ diagonal and positive definite. That is, $\mathbf{P}$ is the unique square root of $\mathbf{D}^{-1}$.
(P2) $\mathbf{D}^{-1} \mathbf{S}$ is similar to the symmetric matrix $\mathbf{P} \mathbf{S} \mathbf{P}$. Indeed, $\mathbf{P}^{-1} \mathbf{D}^{-1} \mathbf{S} \mathbf{P} = \mathbf{P} \mathbf{S} \mathbf{P}$.
(P3) $\sigma( \mathbf{M} - (1/2) \mathbf{I}_m ) \subset \mathbb{R}$ because of (P2).
(P4) It can be shown that $\sigma( \mathbf{M} - (1/2) \mathbf{I}_m ) \subset ( 0, +\infty )$.
(P5) We have  $$\begin{align*}
& \sigma( \mathbf{M} + \mathbf{M}' - \mathbf{I}_m )\\
& = \sigma\bigl( \mathbf{M} - (1/2)  \mathbf{I}_m + \mathbf{M}' - (1/2) \mathbf{I}_m \bigr)\\
& = \sigma\bigr( \mathbf{P}^{-1} \bigl( \mathbf{M} - (1/2)  \mathbf{I}_m + \mathbf{M}' - (1/2) \mathbf{I}_m \bigr) \mathbf{P} \bigr)\\
& = \sigma\bigr( ( \mathbf{I}_m - c \mathbf{P} \mathbf{S} \mathbf{P} )^{-1} - (1/2)  \mathbf{I}_m + \mathbf{P}^{-2} ( \mathbf{I}_m - c \mathbf{P} \mathbf{S} \mathbf{P} )^{-1} \mathbf{P}^{2}- (1/2) \mathbf{I}_m \bigr)\\
& = \sigma\Biggl( \biggl( \begin{array}{c}\mathbf{I}_m\\\mathbf{I}_m\end{array} \biggr)' \biggl( \begin{array}{cc}\mathbf{I}_m & \mathbf{O}_{m}\\\mathbf{O}_{m} & \mathbf{P}^2\end{array} \biggr)^{-1} \biggl( \mathbf{I}_2 \otimes \bigl( ( \mathbf{I}_m - c \mathbf{P} \mathbf{S} \mathbf{P} )^{-1} - (1/2)  \mathbf{I}_m \bigr) \biggr) \biggl( \begin{array}{cc}\mathbf{I}_m & \mathbf{O}_{m}\\\mathbf{O}_{m} & \mathbf{P}^2\end{array} \biggr) \biggl( \begin{array}{c}\mathbf{I}_m\\\mathbf{I}_m\end{array} \biggr) \Biggr)\\
& \subset \sigma\Biggl( \biggl( \mathbf{I}_2 \otimes \bigl( ( \mathbf{I}_m - c \mathbf{P} \mathbf{S} \mathbf{P} )^{-1} - (1/2)  \mathbf{I}_m \bigr) \biggr) \biggl( \begin{array}{cc}\mathbf{I}_m & \mathbf{O}_{m}\\\mathbf{O}_{m} & \mathbf{P}^2\end{array} \biggr) \biggl( \begin{array}{c}\mathbf{I}_m\\\mathbf{I}_m\end{array} \biggr) \biggl( \begin{array}{c}\mathbf{I}_m\\\mathbf{I}_m\end{array} \biggr)' \biggl( \begin{array}{cc}\mathbf{I}_m & \mathbf{O}_{m}\\\mathbf{O}_{m} & \mathbf{P}^2\end{array} \biggr)^{-1} \Biggr)\\
& = \sigma\Biggl( \biggl( \mathbf{I}_2 \otimes \bigl( ( \mathbf{I}_m - c \mathbf{P} \mathbf{S} \mathbf{P} )^{-1} - (1/2)  \mathbf{I}_m \bigr) \biggr) \biggl( \begin{array}{cc}\mathbf{I}_m & \mathbf{D}\\\mathbf{D}^{-1} & \mathbf{I}_m\end{array} \biggr) \Biggr)\\
& = \sigma( \mathbf{A} \mathbf{B} ),
\end{align*}$$ where $\mathbf{A} := \mathbf{I}_2 \otimes \bigl( ( \mathbf{I}_m - c \mathbf{P} \mathbf{S} \mathbf{P} )^{-1} - (1/2)  \mathbf{I}_m \bigr)$ is symmetric and positive definite because of (P4) and $\sigma( \mathbf{M} - (1/2) \mathbf{I}_m ) = \sigma( \mathbf{P}^{-1} ( \mathbf{M} - (1/2) \mathbf{I}_m ) \mathbf{P} ) = \sigma( ( \mathbf{I}_m - c \mathbf{P} \mathbf{S} \mathbf{P} )^{-1} - (1/2) \mathbf{I}_m )$ and $$\mathbf{B} := \biggl( \begin{array}{cc}\mathbf{I}_m & \mathbf{D}\\\mathbf{D}^{-1} & \mathbf{I}_m\end{array} \biggr) = \dfrac{1}{\sqrt{2}} \biggl( \begin{array}{cc}\mathbf{I}_m & -\mathbf{I}_m\\\mathbf{D}^{-1} & \mathbf{D}^{-1}\end{array} \biggr) \biggl( \begin{array}{cc}2\mathbf{I}_m & \mathbf{O}_m\\\mathbf{O}_m & \mathbf{O}_{m}\end{array} \biggr) \biggl( \dfrac{1}{\sqrt{2}} \biggl( \begin{array}{cc}\mathbf{I}_m & -\mathbf{I}_m\\\mathbf{D}^{-1} & \mathbf{D}^{-1}\end{array} \biggr) \biggr)^{-1}$$ is (in general) not symmetric but similar to the symmetric and positive semidefinite matrix $$\biggl( \begin{array}{cc}2\mathbf{I}_m & \mathbf{O}_m\\\mathbf{O}_m & \mathbf{O}_{m}\end{array} \biggr) = \biggl( \begin{array}{cc} 2 & 0\\ 0 & 0 \end{array} \biggr) \otimes \mathbf{I}_m.$$ Note that $\sigma( \mathbf{M} + \mathbf{M}' - \mathbf{I}_m ) \cup \{ 0 \} = \sigma( \mathbf{A} \mathbf{B} )$, so that $\sigma( \mathbf{A} \mathbf{B} ) \subset \mathbb{R}$ because $\sigma( \mathbf{M} + \mathbf{M}' - \mathbf{I}_m ) \subset \mathbb{R}$.
Any ideas as to how to finish the proof? So far, I did not come up with a counter example.

EDIT:
I have reformulated assumption (A2) because it was stated inconsistently. It read as follows: $\mathbf{B}$ is not symmetric but similar to a nondiagonal, symmetric, and positive semidefinite matrix. In addition, I added the condition that $\mathbf{B}$ is not positive definite. I have also made some minor changes in Detailed description and background, which are related to $\mathbf{B}$.
Answer: According to the new statement, $A=\begin{pmatrix}20&-4&0\\-4&4&0\\0&0&1\end{pmatrix},B=\begin{pmatrix}1&0&0\\2&2&0\\0&0&0\end{pmatrix}$.
When the next change ?
Comment: Thanks. This example shows that assumptions (A1) and (A2) (in its original formulation) do not imply (A3).
Comment: No, in its current formulation.
Comment: Thank you for altering your example to match assumption (A2) in its current formulation. Thus, the answer to Question 1 is no.


On identity elements in monoids

Question: In the definition of a monoid firstly we should have associativity. What I wonder about is the definition of the identity element;
$\exists x \forall y\;\;  x.y=y.x=y $
Which structure do we get if we change the order of quantifiers in the definition? That is;
$\forall y \exists x \;\;  x.y=y.x=y $
Comment: Well, we get something weaker certainly, though still of interest. For example, if $R$ is a ring with unity, then the set of sequences of elements from $R$, which are $0$ from some point, becomes a ring where there is no unit for multiplication, but where the multiplication has the weaker version of a unit you describe here.
Answer: In some sense, neither property is that important, because if a semigroup doesn't have an identity you can just add one in (call it $e$) and define $ex = xe = x$ for all $x$.  Then the associative property still holds, and now both of your properties are satisfied.

Global identity: there exists $e$ such that $xe = ex = x$ for all $x$
Local identities: for all $x$ there exists $e_x$ such that $e_x x = x e_x$.

What about semigroups with local identities but no global identities?
I'm not sure.  Tobias Kildetoft gives a good example.  Many of the identities will work for multiple elements since $e_x (xyx) = (xyx) e_x = xyx$.  I couldn't find any references on this property being studied or named before.
Comment: Indeed, in the example I mentioned, any finite subset will have a "common identity" (but if the ring $R$ is finite, then no infinite subset will have such a "common identity").
Comment: @Goos Thanks for the answer. As far as I can see the existence of only local identities boils down to this: If all elements of the monoid can be written as $xyx$ then $e_x$ is the global identity. What happens if the premise is not true, I really don't know.
Answer: The structure I asked about seems very much like square matrices. They satisfy associativity and there may be more than one element acting as identity on an element.

On identity elements in monoids


How to recognize Java in CMD

Question: After installing Java Corretto 17 from Java 8, java-version is not recognized in CMD. Prior java projects are not compiling in my IDE.
I uninstalled prior JDK 8 and installed Corretto. I updated the path in my system and environmental variables, but to no avail. I am able to update each project individually with the Corretto in my IDE's project structure. I'm looking for a system wide solution.
Answer: You need to follow the instructions here - https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/windows-7-install.html
Specifically step 4:

Once the install wizard is finished, set the JAVA_HOME and PATH
environment variables.
Set JAVA_HOME to the installation location, noting that the directory
contains the currently-installed version. For example, if the default
directory is used for 17.0.0, then set JAVA_HOME as C:\Program
Files\Amazon Corretto\jdk17.0.0_35.
Add %JAVA_HOME%\bin to the current PATH variable.

Based on the symptoms you reported, it seems that you did not set PATH correctly ...

I'm looking for a system wide solution.

Make sure that you set the "system" versions of the variables.  But if there are user / account specific overrides for PATH and JAVA_HOME they will need to be updated also.  Note that you may need to restart your CMD shell to pick up changes that you made to environment variables via the GUI.  That's just the way that environment variables work ...

How to recognize Java in CMD


.net - Added a strong named assembly, but it is looking for unsigned assembly

Question: So, I have two projects... One is a big class library, and the other is a big simulator project.
Originally during testing the assemblies were not strong-named, but now that I need COM visibility, I need to strong name them (I need this quick, and it is easier to make them COM visible rather than deal with the CLI).
I generated a .snk and added it to the properties of each of the projects, the class library compiles just fine and outputs the .dll just fine. I added this .dll as a reference in the simulator project, but now the simulator project is giving me the following error:

The type "DynamicsControl" is defined in an assembly that is not
  referenced. You must add a reference to assembly "DynamicsControl,
  Version=0.4.3.0, Culture=neutral, PublicKeyToken=null"

The type DynamicsControl does exist in the class library (I verified), but it is claiming I am not loading the correct assembly. I believe it is the PublicKeyToken=null that is causing the issue (as my assembly would have a public key).
When I do sn -Tp DynamicsControl.dll (the one in the location I am referencing), it outputs the private and public key, so I know it has a proper signature.
What step am I missing? Do I have to add the assembly to the GAC? Do I manually have to add the public key?
Answer: Yes you need to specify the publicKeyToken for a strong named assembly otherwise it will look for unsigned version of the assembly. You can find out the public key token either by adding the assembly to GAC (and you will see it there) or by using the steps mentioned in the this link
If you want to read more about strong name and dll hell you can go to this URL .
Strong name prevents from dll hell which means you can have multiple versions of same assembly.
To your other question you don't have to add the assembly to GAC but CLR will look for the assembly first in GAC and then other places. Also, you don't have to add the key manually. If you remove the reference and add it back using the signed assembly it should automatically take the key.
Comment: I followed these steps several times... When I add the unsigned DLL I am still getting an error that it is not defined in an assembly, that I need to add the same assembly with a null public key.

Is there anyway I can obliterate the cache of the project or something? I've done Build -> Clean several times, but I can't help but feel like there is a file reference that is not being cleared up because its just a signed version of the same file...


Drupal Commerce payment transaction: execute script and pass variables

Question: When you need to create a new transaction method for Drupal Commerce, you need to dive into the code. And that's something I have zero experience with. BUT the following couldn't be hard. I already created a new payment module (just copied and edited the payment example module so I have a new payment method).
In commerce_payment_example.module you have the function commerce_payment_ideal_transaction that is been executed by the submit button of the checkout form. The only thing I need to do is to execute a script on submit (in HTML you can do this with <form method="post" action="script.php">, and pass three variables with it: the amount ($charge ?), the order ID ($order->order_id ?) and a description ($order ?). Could someone help me on the right way?
Comment: I don't know about you, but commerce payment methods are about money. I would *totally* not be comfortable running a payment method that is hacked by yourself when you have zero experience with programming.
Answer: the transaction is meant to be created on a successful response of your provider (this could be payed, denied or whatever), usually an IPN.
meaning you have to provide a MENU_CALLBACK item in hook_menu.
most likely information about the order will be posted, make sure you get the order id back.
if you really want that on the payment form submission, just call the method (commerce_payment_ideal_transaction) in the hook_redirect_form. the question here is, how do you decide if a payment was successful or not ;)


Is there any way to avoid using break; in while loop when the test include scanf()?

Question: In this while loop:
while (scanf("%lf", &first) == 1)
{
    printf("Enter your second float number (q to exit):\n");
    while (scanf("%lf", &second) == 1)
    {
        printf("The result is %f\n", (first - second) / (first * second));
        break;
    }
    printf("Enter your first float number (q to exit):\n");
}

I want to read an input and give it to second, then I want to quit this loop to the outer while loop so I can input a non-numerical character (e.g.q) given to first to jump out of the outer loop.
But I met this question in the book C Primer Plus, and the book haven't told me how to use break; or if before the question, so I wonder if there's an alternative way to do the same thing. Thanks in advance.
The original question:

Write a program that requests two floating-point numbers and prints
  the value of their difference divided by their product. Have the
  program loop through pairs of input values until the user enters
  non-numeric input.

What I wanted to do is to jump out the loop as either first or second is given to a non-numerical character.
Comment: In the code posted, the inner `while` loop is just acting as an `if` -- just change it to `if` and get rid of the break.
Comment: The code is your answer to that question from the book?
Comment: @Dmitri However, the book haven't told me how to use `if`...even I know a little about how to use it
Comment: @glauxosdever Yes~
Comment: "the book haven't told me how to use if" - A book teaching loops before conditional statements should be thrown out of the window! However, I strongly doubt it does. It is more likely you skipped a chapter.
Comment: @Olaf Check the 8th Programming Question in Chapter 6, *C Primer Plus, the 6th edition* and you'll find I'm just follow the reading order...and the `if` statement is just in Chapter 7
Comment: @MuYuanLi: So part 1 of my comment applies! Just that: you very likely have missunderstood the task.
Comment: @Olaf Maybe I am...with a statement of `break` and the question is very easy to solve, and I'm sometimes a hair-splitter, which is not a good habit in language study
Comment: I see, I'm heading a wrong way...I can use just one `scanf()` to get 2 inputs and then give them to `first` and `second` respectively!
Answer: Using while with an unconditional break will always do that code once exactly, and is therefore just as good as an if - as already said by @Dmitri. Moreover, break only gets out of the innermost relevant block - so in your case, it will not break out of the outer while block.
However, most break calls (and, without doubt, those that are at the very end of a block) can be easily replaced by just using the right condition in the while clause.
Please pay attention that your code currently reads double values (due to the %lf) anyway. In order to allow quitting by entering a 'q' char, you must change the way you read input. For example, one way might be to read a string and, if it is not "q", translate it to double.


SELECT a date that is greater than current date

Question: I have a MySQL database table where a single cell contains multiple dates and I am wanting to SELECT all rows that contain a cell where one or more of the dates is greater than todays date is this possible? (using PHP)
Comment: When you say cell you mean a column? so in one single column you have many dates? are they comma separated?
Comment: the field is a simple text field (this is my first project using MySQL and PHP so I accept it may not be the best way to store and use my data) the table is used to store events which may only occur on one date or occasionally many dates, past events are irrelevant so I only want to pull the row where the date field(set as a text field at the minute) contains a date that is in the future of 'today's' date...
Comment: The data is not currently comma separated but it is only test data and easily formatted...
Comment: The best thing would be to create another table only for dates with a relationship to the original table, one to many, in that way you will be able to have one row in the original table related to many date columns on the new table.
Answer: Sure:
select * from MyTable where MyDate > Now()

How does your single field contain multiple dates? Maybe you should consider a separate table for this instead.
Comment: From your example, I think MyDate has many dates inside according to @Michael Jones, that wont work.
Comment: You're right... I'm not sure how you can have many dates in a single field, at least not in MySql. PostgreSQL on the other hand allows horrors such as array date times.
Comment: the dates are currently stored in a 'text' field see comment on original post thanks
Answer: If the field is a DATE or DATETIME you can use
SELECT * FROM table WHERE datefield > NOW()

Answer: A "single cell contains multiple dates" .. is the crux of the problem. Here are three options.
Normalize/fix the schema
Start with an adequately normalized schema - in particular, any column/"cell" can have at most one date (or piece of information). This may or may not require introducing another table depending upon the role of the information.
This approach is scalable and works within the RDMBS/RA design and, if done, the other queries presented would "just work".
(This is by far the overall best option and should be done if at all possible. Proper normalization should also guide further schema development to mitigate such issues in the future.)
Create a normalized view
Create a normalized view of the denormalized table (or such a nomalizing query) that can be JOINed. Then use one the various suggested answers (that work on a normalized schema) .. albeit at an extreme disadvantage of not being able to utilize indices.
This is terribly messy, but it can be done. See SELECT de-normalized columns into separate records? for an example. (Note the synthesized row relationship here, although some [non MySQL] databases also support table-valued functions and cross applications of such.)
This approach does not scale because it cannot use indices.
Filter in client (PHP)
Fetch every row. Loop and use explode, etc, as appropriate.
This approach does not scale due to lack of indices and requiring all the data is fetched locally.

While finding equal values in denormalized columns can be done with various hacks (e.g. FIND_IN_SET), finding relative (i.e. larger/smaller) values is not possible with the same techniques. The solution that works in both cases is to fix the underlying schema.
Answer: If you are only after a DATE and not a DATETIME you can use CURDATE() instead of NOW()


Is there a limiting distribution if you keep taking conjugate priors within the exponential family?

Question: I'm assuming this is pretty commonly discussed but haven't found it yet.
For example, if you start with a binary (0-1 binomial), conjugate prior is beta distribution. Beta distribution has some un-named conjugate prior. You can take the conjugate prior of that.
Is there anything interesting coming of this? Anything useful? Looking for links and references mostly.
Answer: No, there is no end to this process, and you always end up with a distribution having one additional parameter.
Copied from my answer here:
Let's say that you have a distribution $F$ in the exponential family with density
\begin{align}
\newcommand{\mbx}{\mathbf x}
\newcommand{\btheta}{\boldsymbol{\theta}}
f(\mbx \mid \btheta) &= \exp\bigl(\eta(\btheta) \cdot T(\mbx) - g(\btheta) + h(\mbx)\bigr)
\end{align}
Given independent realizations $\{x_1, x_2, \dotsc, x_n\}$ of $F$ (with unknown parameter $\theta$), then the distribution over $\theta$, $F'$, is the conjugate prior of $F$.  The density of $F'$ is
\begin{align}
f(\btheta \mid \boldsymbol\phi) = L(\btheta \mid \mbx_1, \dotsc, \mbx_n)
&= f(\mbx_1, \dotsc, \mbx_n \mid \btheta) \\\\
&\propto \prod_i f(\mbx_i\mid \btheta) \\\\
&= \textstyle\prod_i\exp\Bigl(\eta(\btheta) \cdot \textstyle T\left(\mbx_i\right) - g(\btheta) + h(\mbx_i)\Bigr) \\\\
&\propto \textstyle\prod_i\exp\Bigl(\eta(\btheta) \cdot \textstyle T\left(\mbx_i\right) - g(\btheta)\Bigr) \\\\
&= \textstyle\exp\Bigl(\eta(\btheta) \cdot \bigl(\textstyle\sum_iT\left(\mbx_i\right)\bigr) - ng(\btheta)\Bigr) \\\\
&= \exp\bigl(\eta'(\boldsymbol \phi) \cdot T'(\btheta)\bigr)
\end{align}
where
\begin{align}
\eta'(\boldsymbol\phi) &=
\begin{bmatrix}
\sum_iT_1(\mbx_i) \\\\
\vdots \\\\
\sum_iT_k(\mbx_i) \\\\
-\sum_i1
\end{bmatrix}
&
T'(\btheta) &=
\begin{bmatrix}
\eta_1(\btheta) \\\\
\vdots \\\\
\eta_k(\btheta) \\\\
g(\btheta)
\end{bmatrix}.
\end{align}
Thus, $F'$  is also in the exponential family ($T'$ replaced $\eta$ and $\eta'$ replaced $T$ since this distribution is over $\theta$ the parameter of the distribution over $x$.)
Interestingly, $\boldsymbol\phi$ has exactly one more parameter than $\btheta$ except in the rare case where  natural parameter $\phi_{k+1}$ is redundant, but such a distribution would be very weird (it would mean that the number of observations $\mbx$, that is, $n$, tells you nothing about $\btheta$.)
So, to answer your question, with each conjugate prior you get exactly one more hyperparameter.
Comment: (+1) Indeed, the next conjugate remains within an exponential family and the extra parameter that was a scale term gets another conjugate that is also within an exponential family.
Comment: @mathtick See my edit.
Comment: Interesting ... but isn't one of those parameters kind of the weight of the prior and you can set it to one or something fixed? If you do that or something like this are there any results on convergen of the sequence?


What is the result of $ \lim_{n \rightarrow \infty} \frac{ 2^n }{ n! } $ and why?

Question: What is the result of the next limit: $ \displaystyle\lim_{n \rightarrow \infty} \frac{ 2^n }{ n! } $
Why (theorem)?
Comment: You could of course use stirling, but its not really necessary.
Comment: @Prism Looked into it. It's definately a duplicate; flagged as such.
Comment: http://math.stackexchange.com/a/77561/8581, I think, could be the best.
Answer: $$\frac{2^n}{n!} = \frac{2}{n} \cdot \frac{2}{n - 1}\cdot  \frac{2}{n - 2}\cdot  \dots \cdot \frac{2}{2}\cdot  \frac{2}{1} \leq \frac{2}{n} \frac{2}{2} \frac{2}{2} ... \frac{2}{2} \frac{2}{1} = \frac{4}{n} \to 0$$
as $n \to \infty$.