How do I populate report page using a controller?

Question: I'm following this tutorial on creating a report page for a custom plugin, but note that I'm using Drupal 9, and not Drupal 8 as per the tutorial.
I've created a report() method inside my implementation of ControllerBase:
<?php
/**
 * file
 * Contains \Drupal\rsvplist\Controller\ReportController
 */

namespace Drupal\rsvplist\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Database;
use Symfony\Component\HttpFoundation\Response;

/**
 * Controller for RSVP List Report
 */

class ReportController extends ControllerBase {

  /**
   * Gets all RSVPs for all nodes.
   *
   * @return array
   */
  protected function load() {
    $select = Database::getConnection()->select('rsvplist', 'r');

    // join the users table, so we can get the entry creator's username
    $select->join('users_field_data', 'u', 'r.uid = u.uid');

    // join the node table, so we can get the event's name
    $select->join('node_field_data', 'n', 'r.nid = n.nid');

    // Select the specific fields for the output
    $select->addField('u', 'name', 'username');
    $select->addField('n', 'title');
    $select->addField('r', 'mail');

    $entries = $select->execute()->fetchAll(\PDO::FETCH_ASSOC);

    return $entries;
  }

  /*
   * Creates the report page
   *
   * @return array
   *   Render array for report output.
   */
  public function report() {
    $headers = [
      t('Name'),
      t('Event'),
      t('Email'),
    ];

    $rows = [];
    foreach ($this->load() as $entry) {
      // sanitise each entry
      $rows[] = array_map('Drupal\Component\Utility\SafeMarkup::checkPlain', $entry);
    }

    return [
      ['table'] => [
        '#type' => 'table',
        '#header' => $headers,
        '#rows' => $rows,
        '#empty' => t('No entries available'),
      ],
      ['message'] => [
        '#markup' => t('Below is a list of all Event RSVPs including username, email address and the name of the event they will be attending.'),
      ]];

  }
}

My routing file seems to be set up correctly since I see the link to the report page:

However, when I navigate to the report page, I just see a blank page;

I thought perhaps I'm supposed to return a HTTPFoundation\Response object, so I tried this;
$response = new Response();
$response->setMaxAge(0);
$response->setContent('hello world');

return $response

But that seemed to have the effect of completely nuking the HTML of my page and just printing "hello world" to the screen with all menu items gone, so clearly that's not correct either. What am I doing wrong here? Better yet, where should I go to learn about how to do this correctly?
Comment: A response is sent to the browser as it is. If you want a themed page you have to return an array. But your array looks weird. Try to remove the extra brackets from the top level keys `['table']` and `['message']`.
Answer: A controller needs to return a render array for the page content. It is explained in Routing API and page controllers / Route controllers for simple routes.

The only requirement is that the method specified in your *.routing.yml file returns:

A render array (see the Theme and render topic for more information). This render array is then rendered in the requested format (HTML, dialog, modal, AJAX are supported by default). In the case of HTML, it will be surrounded by blocks by default: the Block module is enabled by default, and hence its Page Display Variant that surrounds the main content with blocks is also used by default.
A \Symfony\Component\HttpFoundation\Response object.

It's exactly what DbLogController::overview(), the controller method for the Recent log messages (/admin/reports/dblog) route, does.
  $build['dblog_table'] = [
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => [
      'id' => 'admin-dblog',
      'class' => [
        'admin-dblog',
      ],
    ],
    '#empty' => $this->t('No log messages available.'),
    '#attached' => [
      'library' => [
        'dblog/drupal.dblog',
      ],
    ],
  ];
  $build['dblog_pager'] = [
    '#type' => 'pager',
  ];
  return $build;

(The Database Logging module also adds a pager, which is helpful when the rows to show could be too much, or they would make the rest of the page rendered too low in the page.)
What is wrong in your code is that it uses an array containing a string as array index, instead of a string. Any PHP version that supports the short array syntax would throw Fatal error: Illegal offset type. (The other versions would throw Parse error: syntax error, unexpected '[' since they don't support the short array syntax.)
The return instruction should be the following one.
    return [
      'table' => [
        '#type' => 'table',
        '#header' => $headers,
        '#rows' => $rows,
        '#empty' => t('No entries available'),
      ],
      'message' => [
        '#markup' => t('Below is a list of all Event RSVPs including username, email address and the name of the event they will be attending.'),
      ]
    ];

Comment: Thanks for explaining and providing helpful links.


Ubercart 2.x: Given a product nid, retrieve its manufacturer

Question: I'm trying to figure out how Ubercart stores manufactures.
Currently it's set up as a Vocabulary, but I can't figure out how to grab that info programmatically given a product nid.
Any advice?
Comment: Is this for Drupal 6 or 7?
Comment: @Clive: Drupal 6 (added tag)
Answer: In Drupal 6 taxonomy terms are linked to the node object, Ubercart just piggy-backs off the way Drupal core handles this.
You can use the very handy taxonomy_node_get_terms_by_vocabulary() function to grab all of the terms associated with a node in a certain vocabulary. You would use it like so:
$vid = 1; // Vocabulary ID
$nid = 1; // Node ID

$node = node_load($nid);
$terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);


Why is the Y velocity in rigidbody2D changing with no reason?

Question: I'm making a 2D game where the player is able to jump only when the
Y velocity==0, the player moves only on the X axis so I don't see a reason for the Y velocity to either decrease or increase. The problem is that it's weirdly changing.
Please help me fix that RigidBody2D velocity's problem, it's making me crazy.
Thanks.
I'm showing you how the velocity is changingThe Colliders of the objects that are causing this problem
edit: I restarted unity but it didn't work, even when I'm not moving the Y velocity is increasing.
Comment: Rigidbody velocities are basically never zero unless the rigidbody is sleeping. I would check `if(Mathf.Abs(rigidbody.velocity.y) < Mathf.epsilon)` but even that might be too restrictive. Try `if(Mathf.Abs(rigidbody.velocity.y) < 0.01)` or something.
Answer: You should'nt compare float numbers because they are not fully precise.
Check IEEE 754 and instead of comparise them, check if it's greater than some value. Also look at you're y value in the rigidbody component to be sure.
Comment: That worked! I made the character able to jump if the Y velocity is bigger than 0.
Thanks for your answer!
Answer: There are two solutions:

Check if the speed y is very small, as they suggested.
Use Freeze Position Y. By activating that box and deactivating it
when you have to move vertically, for example to jump, you will be
constrained to the Y axis, and therefore the speed will not change.

Good work!
Comment: Well I tried your 2nd suggestion before and unfortunately... It is somehow complicated to keep changing between freezing and unfreezing the Y position every time and I don't know how would it be after building it.
But the first one worked!
Thank you very much and I wish you a nice day!
Comment: @Tunisia I'm glad you found a solution. If you want, you can also accept the answer to help other users find the solution faster :)


Reading a file with fscanf()

Question: I have used fgets as well as fscanf to read a file line by line but all the time I have got some wrong output.
1st line of the file contain 149 characters and 2nd line contains 122 characters, but in my output file it shows 1st line contain 149 but 2nd line contain 128.
Comment: Show us the code you're using, and the input and output, and why it is not what you expect. Try to reduce it to a smaller program that shows the problem with less input, if you can.
Comment: Please update your post to include the code that reads from file 1 and writes to file 2. Without that, we're just guessing and hinting at common mistakes.
Comment: in `C` that extra 6 chars are normal, it just tells that you did not truncate the data with `\n` and you are getting garbage chars.
Answer: By output file do you mean to say that you are reading from one file and writing it into another? Are you manipulating the string before writing it? If that is the case then maybe your manipulaion is repositioning the newline characther. Just a guess. We will need to see the code.

Reading a file with fscanf()


App is stuck on splash screen after upgrading to Expo SDK 48.0.10

Question: I updated my Expo project to SDK 48.0.10. It works fine on test environments and Expo Go, but when I produce an APK and install it on my device, it gets stuck on the splash screen. I've tried many things but no luck yet.
Things to consider:

App flashes one time and nothing happens
hideasync() runs
When I downgraded to SDK 47, it works fine
Updated all packages and  Node version,
Did everything from the Expo migration guide

Any suggestions would be appreciated.
Answer: Exactly the same is happening to me. The app works perfect on expo go, but once the build is done, testing in the mobile phone is gets stuck in splash screen.
Any ideas?
In case it helps (it didn't help me) a user in Discord mentioned:
Juhis
—
02/05/2023 10:16
I was able to fix it. My issue was that react-native-reanimated was not included in babel.config.js as a plugin, I don't know but maybe this could help. Good luck!
I just don't know how to check which modules should be in babel.config.js
Extra update:
So! here it goes:  E  Invariant Violation: requireNativeComponent: "RNGestureHandlerRootView" was not found in the UIManager. Seems like I was missing react-native-gesture-handler and somehow expo go was ignoring it. Now tried the app in TestFlight and is working!  It is really helpful to have Android Studio with the virtual device to see the log from the APK. Cheers!
Comment: I considered this solution, but it didn't work for me.
Comment: Something did the trick for me. Important! Test the apk using android simulator to be able to see the logs. Not all show up in expo go sdk 48. My problem was here: here it goes:  E  Invariant Violation: requireNativeComponent: "RNGestureHandlerRootView" was not found in the UIManager. Seems like I was missing react-native-gesture-handler and somehow expo go was ignoring it. Now tried the app in TestFlight and is working!  It is really helpfull to have Android Studio with the virtual device to see the log from the APK. Cheers!
Answer: Update: I updated some other dependencies, and now it is working again. I don't exactly know which one, but I updated the dependencies to the latest versions, which are newer than the versions recommended by the Expo migration guide. I also updated the Babel version. I went to npm, searched for all package names, and checked that the versions were the latest.
Here are all of the dependencies that I am using and have updated:
"dependencies": {

    "@react-native-async-storage/async-storage": "^1.18.1",
    "expo": "^48.0.10",
    "expo-dev-client": "^2.1.6",
    "expo-font": "^11.1.1",
    "expo-splash-screen": "^0.18.1",
    "expo-status-bar": "^1.4.4",
    "react": "^18.2.0",
    "react-native": "^0.71.6",
    "react-native-paper": "^5.6.0",
    "react-native-safe-area-context": "^4.5.0",
  },
  "devDependencies": {
    "@babel/core": "^7.21.4"
  },

Answer: if you want, you can downgrade to SDK version 48.0.0. The latest version, SDK 48.0.10, may have some bugs
Comment: did it nothing fixed


Lengths of principal components to determinate SOM grid

Question: "Most applications of the SOM are based on
regular arrays of nodes. Sometimes one uses rectangular arrays of
nodes for simplicity. However, the hexagonal arrays are visually
much more illustrative and accurate, and are recommended.
Whatever regular architectures are used, it is advisable to select
the lengths of the horizontal and vertical dimensions of the array to
correspond to the lengths of the two largest principal components
(i.e., those with the highest eigenvalues of the input correlation
matrix), because then the SOM complies better with the low-order
signal statistics.The oblong regular array shave the advantage over
the square ones of guaranteeing faster and safer convergence in
learning"
This is taken from the article "Essentials of the self-organizing map" written by Teuvo Kohonen itself.
What does he mean by lenghts of the two largest principal components and what is the rationale of choosing the dimensions of the grid in this way?
Answer: It means that the 2D SOM map can be sized using the proportion of the largest principal component to the second largest. The rationale is that the principle components corresponds with the global structure, so provide some information about the global shape of the data to get a map that is the same shape as the data. Linear initialisation using the two largest principal components leads to significantly faster convergence.
Also touched on in Kohonen's recent book:

"Because the SOM is trying to represent the distribution of
  high-dimensional data items by a two-dimensional projection image, it
  may be understandable that the scales of the horizontal and vertical
  directions of the SOM array should approximately comply with the
  extensions of the input-data distribution in the two principal
  dimensions, namely, those two orthogonal directions in which the
  variances of the data are largest." Kohonen, T. K. (2014). MATLAB
  Implementations and Applications of the Self-Organizing Map.

Kohonen wrote this in a different way in his earlier book.

"If one wants to obtain an approximately uniform lattice spacing in
  the SOM, the relative numbers of cells in the horizontal and
  vertical directions of the lattice, respectively, should be
  proportional to the two largest eigenvalues considered above." Kohonen, T. K. (2001). Self-Organizing Maps. Springer Series in Information Sciences (Vol. 30). Springer-Verlag Berlin. Page 142. http://doi.org/10.1007/978-3-642-56927-2

Thus, the PCA is an approximation to the final solution by SOM. If your data is well suited to this variance analysis, then it will significantly speed up the algorithm without affecting the results.
Comment: Yes, that's what Kohonen suggested, to set the height and width to the ratio of the first two eigenvectors.
Comment: Applying SVD to centred data matrix $X=UDV^{T}$, principal component are defined as column of $DV$? For example, if the ratio of the first two eigenvalues is $4/1$ I should use the same proportion for the size of the map?


Solve $2\sin(x)^2 -\sin(x) = 1$ by hand

Question: I'm am trying to solve
$ 2\sin^2(x)-\sin(x)=1 $
and I know that the solutions are:
$ x=\frac{1}{4}(4\pi~ n+\pi)$,
$x=\pi(2n-\frac{1}{6})$, and $ x=\pi(2n+\frac{7}{6})$, (for any integer $n$).
But I have no idea where to start, any thoughts?
Thank's in advance
Comment: A start: $2\sin^2 x-\sin x-1=(2\sin x+1)(\sin x-1)$. The solutions given don't seem quite right.
Answer: I'll be happy to give you a starting point.
Let $u = \sin{x}$.  Then our equation $2 \sin^{2}(x) - \sin{x} = 1$ becomes $2 u^{2} - u = 1$.  Then $2u^{2} - u - 1 = 0$, and factoring gives: $(2u + 1)(u - 1) = 0$.
The price for this starting point is now you must attempt the rest of the problem on your own and post your attempts before receiving any further help (at least from me).
Answer: $$2\sin(x)^2 -\sin(x) = 1 \implies 2\sin(x)^2 -\sin(x) - 1=0 \implies \sin(x)=\frac{1\pm3}{4}$$
Answer: Let $y=\sin(x)$. Then, the equation $2y^2-y=1$, this is
$$2y^2-y-1=0,$$
has solutions $y_1=1$ and $y_2=-\frac{1}{2}$ (ok so far?). So you have:
$$\sin(x)=1\quad\Rightarrow\quad x=\frac{\pi}{2}+2k\pi,\ k\in\Bbb Z$$
and
$$\sin(x)=-\frac{1}{2}\quad\Rightarrow\quad x=\frac{7}{6}\pi+2k\pi,\ k\in\Bbb Z\ \vee\ x=\frac{11}{6}\pi+2k\pi,\ k\in\Bbb Z.$$
If you like, for all $k\in\Bbb Z$, it is $\frac{11}{6}\pi+2k\pi=-\frac{\pi}{6}+2k\pi$.

Solve $2\sin(x)^2 -\sin(x) = 1$ by hand


A question about $\pi$-system.

Question: If $\mathcal{P}$ is a $\pi$-system and use $\mathcal{S}$ to denote the intersection of all $\lambda$-systems containing $\mathcal{P}$. I want to show $\mathcal{S}$ is also a $\pi$-system. By definition, take $A,B\in \mathcal{S}$ and show $A\cap B\in \mathcal{S}$.
Let $\mathcal{A}:=\{C\subseteq X\mid A\cap C\in S\}$, it suffices to show $B\in\mathcal{A}$. If I can show $\mathcal{A}$ is a $\lambda$-system containing $\mathcal{P}$, this completes the proof. I can already show $\mathcal{A}$ is a $\lambda$-system, but I can't show $\mathcal{P}\subseteq\mathcal{A}$.
Could anyone give me some help? Thanks in advance!
Comment: This is just for clarification, but has this doubt come from analysing the proof of a larger theorem? (I think the $\pi-\lambda$ theorem, if I were pushed to state which one)
Comment: Why make it so difficult? If $\mathcal P'$ is a $\pi$-system containing $\mathcal P$, then $A,B \in \mathcal P'$, and this implies that $A \cap B \in \mathcal P'$. Hence, $A \cap B \in \mathcal S$. Isn't?
Comment: @SarveshRavichandranIyer yeah, I met this question when I read pi-lambda theorem
Comment: Thanks @BowenL, that will be helpful to others reading up about the $\pi-\lambda$ theorem. For convenience, I will edit the tags in your question to make it more accessible. Having said that, I get the feeling your question has been answered before, but will leave the task of finding a duplicate to someone currently having more time than me. I don't really think this is a question in real analysis, more measure theory and probability (where sigma-algebras are likely to be introduced)
Comment: @azif00, no since we don't know that $P'$ is a $\pi$ system.

This question is asking the hard part of the $\pi \lambda$ Theorem since a $\lambda$ system is $\pi$ if and only if it's $\sigma$. You can find a proof of that anywhere - here's one: https://www.math.lsu.edu/~sengupta/7360f09/DynkinPiLambda.pdf
Comment: @Eric You're right. I didn't read carefully the question.
Answer: You have to do this in just two simple steps. First fix $D \in \mathcal P$ and consider $\{A\subseteq X: A \cap D \in \mathcal S\}$. This is a  $\lambda$ system containimng $\mathcal P$ and hence it contains $\mathcal S$. Thus, $A \in \mathcal S, D \in \mathcal P$ imlies $ A\cap D \in \mathcal S$. Now Fix $A \in \mathcal S$ and consider $\{D\subseteq X: A \cap D \in \mathcal S\}$. This is a $\lambda$ system containing $\mathcal P$ and so it contains $\mathcal S$. Thus, $A\cap D \in \mathcal S$ whenever $A$ and $D$ in $\mathcal S$.
[As mentioned by OP, it was enough to say $A \in \mathcal S, D \in \mathcal P$ imlies $ A\cap D \in \mathcal S$].
Comment: Thanks for your answering, but why we need the second step, I think your first step may already answer my question: I need to show for any $A\in\mathcal{S},D\in\mathcal{P}$, we have $A\cap D\in\mathcal{S}$. Is there anything wrong with my understanding?
Comment: You are right. I just completed the proof of the fact that $\mathcal S$ is a $\pi$ system. @BowenL
Comment: So sorry, I may click the wrong vote, could you edit anywhere so I can change my vote, sorry to bother u.
Comment: @BowenL I have edited.

A question about $\pi$-system.


Como adiciono atributos na img com a função the_post_thumbnail do WordPress?

Question: Preciso adicionar um width="100%" e o class="img-responsive".
Como faço para adicionar na img se eu chamo ela na index desta maneira?
<?php the_post_thumbnail(); ?>

Comment: Tente desta forma  'alignleft' ) ); ?>
Answer: Faz assim:
<?php
  $thumb_id = get_post_thumbnail_id();
  $thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
  echo "";
?>

get_post_thumbnail_id pega o id da thumb.
wp_get_attachment_image_src pega a url da imagem, passando o id da thumb como parâmetro.
Comment: Muito bom, me ajudou também!
Comment: Opa deu certo, valeu cara! e vai ajudar em projetos futuros!


Preencher campos com dados da base de dados após selecionar uma opção no

Question: Estou tentando desenvolver uma funcionalidade em que, ao escolher um operador em um formulário, as horas associadas a esse operador (hora de início e hora de fim) sejam automaticamente preenchidas nos campos correspondentes do formulário. O objetivo é garantir que, ao selecionar um operador, as informações de hora associadas a esse operador sejam exibidas instantaneamente nos campos apropriados do formulário.
Ao selecionar um operador, o JavaScript deveria capturar as horas associadas a esse operador e preencher automaticamente os campos de hora. No entanto, mesmo após várias tentativas e verificações, essa funcionalidade não está ocorrendo conforme o esperado.

<?php   $query_operadores = "SELECT nome_operador,id_matricula_operador,hora_inicio_turno, hora_fim_turno FROM tb_operadores, tb_turnos where tb_turnos.id_turno=tb_operadores.id_turno_operador_fk ORDER BY id_matricula_operador ASC";
        $resultado_operadores = $conn->query($query_operadores);
?>

<!DOCTYPE html>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Cadastro de Produção</title>

Cadastro de Produção

        <form>

                Data:
                <input type="date" id="data_producao" name="data_producao" value="today()">

                Operador:
                <select id="operador_producao" name="operador_producao">
                <?php
                    while ($row_operador = $resultado_operadores->fetch_assoc()) {
                        $nome_operador = $row_operador['nome_operador'];
                        $id_operador = $row_operador['id_matricula_operador'];
                        $hora_inicio = $row_operador['hora_inicio_turno'];
                        $hora_fim = $row_operador['hora_fim_turno'];

                        echo "<option value=\"$id_operador\" data-hora-inicio=\"$hora_inicio\" data-hora-fim=\"$hora_fim\">$nome_operador</option>";
                    }
                    ?>
                </select>

                Hora Inicio:
                <input type="time" id="hora_inicio_producao" name="hora_inicio_producao" min="1">

                Hora Fim:
                <input type="time" id="hora_fim_producao" name="hora_fim_producao" min="1">

                Produto:
                <select id="produto_producao" name="produto_producao">
                    <option value="un">Unidade</option>
                </select>

                Quantidade Produzida:
                <input type="text" id="quantidade_producao" name="quantidade_producao" min="1">

            <button type="submit">Cadastrar Produção</button>
        </form>

```

Answer: Qual erro é exibido?
O que você quer é possível com ajax e PHP(veja abaixo um pseudo-código, não está completo mas é uma ótima base de por onde começar! Ressalto que também utilizei jQuery.)
Inclua o jQuery para que funcione corretamente:

$('#SeuSelect').click(function () {
const data = this.value;
$.ajax({
                 url: 'pagina-handle-dados.php?data=' + data,
                    type: 'get',
                    dataType: "JSON",
                    success: function (result) {
                        $.each(result, function (i, obj) {
                            //id do campo que você quer popular, neste caso é uma div(por isso usei .innerHTML)
                            txt = document.getElementById("myspan2").innerHTML = "SuaFrase: " + obj.definido_no_retorno;
                        });
                    }
                });
pagina-handle-dados.php:
~~faça sua conexão com o banco de dados~~

$data = $_GET['data'];

$stmt = $conn->prepare("SELECT *, COUNT(id) AS definido_no_retorno FROM tabelaQualquer WHERE dados=$data");
        $stmt->execute();
        $results = $stmt->fetchAll(PDO::FETCH_OBJ);
        echo json_encode($results);
Comment: Esta resposta não é útil? É EXATAMENTE o código que uso em uma das minhas páginas que precisei popular campo X baseado em um select... Algumas coisas por aqui simplesmente não fazem sentido às vezes.


Assessing the validity of a PMF?

Question: How would one go about solving the following given that the function h(x) isn't provided in the question? I'm at a loss on where to begin.
Suppose h(x) is such that h(x) > 0 for x = 1,2,3,...,I. Argue that $p(x) = h(x)/ \sum_{i=1}^I h(i)$ is a valid pmf
Answer: The fact that $h(x)$ isn't provided is a strong hint: it doesn't matter what $h(x)$ is except that it's always positive ($\geq 0$ would also be ok).
First, why is $p(x)>0$ always true? Second, what's the other property that a pmf has to have?
Comment: Thank you! However I'm still stuck on the second portion. The second property is that the sum of all of the probabilities where the function is defined is 1 but I'm unsure how to show this without knowing the function.
Comment: Ok. The sum of  $h(x)$ is something, call it $H$.  $p(x)=h(x)/H$, so what's the sum of $p(x)$.

Assessing the validity of a PMF?


How to display a field before the title when the title was printed before the node template?

Question: This answer works when the title is printed in the node template.
However, the base node template contains this code:
<?php if (!$page): ?>
    <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?>

<?php endif; ?>

So how do I print a field before the title when the title was already printed in the page template?
Answer: page.tpl.php has a $node variable on all node/%nid pages. So you have two options:

You can use it directly in page.tpl.php (with the help of the field_get_items() and field_view_field() functions).
You can do your messing around with $variables['node'] in a THEME_preprocess_page() function in your theme's template.php, then add your complete data to $variables[] to print the final value in page.tpl.php.

This may also help: Setting up variables in preprocess functions


OLS variance estimator in linear regression without strict exogeneity

Question: (I don't remember seeing this result stressed enough.)
Consider the "benchmark" linear regression model
$$\mathbf{Y} = \mathbf{X} \beta + \varepsilon.$$
$$E(\varepsilon) = 0,\, E(\varepsilon \varepsilon' \mid \mathbf X) = \sigma^2I.$$
The initial presentation of this model in econometrics, is with the additional assumption of "strict exogeneity", $E(\varepsilon \mid \mathbf X) =0$. But usually, we move on to say that this assumption is too strong and not expected to hold, and we settle for the weaker assumption $E(\mathbf X' \varepsilon) = 0$.  With this assumption, we lose finite-sample unbiasedness of the OLS estimator, but we retain consistency and asymptotic normality.
Now, in order for the weaker model to be usefully discriminated from the model with strict exogeneity, it must be the case that we have (alongside $E(\mathbf X' \varepsilon) = 0$), $E(\varepsilon \mid \mathbf X) =h(\mathbf X)$ also.
Question: in such a setting, what does the variance estimator of $\hat \beta_{OLS}$ estimate?
Answer: By definition, under any case the finite-sample variance of $\hat \beta$
is
$${\rm V}(\hat \beta \mid \mathbf X) = (\mathbf X'\mathbf X)^{-1}\mathbf X'E\left[\varepsilon \varepsilon' \mid \mathbf X\right]\mathbf X(\mathbf X'\mathbf X)^{-1} $$
$$-  (\mathbf X'\mathbf X)^{-1}\mathbf X'E\left[\varepsilon \mid \mathbf X\right]E\left[\varepsilon' \mid \mathbf X\right]\mathbf X(\mathbf X'\mathbf X)^{-1}.$$
Under the assumptions without strict exogeneity but with orthogonality,
$$E(\varepsilon \mid \mathbf X) = h(\mathbf X),\quad E(\mathbf X' \varepsilon) = 0,\quad E(\varepsilon \varepsilon' \mid \mathbf X) =\sigma^2I, $$
the finite sample variance becomes
$${\rm V}(\hat \beta \mid \mathbf X) = \sigma^2(\mathbf X'\mathbf X)^{-1} -  (\mathbf X'\mathbf X)^{-1}\mathbf X'h\left(\mathbf X\right)h'\left(\mathbf X\right)\mathbf X(\mathbf X'\mathbf X)^{-1},$$
while the (conditional) bias of the estimator is
$${\rm B}(\hat \beta \mid \mathbf X) = E(\hat \beta \mid X) - \beta = (\mathbf X'\mathbf X)^{-1}\mathbf X'h\left(\mathbf X\right).$$
It follows that the Mean Squared Error of $\hat \beta$ is
$${\rm MSE}(\hat \beta \mid \mathbf X) = {\rm V}(\hat \beta \mid \mathbf X) + {\rm B}(\hat \beta \mid \mathbf X){\rm B}'(\hat \beta \mid \mathbf X) = \sigma^2\left(\mathbf X' \mathbf X\right)^{-1}.$$
We see that , when we do not assume strict exogeneity but only orthogonality, the finite sample "variance" estimator (that is automatically computed by software) in reality computes the finite-sample Mean Squared Error (this continues to hold if we assume conditional heteroskedasticity and want to compute "robust" standard errors).
In general when we expect the estimator to be biased, we tend to prefer using MSE as a more appropriate "quality" measure than the Variance alone. But this does not mean that we can use MSE in all cases instead of the Variance without consequences. For example, in significance testing, the value of the $t$-statistic will be deflated (in absolute terms) due to the use of the estimated MSE in its denominator.
Comment: Hi Alecos: Not only is it not stressed but I never even seen it or known that it was true !!!! One question, though. If one knows that $E(\epsilon | X) = h(X)$, then can't one just "transform all the predictor variables by subtracting off $h(X)$ and then be  back to the exogenous case ?
Comment: @mlofton We usually do not know $h(\mathbf X)$, we just argue structurally that there exists mean-dependence of unknown  functional form.
Comment: Thanks. Do you know of any texts, stats or econometrics, that talk about the difference between the exogeneity assumption and the orthogonality assumption. I have many and I've never seen such a discussion but maybe I missed it ?
Comment: @mlofton Well, it is standard practice in econometrics textbooks (eg. Greene, Hayashi) to initially present linear regression with strict exogeneity and talk about finite sample properties, and then discuss asymptotic properties, where they assume only orthogonality. But they don't contrast the two and they don't discuss what happens to finite-sample inference under orthogonality only. That was the reason for this post.
Comment: Thanks. I have hayashi so I'll check it out. That description seems better than what they do in statistics textbooks where they generally talk about orthogonality and that's that. Exogeneity is not discussed AFAIK.


Display html in a flutter widget on macOS app

Question: I am new to Flutter and I think that I need help.
I am writing a native macOS app with Flutter, and I need to display HTML contained in a String variable. I need to display it in a scrollable widget, such as SingleChildScrollView.
The HTML I need to print is collected via the Gmail API, so it is supposed to display emails from the API, written in HTML.
First I tried the libraries flutter_html and flutter_widget_from_html but they only work with basic HTML, when I am trying to display more heavy html, it crashes.
So I am now trying to display HTML via a web view, but I can't make them work with a native macOS app.
I tried with webview_flutter, which doesn't support macOS currently, so I moved to flutter_macos_webview, but it crashes when I try to open the web view. Here is the code.
The only thing that seems to work is the library desktop_webview_window, but it opens another window when I want an embedded widget, and I don't know how to execute local HTML contained in a string instead of launching a website
I hope it's clear, thanks for your help!
Here is the code of flutter_macos_webview that crashed when I launch the review.
import 'package:flutter/cupertino.dart';
import 'package:flutter_macos_webview/flutter_macos_webview.dart';

void main() => runApp(App());

class App extends StatelessWidget {
  Future<void> _onOpenPressed(PresentationStyle presentationStyle) async {
    final webview = FlutterMacOSWebView(
      onOpen: () => print('Opened'),
      onClose: () => print('Closed'),
      onPageStarted: (url) => print('Page started: $url'),
      onPageFinished: (url) => print('Page finished: $url'),
      onWebResourceError: (err) {
        print(
          'Error: ${err.errorCode}, ${err.errorType}, ${err.domain}, ${err.description}',
        );
      },
    );

    await webview.open(
      url: 'https://google.com',
      presentationStyle: presentationStyle,
      size: Size(400.0, 400.0),
      userAgent:
          'Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1',
    );

    // await Future.delayed(Duration(seconds: 5));
    // await webview.close();
  }

  @override
  Widget build(BuildContext context) {
    return CupertinoApp(
      debugShowCheckedModeBanner: false,
      home: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          CupertinoButton(
            child: Text('Open as modal'),
            onPressed: () => _onOpenPressed(PresentationStyle.modal),
          ),
          SizedBox(height: 16.0),
          CupertinoButton(
            child: Text('Open as sheet'),
            onPressed: () => _onOpenPressed(PresentationStyle.sheet),
          ),
        ],
      ),
    );
  }
}

Answer: You can use flutter_widget_from_html_core: ^0.10.3 package to display Html in your app.
Or you can use webview_flutter_plus 0.3.0+2 to create a webview to display the html
Comment: Not working too :(
It shows a blank page
Idk how to show you my html code because it is a very long String, but when I put it in an html viewer online it works, so I don't think that it is my html code that is broken, but instead that the plugins doesn't support heavy html
Comment: what html you want to show
Comment: then try using webview instead
Comment: that's why I am trying to do, but I can't achieve to make a webview embedded in a widget on a macOS native app
Comment: here is my html [link](https://codebeautify.org/htmlviewer/y2324234c)
Comment: this is a very heavy html
Comment: Use webview_flutter_plus 0.3.0+2 for this type of html
Comment: I have this error using webview_flutter_plus ; UnsupportedError (Unsupported operation: Trying to use the default webview implementation for TargetPlatform.macOS but there isn't a default one). I think Macs apps are not supported...
Answer: here is an idea , why not create a temporarily html file then open it in browser like
import 'dart:html' as html;
html.window.open(url, name);

Comment: thank for your idea, but I need it to be in an embedded widget, not in another window or in the browser


Rmarkdown fails at using xelatex engine

Question: I am trying to specify a font style in my document and I found out I should use a specific latex engine: xelatex. However when I specify the following instruction inside the YAML header:
---
title: BLABLA - me
output:
  pdf_document: default
  engine: xelatex
header-includes:
  - \usepackage{fontspec}
  - \setmainfont{Times New Roman}
fontsize: 12pt
---

I could not get my document compiled because of the error:
    ! Fatal Package fontspec Error: The fontspec package requires either XeTeX or
(fontspec)                      LuaTeX.
(fontspec)
(fontspec)                      You must change your typesetting engine to,
(fontspec)                      e.g., "xelatex" or "lualatex"instead of
(fontspec)                      "latex" or "pdflatex".

I have installed the package tinytex and I do not know much about latex
Answer: Check your header. Some posts (i.e. here) report that the correct way to specify engine is
output:
  pdf_document:
    latex_engine: xelatex

Comment: That sounds like another question.
Comment: Yes I am sorry. Do you know any way to change the title font to another one? such as Helvetica

Rmarkdown fails at using xelatex engine


$e^{(A+B)} = e^Ae^Be^{[A,B]}$ for non commuting A and B?

Question: For non commuting A and B, and the derivative of $[A,B] = 0$. Is it true that/how to prove that
$e^{(A+B)} = e^Ae^Be^{[A,B]}$
If not, what is the expression according to Wikipedia's article on the Baker–Campbell–Hausdorff formula
Comment: Presumably you prove / disprove it by expanding the exponential function into its power series representation, and then comparing terms of equal degrees.
Comment: Surely $[A,B] = 0$ means that $A,B$ commute?
Comment: Derivative with respect to what?
Comment: Please edit the question to fix it: as it stands, it makes no sense.
Comment: @copper.hat Didn't he say "the derivative of $[A, B]$"?
Comment: @Arthur: Yes, I assumed it just meant the commutator was zero, otherwise I am not sure what the derivative of $[A, B]$ means.
Comment: @copper.hat I agree that that seems strange. Are the operators $A$ and $B$ time-dependant or something? I dunno.
Comment: Well, if the derivative of $(A,B) \mapsto [A,B]$ is zero, then $A,B$ commute with every matrix and hence are multiplies of the identity (and hence commute).
Comment: Yes it is derivative.
Comment: One might speculate that the right-hand side is a miscopy of $e^A e^B e^{[A,B]}$ or something similar. At least the "type checking" would be ok then.
Answer: I don't know what the OP means by "the derivative of $[A,B] = 0$", but the equation
$$e^{A+B} = e^A e^B [A,B]$$
is certainly not on.  This would imply in particular that $[A,B]$ has determinant $1$, which is destroyed by scaling of $A$ or $B$.  It's also false in a limit as, say, $B$ approaches something that commutes with $A$.


Mensagem Java Perspective

Question:
A mensagem esta sendo apresentada toda vez que eu executo o Eclipse e crio um novo Projeto, alguém sabe me explicar o motivo da mensagem?
Comment: Que tipo de projeto vc criou um java? jee?
Comment: Por exemplo estou trabalhando num projeto jee (com a mesma perspectiva) se eu criar um projeto novo do tipo java ele vai perguntar se desejo mudar a perspectiva. Outra sitauação onde isso ocorre é ao debugar algum código ele vai perguntar se quer mudar de perspectiva.
Comment: Eu criei o meu projeto executando conforme segue: File -> New -> Java Project
Answer: Cada tipo de projeto mostra determinada caracteristicas, sempre que criar ou mudar de projeto o eclipse perguntará se deseja mudar para perspectiva adequada ao projeto. Outra situação onde isso ocorre é ao debugar o projeto.
Para desativar essa pergunta faça o seguinte procedimento. Acesse o menu:
window>preference>general>perspectives

Na caixa que abrir marque a opção never open

Mensagem Java Perspective


DNS Prefetch inside AWS Node.js Lambda

Question: I'm trying to prefetch DNS records inside a node.js Lambda function. I have instrumented my http requests (using Sentry) to show how long it takes for the socket to complete the dns lookup, and how long to establish the TCP connection.
When I run the function locally on my machine, it works - the http request takes almost no time at all to perform the lookup
But when I run the function on AWS Lambda, the DNS lookup still takes some time, as if the prefetch did not populate the lookup table. Here is the implementation:
import dns from 'dns'

export const dnsPrefetch = url => {
  const address = new URL(url).hostname
  dns.lookup(address, { hints: dns.ADDRCONFIG }, () => {})
}

And then in a module, I might use it like so: dnsPrefetch('https://url.to/graphql')
Any ideas why the DNS prefetch is not working on Lambda?
Answer: Try to wrap it inside a Promise:
async function lookupPromise(url){
    return new Promise((resolve, reject) => {
        dns.lookup(url, (err, address, family) => {
            if(err) reject(err);
            resolve(address);
        });
   });
}

Or use dns promises:
const dnsPromise = dns.promises;

dnsPromise.lookup(url)

DNS Prefetch inside AWS Node.js Lambda


getType method in contentProvider subclass

Question: i searched a lot about this topic
but i still can't wrap my brain around it
can someone "deeply explains to me " how getType() works ? and few examples that also explains the mime and how it is used when it is returned by getType() ?
Answer: Content URIs can be used to reference content from a wide variety of contexts. The getType method allows a content consumer - which might be a component in your app, but can also be component outside your app and which doesn't know anything specifically about your app except for the content URI - to find out what type of data a content URI refers to. The content consumer needs this information to know how what to do with the content - for example, how to display it - when it resolves the content URI. So in the simplest case, if the URI content://my.app/record/1 refers to a HTML file, then the type is text/html, and if the URI content://my.app/record/2 refers to a JPEG file then the type is image/jpeg. There is no other way to infer the content type from the URI (because e.g. there's no file extensions).
Android also provides some special MIME types for indicating table data, android.cursor.item/* and android.cursor.dir/*.
This approach is designed to fit in with Android's Activity based architecture, allowing the system to open content URIs by examining the content MIME type and then choosing an Intent to open an Activity which displays the content.
Comment: thanks for the clarification !! how does it choose the right activity to open ?
Comment: is MIME type defined in it so it tells the intent that it is the right activity that can act upon the data or what ?
Comment: That is down to intents and intent filters, see https://developer.android.com/guide/components/intents-filters.html Basically, an app can declare an implicit intent that can handle a specified MIME type. When the Android system has to open content with a particular MIME type, it looks at the list of apps with implicit intents for that type, and chooses one. This may mean that the user is presented with a dialog to select the app to use to show content, if more than one intent can handle the content type.


Generated signed X.509 client certificate is invalid (no certificate chain to its CA)

Question: I use Bouncy Castle for generation of X.509 client certificates and sing them using a known CA.
First I read the CA certificate from the certificate store, generate the client certificate, sign it using the CA. Validation of the certificate is failed doe to the following issue

A certificate chain could not be built to a trusted root authority.

As I understand this is due to the certificate not being related to the CA.
Here is a code sample:
<code>public static X509Certificate2 GenerateCertificate(X509Certificate2 caCert, string certSubjectName)
{
    // Generate Certificate

    var cerKp = kpgen.GenerateKeyPair();

    var certName = new X509Name(true,certSubjectName); // subjectName = user
    var serialNo = BigInteger.ProbablePrime(120, new Random());

    X509V3CertificateGenerator gen2 = new X509V3CertificateGenerator();
    gen2.SetSerialNumber(serialNo);
    gen2.SetSubjectDN(certName);
    gen2.SetIssuerDN(new X509Name(true,caCert.Subject));
    gen2.SetNotAfter(DateTime.Now.AddDays(100));
    gen2.SetNotBefore(DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0)));
    gen2.SetSignatureAlgorithm("SHA1WithRSA");
    gen2.SetPublicKey(cerKp.Public);

    AsymmetricCipherKeyPair akp = DotNetUtilities.GetKeyPair(caCert.PrivateKey);
    Org.BouncyCastle.X509.X509Certificate newCert = gen2.Generate(caKp.Private);

    // used for getting a private key
    X509Certificate2 userCert = ConvertToWindows(newCert,cerKp);

    if (caCert22.Verify()) // works well for CA
    {
        if (userCert.Verify()) // fails for client certificate
        {
            return userCert;
        }
    }
    return null;

}

private static X509Certificate2 ConvertToWindows(Org.BouncyCastle.X509.X509Certificate newCert, AsymmetricCipherKeyPair kp)
{
    string tempStorePwd = "abcd1234";
    var tempStoreFile = new FileInfo(Path.GetTempFileName());

    try
    {
        // store key
        {
            var newStore = new Pkcs12Store();

            var certEntry = new X509CertificateEntry(newCert);

            newStore.SetCertificateEntry(
                newCert.SubjectDN.ToString(),
                certEntry
                );

            newStore.SetKeyEntry(
                newCert.SubjectDN.ToString(),
                new AsymmetricKeyEntry(kp.Private),
                new[] { certEntry }
                );
            using (var s = tempStoreFile.Create())
            {
                newStore.Save(
                    s,
                    tempStorePwd.ToCharArray(),
                    new SecureRandom(new CryptoApiRandomGenerator())
                    );
            }
        }

        // reload key
        return new X509Certificate2(tempStoreFile.FullName, tempStorePwd);
    }
    finally
    {
        tempStoreFile.Delete();
    }
}
</code>
Answer: I figured this out. If you call X509Certificate.Verify(publicKey) you have to pass the CA's public key, not the client's public key from the Pkcs10CertificationRequest.


Can the closure of a null set have positive measure?

Question: Let $X=\mathbb{R}^n$ ($n\ge 1$) be equipped with the natural topology (the one coming from the norms) and let $\lambda$ denote the Lebesgue-measure on $X$.
Let $M\subset X$ be a null set: $\lambda(M)=0$. Is it possible that the closure of $M$ has positive measure, i.e. $\lambda(\overline{M}) > 0$?
Thank you!
Answer: Actually, more is true: the closure of a null can have the measure you want. We just deal with the case $n=1$. For example, taking the rational numbers, the measure of the closure is infinite as this set is dense. Now let $a>0$. Then $\Bbb Q\cap (0,a)$ has measure $0$ but it's closure is $[0,a]$ and has measure $a$.
Answer: Yep. The points with rational coordinates are countable and so have zero measure, and their closure is all of $\mathbb{R}^n$!
Comment: $\mathbb{Q}$ is not closed in $\mathbb{R}$... For instance, choose rational points converging to $\sqrt{2}$, which is not rational...
Comment: Damn, you are right. What was I thinking...
Comment: $\mathbb{Q}^n\subset \mathbb{R}^n$ is a closed set (a countable union of points, which are closed sets), so its closure is $\mathbb{Q}^n$ itself, which is a zero set.
Comment: @Sh4pe Closed sets are not closed under infinite union, just intersection.


Linux, adding sub-interfaces

Question: I'll start out by saying networking isn't my strong suit, I'm trying to configure a few sub-interfaces so that some code I am working will have more sockets to locally bind to. So far i've done the following, I can locally bind to my sub interface 192.168.2.210, but I can not make a remote connection with it.
Here is my ifconfig:
eth0      Link encap:Ethernet  HWaddr 00:50:56:BB:00:0B
          inet addr:10.6.19.18  Bcast:10.255.255.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:febb:b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1056026 errors:0 dropped:0 overruns:0 frame:0
          TX packets:638290 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:237037186 (226.0 MiB)  TX bytes:126161362 (120.3 MiB)

eth0:1    Link encap:Ethernet  HWaddr 00:50:56:BB:00:0B
          inet addr:192.168.2.210  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

Here is what i've tried to do to configure eth0:1
ifconfig eth0:1 192.168.2.210/32 up
ip route add 192.168.2.210/32 via 10.6.19.18

Here is my netstat -r output:
192.168.2.210   devserv.        255.255.255.255 UGH       0 0          0 eth0
192.168.2.0     *               255.255.255.0   U         0 0          0 eth0
10.6.19.0       *               255.255.255.0   U         0 0          0 eth0
link-local      *               255.255.0.0     U         0 0          0 eth0
default         10.6.19.1       0.0.0.0         UG        0 0          0 eth0

Any thoughts? Thanks for looking
Comment: Please clarify what youre trying to do a bit more. Youre adding `192.168.2.210/32` which means that IP address has no network. The `/32` netmask says that its the only IP address in the subnet. Also youre adding a route to say that traffic to that IP should go out your `10.6.19.18` address. This doesnt make any sense. Why would you add a route to an IP that is on the server itself? If you can provide more info about what youre trying to accomplish, we can probably help more.
Comment: "some code I am working will have more sockets to locally bind to" - note that there is an OS-imposed limit of sockets per process, which you may be able to increase, but adding more interfaces won't help unless you really need more than 60,000 sockets...
Comment: I need to be able to bind to 600,000 unique local socket pairs and establish a connection on each to a remote system. A previous system I was working on already had this networking setup using 12 sub interfaces (binding on ports 10,000-60,000 for each interface), I no longer have access to this particular server and I just need to recreate the networking configuration.
Comment: You need more ip numbers from your real net, that is eth0:0 => 10.6.19.19, eth0:1 => 10.6.19.20 and so on. I wonder if they are available for you tho. You don't need to set routes then.
Answer: Ditch ifconfig as this is being phased out for the iproute2 package;
root@bensley-n2:~# ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
    link/ether 00:e0:4c:6d:0a:49 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 74:ea:3a:ad:2e:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.5/24 brd 192.168.0.255 scope global wlan0
    inet6 fe80::76ea:3aff:fead:2e00/64 scope link
       valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
    link/ether ce:70:78:f8:10:75 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
root@bensley-n2:~# ip address add 126.96.36.199/24 dev wlan0
root@bensley-n2:~# ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
    link/ether 00:e0:4c:6d:0a:49 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 74:ea:3a:ad:2e:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.5/24 brd 192.168.0.255 scope global wlan0
    inet 188.8.131.52/24 scope global wlan0
    inet6 fe80::76ea:3aff:fead:2e00/64 scope link
       valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
    link/ether ce:70:78:f8:10:75 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
root@bensley-n2:~# ip route show
default via 192.168.0.1 dev wlan0
22.214.171.124/24 dev wlan0  proto kernel  scope link  src 22.214.171.124
192.168.0.0/24 dev wlan0  proto kernel  scope link  src 192.168.0.5
192.168.122.0/24 dev virbr0  proto kernel  scope link  src 192.168.122.1

(You can abbreviate the ip commands: ip address add can be shortened all the way down to ip a a, and ip address show can be shortened to ip a s. show is the default action if you don't specify the second argument, so you can just type ip a if you want to be really terse.)
You don't need to add a route either for a local subnet.
Answer: Firstly, sockets aren't actually bound to an interface -- they're bound to an IP address. Virtual/alias interfaces are deprecated and should be avoided -- you should rather add multiple IP addresses directly to eth0. Secondly, if you want these addresses to be routable on the local network you need to use addresses on that network (i.e. 10.6.19.0/24) and not a machine-local subnet like 192.168.2.0/24 (unless you can get the router or the remote machines reconfigured with this other subnet). To add additional address, use the following command:
ip addr add 10.6.19.19/24 dev bond0

You shouldn't require any additional routing configuration since the addresses are on an existing subnet.
Answer: Rather than adding more addresses, which is going to get a little complicated, why dont your sockets use different ports?
Comment: I need to bind a total of 600,000 sockets, I bind on port 10,000 - 60,000 for each interface, I need 12 of these sub interfaces so I can reach my total.
Comment: Then you need to add a gateway on the same subnet, ie in the 192.168.2.0/24. What route does the 'remote' machine take to get to this network? If it is via the 10.6.19.0/24 youll have to enable ip forwarding on this server too. But 600,000 open sockets and routing... ouch.

Linux, adding sub-interfaces


Single codebase for applications that target AWS as well as Azure for pass services such as service bus, blob, SQS/SNS etc

Question: I am having multiple applications which are deployed in Microsoft Azure. These applications are using various libraries from Microsoft for interacting with services such as Azure Servicebus (Topic & Queue), Blob, etc. There is a new requirement that these applications should run on AWS as well on Azure. Since service bus, blob are very specific to Azure. They are not available in AWS. AWS has equivalent services such as SNS/SQS, S3 bucket etc. AWS has different SDK's/libraries for interacting with there services.
This is a problem since I will have to maintain two different versions of the applications one for Azure and another for AWS. This is difficult to maintain and I want to avoid.
Is there any framework/pattern/approach which abstracts vendor-specific details to service bus or blob and work both with AWS & Azure using a single code base
Answer: Dockerize as much as posible and create a core project where all your Azure and AWS nuget packages are installed then create an abstract layer to use methods within your core project that connects to Azure or AWS services.
You can create this Core layer with both packages for Azure and AWS and depending on current configuration (or cloud being deployed) use methods in azure package or AWS package.
Answer: There are 2-3 ways if you want to target Azure, Aws or any other cloud using a single code base

Libraries such as Simple.Bus targets Azure Service bus and RabbitMQ. But they are limited to message brokers. For storage, you may need to find another library that targets both environments.
More appropriate solution is Dapr (Distributed application portable runtime) which not only facilitates microservice service-based development but also helpful in developing cloud-agnostic code. It has various building blocks such as State management and Pubish and Subscribe which can target Azure, AWS using a single code base. By replacing an appropriate component, You can switch from one cloud to another cloud without code change.
If none of the above solution is not working for you for some reason, you may need to implement your own facade layer to target multiple clouds.


Statistics on tastings

Question: Some people at my workplace have had some fun lunch discussion as of late, concerning some people's alleged ability to taste the difference between things one thought one shouldn't be able to taste a difference between. We have hence decided to do a small "competition" (or however you want to call it), where said abilities are to be tested and quantified. Being the one of us who took a course in statistics, I'm trying to find out the best experimental design and statistics to use. Not really being a statistician, I went here to get some help, for which I'd be very appreciative!
One of the tests we will do is the ability to taste the difference between the bottom and top half of an apple (i.e. flower vs. stem parts). My initial thinking was a simply blind-folding the taster and giving them parts of an apple one at a time, recording if they were RIGHT or WRONG (categorical values). I'd also have pieces coming from different apples, both of the same and of difference kinds of apples. A null hypothesis here would be 50 % (i.e. same proportion of right/wrong, p=0.5), and alternative hypothesis would be > 50% (p_hat). Standard error (SE) is sqrt(p(1-p)/n) and Z = (p_hat - p)/SE.
Would this be a correct way of doing it? If not, how far off am I and what should I do instead, perhaps a t-test? What if the test is the tasting a difference between three things, rather than two; would it be wrong to still use a simple right/wrong metric, or should something else be used?
Answer: Fisher himself had such a discussion, which is detailed in his book, The design of experiments. Basically a lady working with him claimed she had the ability of differentiating tea made with boiled water than one without boiling, if I remember correctly; Fisher designed an experiment to check it. For an overview, see this wikipedia article, or check the book itself, I think it started with this example. He used the Fisher exact test.
Comment: She actually claimed she could taste whether the tea was added to the milk or the milk was added to the tea ;)
Comment: I'm not really sure how I get my data into a 2x2 contingency table. I mean, my only values are right/wrong, for a person - how do I expand that into a table?
Comment: @Sajber the contingency table is not right/wrong answer, but it would be 'person answer flower/stem part', for example for the rows, and 'real: flower/stem part'. The 'right' answer is if you fall into the diagonal of the contingency table. Ideally the test is double blind, so even the guy who asks doesn't know the correct answer (although is registered somewhere else).

Statistics on tastings


Comparing String from Dictionary to Multiple Strings

Question: I'm receiving a dictionary from a server and have a few expected values to get back, however there are times that I get values I don't want to process my code for. Is there a way I can do this check without needing to repeat dict["travel"] !=
if dict["travel"] != "Bee" and dict["travel"] != "Fly" and dict["travel"] != "Bird":
    print("Didn't receive flying animal of choice")
    return

Ideally my code would look like...
if dict["travel"] != ("Bee" or "Fly" or "Bird")
    print("Didn't receive flying animal of choice")
    return

Answer: If you want to check if either A, B, or C is in X, you do:
if X in [A, B, C]

In your case this is:
if not dict['travel'] in ['Bee', 'Fly', 'Bird']

To check the opposite, remove the not keyword
if dict['travel'] in ['Bee', 'Fly', 'Bird']

Answer: checks if dict["travel"] is not present in the list ["Bee", "Fly", "Bird"].
You can try this code:
if dict["travel"] not in ["Bee", "Fly", "Bird"]:
    print("Didn't receive flying animal of choice")
    return


Cartan subalgebras of a semisimple Lie algebra

Question: Let $L$ be a semisimple complex Lie algebra and $H$ a Cartan subalgebra. Suppose that $L=L_{1}\oplus ...\oplus L_{k}$ with each $L_{i}$ a simple ideal of $L$. Show that for $1\leq i \leq k$, $H\cap L_{i}$ is a Cartan subalgebra of $L_{i}$.
I have had no thoughts on this problem and no idea how to solve it hence I cannot make an attempt. I have seriously severe difficulties.
Comment: It is a bad idea to write «its Cartan subalgebra», for the Cartan subalgebra is not unique.
Comment: Same question [here](http://math.stackexchange.com/questions/2172722/cartan-subalgebra-proof).
Comment: @MarianoSuárez-Álvarez I have reworded this.
Comment: @DietrichBurde The link you gave leads to "Page not found"
Comment: Yes, the question was deleted and then asked again. But the link is still there.
Answer: Let $\phi_i\colon L\rightarrow L\cap L_i$ be the canonical projection to the $i$-th factor. We can use now the following lemma:
Lemma: Let $\phi:L\rightarrow L'$ be a surjective Lie algebra homomorphism, and $H$ be a Cartan subalgebra of $L$. Then $\phi(H)$ is a Cartan subalgebra of $L'$.
Proof: See Lemma $3.6.2$ here. The proof works also for not necessarily semisimple Lie algebras.
Answer: Hint: Let $C_i$ be the Cartan subalgebra of $L_i$, $\oplus_iC_i$ is a Cartan subalgebra of $L$ since it is Abelian and equal to its normalizer. $(\oplus_iC_i)\cap L_i=C_i$.
If $D$ is another Cartan subalgebra, there exists an automorphism $f$ of $L$ such that $f(\oplus_iC_i)=D$ (see property 3) in the reference. Such an automorphism sends a simple component to a simple component, We can write $f(C_i)=D_{f(i)}$ where $f(C_i)\subset L_{f(i)}$. We can write $D=\oplus_iD_i$.
http://mathworld.wolfram.com/CartanSubalgebra.html
Comment: You showed that there exist Cartan subalgebras whose intersections with the summands are Cartan subalgebras there, but the question is whether *every* Cartan subalgebra had that property.


How to find a type declaration in an XSD?

Question: I'm reviewing the XML for the UPS Shipping API, and the XSD contains this block:
  <xsd:complexType name="PackageType">
    <xsd:sequence>
      <xsd:element name="Description" type="xsd:string" minOccurs="0"/>
      <xsd:element name="PackagingType" type="PackagingTypeType" minOccurs="0"/>
      <xsd:element name="Dimensions" type="DimensionsType" minOccurs="0"/>
      <xsd:element name="DimWeight" type="PackageWeightType" minOccurs="0"/>
      <xsd:element name="PackageWeight" type="PackageWeightType" minOccurs="0"/>
      <xsd:element name="LargePackageIndicator" type="xsd:string" minOccurs="0"/>

...

I'd like to see what the possible values for PackageWeightType are, but I can't figure out how to backtrack.  The top of the XSD is
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:ups="http://www.ups.com/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="201707">
  <xsd:include schemaLocation="IF.xsd"/>

but there's nothing in IF.xsd that I can see that would help me in my quest.
What are my next steps?
Answer: The same XSD that houses PackageType (ShipConfirmRequest.xsd, version 201707) also contains PackageWeightType:
<xsd:complexType name="PackageWeightType">
    <xsd:sequence>
        <xsd:element name="UnitOfMeasurement" type="UnitOfMeasurementType"/>
        <xsd:element name="Weight" type="xsd:string"/>
    </xsd:sequence>
</xsd:complexType>

and UnitOfMeasurementType as well:
<xsd:complexType name="UnitOfMeasurementType">
    <xsd:sequence>
        <xsd:element name="Code" type="xsd:string"/>
        <xsd:element name="Description" type="xsd:string" minOccurs="0"/>
    </xsd:sequence>
</xsd:complexType>

Generally, to find a declaration:

Search first in the XSD in which you see its use.
Search next in the included/imported XSD files, and their
included/imported XSDs, recursively.  (Typically, if all files are
in a common directory, grepping the directory tree recursively will
suffice.)

If the component is in the same namespace, you need only look in the original XSD and the transitive closure of the included XSDs.  If the component is in a different namespace, you can typically find the XSD based upon the referenced namespace.
Comment: How can I deduce the possible values from this though if `Code` is just a string?  (How can I know if "OZS" is a possible code, for example?)
Comment: If Code is declared as xs:string, then the schema imposes no constraints on its value. There may be constraints imposed by some other mechanism (e.g. validation applied to user input fields on a form), but if the schema doesn't define the constraints then there's no point looking for them in the schema.


Plot $|z - i| + |z + i| = 16$ on the complex plane

Question:
Plot $|z - i| + |z + i| = 16$ on the complex plane

Conceptually I can see what is going on. I am going to be drawing the set of points who's combine distance between $i$ and $-i = 16$, which will form an ellipse. I was having trouble getting the equation of the ellipse algebraically.
I get to the point:
$x^2 + (y - 1) ^2 + 2\sqrt{x^2 + (y - 1)^2}\sqrt{x^2 + (y + 1)^2} + x^2 + (y+ 1)^2 = 256$
$2x^2 + 2y^2 + 2\sqrt{x^2 + (y - 1)^2}\sqrt{x^2 + (y + 1)^2} = 254$
It seems like I'm and doing something the hard way.
Comment: The set of points with constant sum of distances from given two points is an [ellipse](http://en.wikipedia.org/wiki/Ellipse). A derivation of the equation of the ellipse, given the two points and the sum of distances, is shown e.g in [this question](http://math.stackexchange.com/questions/70732/why-do-definitions-of-distinct-conic-sections-produce-a-single-equation).
Answer: Maybe it's quicker way.
Equation $|z-i| + |z+i| = 16$ is equivalent to
$$
\sqrt{x^2 + (y-1)^2} = 16 - \sqrt{x^2 + (y+1)^2}.
$$
Squaring both sides you obtain
$$
x^2 + (y-1)^2 = 256 - 32\sqrt{x^2+(y+1)^2} + x^2 + (y+1)^2.
$$
Some terms cancel out hence you get
$$
8\sqrt{x^2 + (y+1)^2} = 64 + y,
$$
and
$$
64(x^2 + (y+1)^2) = 64^2 + 128y + y^2.
$$
Finally
$$
64x^2 + 63y^2 = 64 \cdot 63.
$$
Now it is easy to write ellipse equation
$$
\frac{x^2}{63} + \frac{y^2}{64} = 1.
$$
Answer: He asked for a plot:

from here, where I used
$
\sqrt{x^2 + (y-1)^2} = 16 - \sqrt{x^2 + (y+1)^2}
$
from the currently accepted answer.
Comment: @Emre it's not, it's an ellipse (with a [flattening factor](http://en.wikipedia.org/wiki/Ellipse#Mathematical_definitions_and_properties)  $g=1-\frac {b}{a}=\frac{1}{64}$)! See the link(http://tinyurl.com/clunqaw)!
Comment: ok, it is an ellipse and i revoke the -1
Comment: -1 because this is not the plot of the complex equation of the question
Comment: @miracle173, why?
Comment: This is $|z|=8$
Answer: Just keep going:
$$2x^2+2y^2 + 2\sqrt{x^2 + (y - 1)^2}\sqrt{x^2 + (y + 1)^2} = 254$$
$$\sqrt{x^2 + (y - 1)^2}\sqrt{x^2 + (y + 1)^2} = 127 - (x^2+y^2)$$
$$(x^2 + (y - 1)^2)(x^2 + (y + 1)^2) = (127 - (x^2+y^2))^2$$
$$x^4 + x^2[(y - 1)^2 + (y + 1)^2] + [(y+1)(y-1)]^2 = 127^2 -2\cdot127\cdot(x^2+y^2)+ (x^2+y^2)^2$$
$$x^4 + 2x^2y^2 +2x^2 + (y^2-1)^2 = 127^2 -2\cdot127\cdot(x^2+y^2)+ x^4+y^4+2x^2y^2$$
$$x^4 + 2x^2y^2 +2x^2 + y^4-2y^2+1 = 127^2 -2\cdot127\cdot(x^2+y^2)+ x^4+y^4+2x^2y^2$$
$$2x^2 -2y^2+1 = 127^2 -2\cdot127\cdot(x^2+y^2)$$
$$x^2(2+2\cdot127) +y^2(-2+2\cdot127) = 127^2 -1$$
$$256x^2 +252y^2 = 16128$$
$$\frac {x^2} {63} +\frac {y^2} {64} = 1$$
Answer: Don't we all love algebraic solutions...
The ellipse has an equation of the form
$$(\frac {x} {a})^2 + (\frac {y} {b})^2 = 1$$
The focals are aligned on the y axis, therefore

a is the side of a rectangle triangle, the other site being 1 and the hypothenuse 16/2:

$$a = \sqrt{8^2-1}$$

b is 16/2.

The equation of the ellipse is
$$(\frac {x} {\sqrt{63}})^2 + (\frac {y} {8})^2 = 1$$
Or, to write it as above
$$\frac {x^2} {63} + \frac {y^2} {64} = 1$$
Answer: I think you are on the right track.
Wolframalpha also doesn't have a "simpler form" of the algebraic equation.
(see http://www.wolframalpha.com/input/?i=%28%7Cx%2Biy-i%7C%2B%7Cx%2Biy%2Bi%7C%29%5E2%3D256)
Maybe this question is meant to be done on computer. Usually questions done by hand will ask you to "sketch" the graph.
Answer: Sketching the graph gives a centrally symmetric ellipse with the imaginary axis as the major axis. The length of the half the major axis is clearly 8 (square 64), and pythagoras gives the square of half the minor axis as 63. This is reflected in the answer obtained by algebraic manipulation.
$$2x^2+2y^2 + 2\sqrt{x^2 + (y - 1)^2}\sqrt{x^2 + (y + 1)^2} = 254$$
$$\sqrt{(x^2 + y^2 + 1) - 2y}\sqrt{(x^2 + y^2 + 1) + 2y} = 127 - x^2 - y^2$$
Square both sides:
$$((x^2 + y^2 + 1) - 2y)((x^2 + y^2 + 1) + 2y) = (127 - x^2 - y^2)^2$$
$$(x^2+y^2+1)^2-4y^2 = 127^2+x^4+y^4-254x^2-254y^2+2x^2y^2$$
Cancelling as we go and gathering terms in the obvious way:
$$256x^2+252y^2=127^2-1=128 \times 126$$
(difference of two squares)
The divisions now become easy and we reach the canonical form:
$$\frac {x^2} {63} + \frac {y^2} {64} = 1$$


How do I run WinRM or PsExec in all domains and not only in the same subnet?

Question: I tested in my domain and I have this scenario:

In a computer with IP 10.100.40.10:

I can run the WinRM and PsExec on all computers with the same subnet: 10.100.40.*

In a computer with ip 10.200.30.50:

I can also run the same in all subnets: 10.200.30.*

But if I want to "cross" this subnet, it will fail even if I can see and check that the ports are OPEN for me. This mean:

In ip 10.100.40.10:

If I do nmap -p 135,445,3389,5985,5986 10.200.30.- the ports will show open!

The same in 10.200.30.50 for the subnet 10.100.40.10

So, how can I admin the computer on the same domain but on different subnet? What do I need to configure to make it work? What is blocking me?
Answer: Winrm uses TCP/5985, or TCP/5986 for TLS connections need to be enabled at the firewall.
For psexec, TCP/135, and 49152-65536 need to be enabled at the firewall.
Comment: Lol.. maybe I forget the correct port. But I mean the needed ports are opens. I can access it.. This is something about the subnets...
Comment: What does a netmon packet capture show on both ends (correlated capture) when performing a winrm ping? Which winrm port are you testing? Which protocol is used for authentication?
Comment: Also the Windows firewall configuration... It's common to have local subnets granted access. There are several variations of firewall rule configuration.
Comment: humm. netmon is new for me. I will test it. About the firewall, I tried to open it. I don't know how to check it. What is the correct way to troubleshooting it? Does you have a tutorial?
Comment: It's the same host based firewall that exists on every Windows host. And there is logging for both the firewall and Winrm, which is mostly likely in a domain and using Kerberos and 5985 by default. https://learn.microsoft.com/en-us/windows/security/operating-system-security/network-security/windows-firewall/ https://learn.microsoft.com/en-us/windows/security/operating-system-security/network-security/windows-firewall/rules


Send RTSP + Audio to RTMP server with ffmpeg

Question: I successfully sent an rtsp video stream to rtmp server (facebook) but have not been able to use audio using ffmpeg.
If I play RTSP from camera locally audio works fine.
This is the command I use (ubuntu server 16.0.4 LTS - ffmpeg 2.8.11):
sudo ffmpeg -f lavfi -i anullsrc -rtsp_transport tcp -i "rtsp://admin:firstname.lastname@example.com/mode=real&idc=1&ids=1" -tune zerolatency -vcodec libx264 -g 60 -keyint_min 60 -r 30 -pix_fmt + -b:v 4000k -acodec copy -ar 44100 -b:a 128k -strict experimental -f flv  "rtmp://live-api.facebook.com:80/rtmp/STREAM-KEY"

Here the full log:
https://www.dropbox.com/s/vo05n0kehs75iba/ffmpeg-20180207-100549.log?dl=0
Comment: Share full log.
Answer: -acodec copy -ar 44100 -b:a 128k -strict experimental is mutually exclusive. You are asking ffmpeg to copy and mux the audio format from source but at the same time you are attempting to encode it.
It should be either -acodec copy to copy without transcoding or -acodec {codec} {additional audio params} to transcode.
Facebook accepts only H.264 + AAC combination, see Live Video Specs at https://www.facebook.com/facebookmedia/get-started/live while you are actually copying audio format from anullsrc which is PCM. You should transcode to AAC with -acodec aac -ar 44100 -b:a 128k -strict experimental
Comment: thanks, just tried it now but no audio yet. Used: -acodec aac -ar 44100 -b:a 128k -strict experimental -f flv "rtmp url"
Comment: By no audio you mean that the stream from FB is then missing the audio track or just that you are not hearing anything? Anullsrc in your commandline is generating silence into the audio track.


Inverter valores da pilha

Question: Estou tentando inverter a ordem dos elementos da pilha usando o laço while, mas não estou conseguindo.
pilha* inverte(pilha **p) {
    pilha *outra = cria(); //aloca e seta a qnt com 0
    while(vazia(&p)) {
         outra->dados[outra->qnt++] = (*p)->dados[(*p)->qnt];
        (*p)->qnt--;
    }
    return outra;
}

Estou tentando pegar posição atual.
Comment: O código está bem esquisito, mas só com isto não sei se dá para responder adequadamente. Precisa colocar algo mais para entender como chegou aí e se o problema não está outro lugar.
Comment: A pilha é só de valores.
Comment: Esta exibindo um valor a mais. http://ideone.com/Q1QL37
Answer: Eu dei uma melhorada em várias coisas, entre elas simplifiquei a passagem de parâmetro, não precisa passar ponteiro de ponteiro. Mas o erro principal é que o operador >= não podia ser usado no while. Quando chega a 0 tem que parar, por causa do = ele fazia uma operação a mais. Mas também há um problema do outro lado. Começa pegando o índice equivalente à quantidade de elementos na pilha. Como índice começa em 0, o último é a quantidade menos 1. Com essas duas alterações funciona. Mas ainda não está liberando a memória (eu sei que é algo desnecessário nesse exemplo, mas é bom se acostumar fazer certo sempre):
#include <stdio.h>
#include <stdlib.h>

#define MAX 10

typedef struct pilha {
    int qnt;
    int dados[MAX];
} Pilha;
Pilha* cria() {
    Pilha *p = malloc(sizeof(Pilha));
    if (p != NULL) p->qnt = 0;
    return p;
}
void insere(Pilha *p, int valor) {
    p->dados[p->qnt] = valor;
    p->qnt++;
}
void exibe(Pilha *p) {
    for (int i = 0; i
qnt; i++) printf("%3d", p->dados[i]);
}
Pilha* inverte(Pilha *p) {
    Pilha *outra = cria();
    while (p->qnt > 0) {
        outra->dados[outra->qnt] = p->dados[p->qnt - 1];
        p->qnt--;
        outra->qnt++;
    }
    return outra;
}
int main() {
    Pilha *p = cria();
    insere(p, 32);
    insere(p, 45);
    insere(p, 78);
    exibe(p);
    p = inverte(p);
    printf("\n");
    exibe(p);
}

Veja funcionando no ideone. E no repl.it. Também coloquei no GitHub para referência futura.

Inverter valores da pilha


What is the logic behind "rule of thumb" for meaningful differences in AIC?

Question: I've been struggling to find meaningful guidelines for comparing models based on differences in AIC. I keep coming back to the rule of thumb offered by Burnham & Anderson 2004, pp. 270-272:

Some simple rules of thumb are often useful in assessing the relative merits of models in the set: Models having $\Delta i$ ≤ 2 have substantial support (evidence), those in which 4 ≤ $\Delta i$ ≤ 7 have considerably less support, and models having $\Delta i$ > 10 have essentially no support.

For example, see these questions:

How to compare models on the basis of AIC?
Difference in AIC as a measure of relative importance of variables
Testing the difference in AIC of two non-nested models

I'm trying to understand the rational justification for these threshold numbers of 2, 4, 7 and 10. The Wikipedia article on Akaike Information Criterion gives some guidance on this question:

Suppose that there are R candidate models. Denote the AIC values of
  those models by AIC1, AIC2, AIC3, …, AICR. Let AICmin be the minimum
  of those values. Then the quantity exp((AICmin − AICi)/2) can be
  interpreted as being proportional to the probability that the ith
  model minimizes the (estimated) information loss.
As an example, suppose that there are three candidate models, whose
  AIC values are 100, 102, and 110. Then the second model is
  exp((100 − 102)/2) = 0.368 times as probable as the first model to
  minimize the information loss. Similarly, the third model is
  exp((100 − 110)/2) = 0.007 times as probable as the first model to
  minimize the information loss.

So, based on this information, I compiled the following table:

delta_aic: Minimum AIC of all the models being compared minus AIC of the i th model under consideration. In the Wikipedia example, delta_aic for the model where AIC=100 is 0, for the model where AIC=102 is 2, and for the model where AIC=110 is 10.
prob(min vs. i): Model i is x times as probable as the minimum model to minimize the information loss. In the Wikipedia example, the model where AIC=100 is equally probable, the model where AIC=102 is 0.368 times as probable, and the model where AIC=110 is 0.007 times as probable.
prob(i vs. min): This is simply 1/prob(min vs. i). So, it means that the minimum model is x times as probable as Model i to minimize the information loss. In the Wikipedia example, the model where AIC=100 is equally probable, the minimal model is 2.7 times as probable as the model where AIC=102, and the minimal model is 148.4 times as probable as the model where AIC=110.

OK, so I think I get the mathematics somewhat, but I really don't understand what all this means in terms of practically selecting one model over another. The rule of thumb says that if the minimal model is 2.7 times as probable as another model (that is, $\Delta i$ ≤ 2), then the two models are practically equivalent. But why is 2.7 times probability in minimizing information so little as to be of no consequence? What does that even mean? Similarly, the rule of thumb says that only when you get to when the minimal model is 148.4 times as probable as another model (that is, $\Delta i$ > 10) would you say that the model under consideration can no longer be considered equivalent in any meaningful way. Isn't that an extremely huge amount of tolerance?
Even when breaking it down mathematically this way, the rule of thumb still does not make any intuitive sense to me. So, this brings me to my question:

Could someone please explain a simple logical justification for the commonly accepted rule of thumb for acceptable AIC differences?
Alternatively, could someone please provide alternative rational criteria that are better justified than this rule of thumb?
Comment: I do not know about the rules of thumb, but I would caution against the use of _any_ critical cutoff that entails a (or substitutes for) a decision. A decision regarding the merits of models should be made on the basis of the AIC and all other information.
Comment: I don't want to make it an answer 'cause it's only my guess, that doesn't fit perfectly to the numbers: $1-\exp(-\frac{1}{2}\cdot 2)\approx0.63$, which is quite close to the $1\sigma$ level (see the [68-95-99.7 rule](https://en.wikipedia.org/wiki/68%E2%80%9395%E2%80%9399.7_rule)). Similarly, $1-\exp(-\frac{1}{2}\cdot 6)\approx0.95$ ($2\sigma$) and $1-\exp(-\frac{1}{2}\cdot 10)\approx0.993$ ($3\sigma$). Maybe the first threshold (2) was chosen to be a round number; maybe $7$ was chosen instead $6$ 'cause it's a _lucky number_; maybe $10$ was chosen 'cause it's a decade, so a very round number.
Comment: @corey979, but what does $1−exp(−12⋅2)≈0.63$ actually mean, in layman's terms? Is it that 63% of models with the same real amount of information (in the sense of Akaike "Information" Criterion) would produce AIC values within that range? That would make sense, if that is what it means. (I'm not a statistician; I'm just an advanced user of statististics that tries to understand the real-world meaning behind the procedures I use.)
Comment: It is correct to argue against such rules of thumb.  The log likelihood scale, while extremely useful, is proportional to the sample size.  A difference in AIC of 1000 can be inconsequential for n=1,000,000.  You may not be able to notice improved predictions from the one with lower AIC in this case.   Need to supplement AIC with relative likelihood ratio $\chi^2$ and with other sample-size independent measures such as median absolute prediction error.  See also [here](https://fharrell.post/addvalue).
Comment: Sorry correct link is https://fharrell.com/post/addvalue
Comment: @FrankHarrell, your comment looks quite pertinent, but the link does not work for me. Could you please edit the link?
Comment: @FrankHarrell Thank you! this is very helpful.
Comment: I've seen it used for model mixing.  The probability difference is a lot like a p-value threshold in that it is problem and data dependent and needs to be handled with good care.
Answer: I encountered the same issue, and was trying to search an answer in related articles. The Burnham & Anderson 2002 (Model Selection and Multimodel Inference - A Practical Information-Theoretic Approach Second Edition) book actually used three approaches to derive these empirical numbers. As stated in Chapter 4.5 in this book, one approach (which is easiest to understand), is let $\Delta_p = AIC_{best} - AIC_{min}$ be a random variable with a sampling distribution. They have done Monte Carlo simulation studies on this variable, and the sampling distribution of this $\Delta_p$ has substantial stability and the 95th percentile of the sampling distribution of $\Delta_p$ is generally much less than 10, and in fact generally less than 7 (often closer to 4 in simple situations), as long as when observations are independent, sample sizes are large, and models are nested.
$\Delta_p > 10$ is way beyond the 95th percentile, and is thus highly unlikely to be the Kullback-Leibler best model.
In addition, they actually argued against using 2 as a rule of thumb in their Burnham, Anderson, and Huyvaert et al., 2011 paper. They said $\Delta$ in the 2-7 range have some support and should rarely be dismissed.
Answer: I might be able to provide some justification for the cutoff for AICs less than 2 units apart. I wrote a paper analyzing Quetelet's famous analysis of 5723 Scottish chest girths, one of the first applications of what would come to be called the normal distribution. Quetelet, long before goodness of fit tests, argued that the chest data were normal. Others have disagreed. The AIC for the fit of the normal to Quetelet's Scottish chest data is 24629. I generated 10000 random data with n =  5732 using Matlab's pseudo-random normal generator with the same mean and sd as Quetelet's data, obtaining a mean AIC of 24630 ± 2 [±  half  95% confidence interval]. I would certainly agree with the ▵AIC = 2 cutoff, but I have no idea about justification for the 4-7 or >10 cutoffs.
Gallagher, E. D. (2020). Was Quetelet's Average Man Normal? The American Statistician/Taylor & Francis, 74(3), 301-306. https://doi.org/10.1080/00031305.2019.1706635.


Why cant I say variable.array in this case?

Question: I don't see why I cant do this, without getting an error saying "Songs cannot be resolved or is not a field". I am a noob by the way, trying to learn this stuff :) Thanks in advance for you time, and please tell me if you need more information.
import java.util.ArrayList;

public class Band {

public String bandName;
public ArrayList<String> musician = new ArrayList<String>();
public ArrayList<String> songs = new ArrayList<String>();

// Constructor
 public Band(String bandName) {
    this.bandName = bandName;
 }

 public void getBandSongs(String bandName){
    for (String s : bandName.songs) {             <<<<<<<<<<<ERROR HERE
        String rating = s.substring(0,1);
        s = s.substring(1);
        System.out.println("Rating: " + rating + " - Song name: " + s);
    }
 }

}

Comment: `bandName` is a `String` variable. A `String` variable doesn't have a `songs` member.
Comment: I advise you to go through a [basic tutorial](http://docs.oracle.com/javase/tutorial/).
Comment: Please use code formatting for code, input/output & structured documents like HTML or XML.  To do that, select the sample and click the `{}` button above the messaged posting/editing form.
Answer: songs is a part of Band, not bandName.
use this.songs instead (or just songs).
It should be noted though that public fields are against encapsulation (and thus OOP). Is this really what you want?
The major benefit of encapsulation (providing getters & setters for instance members) is to have a unified way of accessing your fields in a class. This allows you to, for example, add validation logic to your data.
private List<String> songs = new ArrayList<>();

public List<String> getSongs(){
    return songs;
}

public List<String> setSongs(List<String> songlist) {
    this.songs = songlist;
}

Now you can add validation to these methods. For example if you want to make sure you can only set the songlist if it has at least 5 songs in it:
public List<String> setSongs(List<String> songlist) {
    if(songlist.size() > 5) {
        this.songs = songlist;
    }
}

Comment: What do you mean by public fields are agains encapsulation? Should I use private instead? If I do so, my program doesnt work. This is a assignment I have to make for tomorrow, so I apreciate your quick help already. Thank you.
Comment: Yes, you should make them private. Then you can access them trough a method that just sets/gets the field. I'll edit my post with a quick example.
Answer: Sometimes the errors that the IDE gives you are misleading, but this one is quite clear.
So, let's analyse it:
"Songs cannot be resolved or is not a field"
So that should ring up an alarm. First thing you should do is look at the type that is your variable bandName.
public void getBandSongs(String bandName){
      for (String s : bandName.songs) ...

It's a String! Of course you won't be able to access a field "songs" of a type String.
Maybe in your method signature you meant to have the following:
public void getBandSongs(Band band)

In that case, you should be able to access band.songs just fine.
Or you could have meant the following:
for (String s : this.songs)

That means you would be accessing the "songs" variable of the object instantiation of the class Band.
In summary:
The attributes that you define in your class:
public String bandName;
public ArrayList<String> musician = new ArrayList<String>();
public ArrayList<String> songs = new ArrayList<String>();

can be accessed through a variable that is of type of that class (in this case Band).
Hope this has made it a bit clear. Are you following any book in particular? I recommend the O'Reilly series. Good luck!
ps: I don't want to add too much since you are starting. But I advise you to read up on "encapsulation". That means that, unless strictly necessary, your should, by default, make your class's arguments private and let other classes access them through "getters" and "setters". Such that:
public class Band {

private String bandName;
private ArrayList<String> musician = new ArrayList<String>();
private ArrayList<String> songs = new ArrayList<String>();

public String getBandName(){
   return this.bandName;
}

public void setBandName(String bandName){
   this.bandName = bandName;
}

//And like that for the other two attributes. That way the classes that need access
// to these will either use a "get" method or a "set" method without directly
// accessing the attributes.

}

The work of creating getters and setters is so redundant that both Eclipse and Netbeans IDEs have a functionality that allows you to do these automatically.
Comment: Thank you. It helped a lot in understanding.. I just started at an introductory programming course, and im following the book Big Java Early Objects. Thanks for you help :)


Pegar posição prefab e comparar com outras prefab dentro de um grid? Unity 3D

Question: estou desenvolvendo um jogo estilo tetris, porem voltado para quimica. Ao invés de sumir uma linha completa e pontuar, o usuário precisa formar uma molécula. Pra isso, cada elemento (H e C) sao um prefab diferente. Com isso eu preciso identificar se o elemento C tem 4 H ao seu redor, para formar uma molécula e assim pontuar e sumir somente esses blocos. Dai minha duvida.. como faço pra pegar a posição que o C vai se encaixar no grid e comparar se próximo dele tem mais 4H? eu fiz isso, mas não funfou. Pode me ajudar?
public void Verifica(){

  while(gameStarted){

  for (int y = 0; y < gridHeight; ++y) {
   for (int x = 0; x < gridWidth; ++x) {
     if (Grid [x, y] == (GameObject)Instantiate(Resources.Load("Prefab/C"))) {
     Debug.Log ("Hello");//teste
      if(Grid[x+1,y] == (GameObject)Instantiate(Resources.Load("Prefab/H"))){
      cont++;
     }
      else if(Grid[x-1,y] == (GameObject)Instantiate(Resources.Load("Prefab/H"))){
      cont++;
     }
      else if(Grid[x,y+1] == (GameObject)Instantiate(Resources.Load("Prefab/H"))){
      cont++;
     }
      else if(Grid[x,y-1] == (GameObject)Instantiate(Resources.Load("Prefab/H"))){
      cont++;
     }
    }

    }Debug.Log ("Hello"+ cont); //teste
  }
 }
 }

Se cont++ == 4 fechou os elementos e pontuara.
se nao ele continuara fazendo a verificação com os restantes dos blocos..
OBS: os meus blocos sao formados apenas pelas prefabs C e H. que cairão de modo aleatório
Answer: Sua comparação está instanciando uma nova entidade de em base de um prefab, a comparação NUNCA vai ser true, e provavelmente seu cont sempre será zero.
Para realizar esse tipo de comparação recomendo usar tags, defina um valor na prefab para os objetos de C e outra tag para os objetos de H. Com isso, a princípio se a Grid for de GameObjects é só fazer Grid[x,y].tag == "tag".
Toda sua lógica pra construção do jogo fica igual, só muda o que mencionei que na hora de verificar ao invés de criar uma nova instância, verificar pela tag.
As tags são definidas neste ponto da tela:

Você pode usar o Add Tag pra ter outras opções que facilitem identificar melhor os teus objetos. Faça essa alteração no Prefab, porque aí todas as novas instâncias dentro do jogo vão refletir essa mudança da Tag.
Comment: DH. obgado pela resposta. Eu entendi o que falou, mas como faço isso no meu codigo?

`string GetRandomTetromino(){
  int randomTetromino = Random.Range (1, 5);
  string randomTetrominoName = "Prefabs/C";
  switch (randomTetromino) {
  case 1:
   randomTetrominoName = "Prefabs/H";
   break;
  case 2:
   randomTetrominoName = "Prefabs/C";
   break;
  case 3:
   randomTetrominoName = "Prefabs/H";
   break;
  case 4:
   randomTetrominoName = "Prefabs/C";
   break;

  }
  return randomTetrominoName;
 }`

e a variavel `nextTetromino = (GameObject)Instantiate(Resources.Load(GetRandomTetromino()`
Comment: Editei minha resposta pra refletir sua dúvida.
Comment: OK DH eu fiz isso. Ja adicionei as tags aos devidos prefabs, porem da o seguinte erro: NullReferenceException: Object reference not set to an instance of an object. Por que ele nao ta pegando o valor randomico gerado, quando ele da um return randomTetrominoName; Como vou saber qual caso ele pegou e como atribuir a tag? pq a logica da tag peguei, mas como faço para comparar se o valor randomico é da tag H  ou C? seria assim?
`case 1:
   randomTetrominoName = "Prefabs/H";
   randomTetrominoName = GameObject.FindWithTag ("H");`
Comment: @CarlosDiego Na verdade, é só fazer `Grid[x,y].tag == "tag"` como já tinha mencionado no começo da reposta. Talvez o `NullReferenceException` que você está tendo é porque espaços da sua grid vão ter `null`, e por isso você vai ter que verificar primeiro(`xpto != null`)se existe um objeto naquela posição antes de ler a `tag` dele.
Comment: DH. meu codigo esta como antes, `if (Grid [x, y].tag == "C")`
Comment: @CarlosDiego Sim, e aí como disse, antes de entrar nessa linha faça uma verificação de nulo: `if(Grid[x,y] != null)`, e aí sim execute o resto do seu código.
Comment: Mano tu pode me passar teu contato? estou precisando mto de sua ajuda..  e vc ja tem experiencia nessa area. Gostaria de trocar umas ideis ctg e quem sabe tu poder me desempancar nesse projetinho. To tentando aqui com o que vc falou por ultimo. vlw
Comment: DH o que vc falou deu certo em partes.. ele nao da mais erro, porem o contador continua em 0. Mas sinto que to no caminho pra que essa logica funcione
Comment: @CarlosDiego Isso era esperado, tu não pode percorrer uma matriz a cada frame do jogo. Você tem que fazer esse verificação só depois que a "peça" cair, aí você poderia verificar o array todo. Como você ainda não tem reputação pra ir pro chat, recomendo fazer uma nova pergunta caso venha a ter outros problemas :)
Comment: Entendi, estou fazendo novas perguntas afim de adquirir reputaçao o suficiente e conhecimento para aprimorar meu jogo. Ai no caso eu to chamando a funçao `Cecks()` no meu `Update()`, entao eu retiro e coloco dentro da funçao onde o meu objeto cai que da certo? abç e mais uma vez mto obgdo por me ajudar.


Confidence interval for slope of regression

Question: I want to run a test for the slope of regression with
$H_0: \text{slope}=0, H_a: \text{slope}>0$
Slope estimate: $4.034$, std. error $=0.250$, sample size $=144$.
However, if I find the one sided $95\%$ confidence interval I get $(-\infty, 4.034 + ME)$.  The interval always contains $0$ so it means I can't reject the null hypothesis at any point.
So if the slope estimate $x>0$, the upper bound will always be positive. Does it mean I can't reject the null hypothesis at any point for a one sided test?
I know I am making an logical error at some point but I simply cant figure out where. Any advice would be really appreciated thanks!
Answer: In a simple linear regression model $y_i=\alpha+\beta x_i+\varepsilon_i\,,\,i=1,2\ldots,n$ where the errors $\varepsilon_i$ are i.i.d $N(0,\sigma^2)$ with $\sigma$ unknown, a usual test statistic for testing $H_0:\beta=\beta_0$ against $H_a:\beta>\beta_0$ for some given $\beta_0$ is
$$T=\frac{\hat\beta-\beta_0}{\operatorname{s.e.}(\hat\beta)}\stackrel{H_0}\sim t_{n-2}\,,$$
where $\hat\beta$ is the least square estimator of the slope $\beta$ and $\operatorname{s.e.}(\hat\beta)$ is the estimated standard error of $\hat\beta$.
We reject $H_0$ at $5\%$ level of significance if $\text{observed } T>t_{0.05,n-2}$ where $t_{0.05,n-2}$ is the upper $5\%$ point of a $t$ distribution with $n-2$ degrees of freedom. When $n$ is large as in your case, the $t$ distribution is closely approximated by a standard normal distribution.
You have $\beta_0=0$, so the observed value of $T$ is about $16.136$ which exceeds the tabulated value $t_{0.05,142}\approx 1.645$. This suggests you should reject $H_0$ at $5\%$ level of significance.
To find a confidence interval from the above test, we consider the acceptance region associated with $$\frac{\hat\beta-\beta}{\operatorname{s.e.}(\hat\beta)}<t_{0.05,142}$$
That is, $$\beta>\hat\beta-\operatorname{s.e.}(\hat\beta)t_{0.05,142}$$
So a $95\%$ confidence interval for $\beta$ based on the data is approximately $(3.62275,\infty)$. Clearly you will always reject $H_0$ based on this interval.


Problems creating Drupal Commerce Product Display, list of available products not populating

Question: This is something that has happened to a site I'm maintaining. I can't create product displays for many of my products because the select list of products in the product field isn't populated with many of my products.
I have a content type called "Product Display" with product field of type product reference. When adding products the select list of products is only display 10 of about 100 products.
This only diagnostic information is that two javascript errors are reported
Uncaught TypeError: cannot read property 'behaviors' of undefind in jquery-noconflict.slicknav

And
Failed to load resource: Server responded with a status of 403 (forbidden)

This leads me to thing it's a jquery issue, but not sure how to debug this further.
So, how do I get that list of products to contain all of the products in the store?
Answer: This is a bug in Drupal Commerce 1.13. I'll be patching it today:
https://www.drupal.org/node/2697017