Time Series is not white noise but Random Walk

Question: I have time series data which is as shown below

To proceed with this series for building forecasting , I read many places if your data is not white noise and does not have random walk then you can model forecasting , Otherwise if your time series data is either white noise or has random walk then don't use time series forecasting
Is above condition has any implication if it is white series or has random walk?
However , when I check my time series it has not white noise but has random walk
For white noise I checked it using ACF plot
fig = plt.figure(figsize = (12,8))
ax1 = fig.add_subplot(211)
fig = sm.graphics.tsa.plot_acf(df.Frequencylags = 50, ax= ax1)

White noise distributions have approximately 0 autocorrelation at all lags. Above ACF plot does not show any 0 autocorrelation hence time series is not white noise
When I check random walk by using 1 differencing and check its ACF plot then no learnable patterns are found in first order differencing. In short, don't even bother with forecasting.
walk_diff = df['Frequency'].diff()

fig = plt.figure(figsize = (12,8))
ax1 = fig.add_subplot(211)
fig = sm.graphics.tsa.plot_acf(walk_diff.dropna(),lags = 40, ax= ax1)

When I do second order differencing then I see lag 1 in ACF plot shows learnable patterns in data once the series is stationary.Is my understanding correct after second order differencing ,ACF plot shows that data is not random walk. So with second order differencing I can go and use forecasting modelling?
walk_diff = data_dailies['Frequency'].diff().diff()
fig = plt.figure(figsize = (12,8))

ax1 = fig.add_subplot(211)
fig = sm.graphics.tsa.plot_acf(walk_diff.dropna(),lags = 40, ax= ax1)

My question

What an implication on forecasting modelling if your data is not white noise but has random walk by first order difference?

What an implication on forecasting modelling if your data is not white noise and neither has random walk by second order differencing?

Having with this above confusion when I model using SARMIAX and train it first 0 to 233 days and forecast on 234 to 281 then model give me almost same sum of counts as we have in actual data
model=sm.tsa.statespace.SARIMAX(df_train['Frequency'],order=(1, 2, 0),seasonal_order=(0, 1, 1,44),dynamic = False)
model_fit = model.fit()
print(model_fit.summary())

Upon forecasting
df_test['forecast'] = 0
df_test['forecast'] = model_fit.predict(df_test.index.min(),df_test.index.max(),dynamic=False)

df_test[['Frequency','forecast']].plot(figsize=(12,8));

print(f'Actual Count {df_test.Frequency.sum()} Vs Predicted Count {df_test.forecast.sum()}')

Actual Count 19471 Vs Predicted Count 20968.694112941106

Comment: you have to give us better axis titles or else I have no idea what I'm reading.
Comment: By eyeballing your data, it seems much more useful to consider seasonality when building a forecasting model. It does look neither white noise nor unit root nonstationary.
Comment: @Germania I changed axis labels of my data in first plot , please let me know if you want more information
Comment: Why are you differencing your data then drawing acf plots? You report the acf plots on the undifferenced data first.
Comment: @Germania first plot acf is for white noise using actual count , second acf plot using differenced random walk values to see after removing randomness in data by differencing to check whether data still white noise or not. I got this understanding from here https://towardsdatascience.com/time-series-from-scratch-white-noise-and-random-walk-5c96270514d3
Answer:
To proceed with this series for building forecasting , I read many places if your data is not white noise and does not have random walk then you can model forecasting , Otherwise if your time series data is either white noise or has random walk then don't use time series forecasting

You can use ARIMA when you have a random-walk. If you have white noise data you can fit a OLS regression rather than ARIMA.
Comment: Did you mean unit root instead of random walk? As RW is just what it is, there is no use of ARIMA modelling of it.
Comment: @user172500, yes, these things may take time to understand...
Comment: it means my data is random walk so I can go with ARIMA or SARIMAX?
Comment: @RichardHardy I don't have full understanding of unit root yet. However, I am here referring random walk. Now reading your response there is contradiction between you and Gerrmania. Now I am confused
Comment: @RichardHardy one thing is your statement about RW and this article are on same page, i believe random walk series is not good candidate for time series forecasting  https://towardsdatascience.com/time-series-from-scratch-white-noise-and-random-walk-5c96270514d3
Comment: @RichardHardy can we use AR for above time series? Using AR with lag 50 model forecasting out of sample is very close to actual data
Comment: @user172500, I am sorry I cannot help you more; I am busy at work.


js loses chars if typed too quickly

Question: OK, I got this completed and working and I've removed mention of some of the issues I had to assist with easy reading.
I am obfuscating the characters entered to a text box (id='user_pin_code') such that they appear to be ' * ' or ' **** ' according to the number of chars.
It's for the entry of a PIN code.
The first part takes the chars entered and replaces each with an ' * ' asterisk. So a 6 char PIN will show ' ****** '
All good so far, regardless of how quickly I type.
The next part takes the actual chars entered and populates another textbox (id='PINcode'), with the actual characters entered.
Trouble is, if I type quickly some are missed out.
so 'wxymdo' can be entered as 'wxmd'.
<code><script>
$(document).ready(function(e) {

var actualTextEntered = "";

    $("#user_pin_code").keyup(function(e) {

        var x = document.getElementById("user_pin_code").value;

        actualTextEntered += x.replace(/\\*/g,"");

        addEventListener('keydown', function(event) {
            const key = event.key; // const {key} = event; ES6+
            if ( key === "Backspace" ) {
                // Do something
                actualTextEntered = '';
                x='';
            }
        });

        document.getElementById("user_pin_code").value = "";

        for (var i=0;i<actualTextEntered.length;i++)
        {
        document.getElementById("user_pin_code").value += "*";
        document.getElementById("PINcode").value = actualTextEntered;
        }

    });

});
</code>
Comment: Why don't you use ``?
Comment: *"Should I be looking at this in a different way?"* Yes, you should try to stay as non-hacky as possible – it's important for reliability and accessibility. Your [other question](https://stackoverflow.com/questions/63204659/obfuscate-entry-to-textbox-in-ff) says "I want to mask from prying eyes whatever the user may enter" – is that just a nice-to-have? Are these one-time codes? If yes to both, I would leave it as visible text; that's pretty standard.
Comment: Pretty sure what mess you up here is the `setTimeout` function, you should make each function call wait for the previous function call be done first, then call next function. What you do is not a good practice, but if you insist, implement a task queue for the timeout function
Comment: Does the problem continue to exist if you remove the `console.log` line in the `keyup` handler? Logging on the console is blocking and can be sloooow.
Comment: But why is it secret like a bank PIN? The "Send me a new PIN" link makes it sound like it's ephemeral and maybe even a second factor.
Comment: It's for a two-stage and dual level login. Yes, PIN is a second factor but it's part of the access coding to a login area so must be secret.
Comment: Should have mentioned whilst this 'fix' is only for Firefox which doesn't support
        -moz-text-security:disc; I do want my code to work in all browsers.
Comment: @headache: What's the threat model where a random code is at risk when entered without masking into a textbox, but not at risk when being read from an e-mail?
Answer: The problem is just how the keyup event works, it tends not to be able capture some very fast inputs. Just the way onmousemove works, when the mouse moves very fast, some element will be skipped.
Why not use input type="password" or I think using oninput event can be a work around for you.

js loses chars if typed too quickly


Transparent splash screen on the first (and only first) startup of an app for instructions (iOS)

Question: I have a simple app where the buttons are in the form of logos rather than text.  Things like undo, reset, settings, etc...  I'm trying to keep the interface simple, so I just want to have instructions shown on the first ever startup of the app.  I've seen this done in other apps, where a transparent subview with labels is loaded, then touching the window dismisses the subview.
I currently have the launch count stored in NSUserDefaults, so I just need to figure out how to add the subview on top of the main view, which then gets dismissed on a touch.  I would like to just load a png that fits the screen size in the subview.
This seems simple, but I am having trouble not overcomplicating this process.
Thanks!
Comment: That link gets me to where I'm already at.  I should have been more clear that I'm at the point where I can detect if it's the first launch, but my first instinct was to load a whole other view, rather than a pop-up style view.
Answer: check for your NSUserDefaults for the first launc and if it is then you could display your image as a modalViewController and to dismiss it on touch use touchesBegan metod to dismiss this controller.
Comment: This seems to be the solution I'm looking for.  I'll give it a shot and update with what I come up with.
Answer:
This seems simple, but I am having trouble not overcomplicating this process.

What have you tried?
There's not much required to add a view to another view, but you don't even have to go that far. You could add your instructions view in your .xib/storyboard file and set it's hidden property to YES. Then all you need to do if the user is launching for the first time (or if they ask to see the instructions again) is flip the hidden property to NO, and then back to YES when they touch it.
Comment: I'm not using a storyboard.  There are only two views, a main view and a settings view.  I suppose I already know how to check whether it's the first launch by checking if the launchCount == 1.  I'm going to try using a modalViewController as Abhijit Chaudhari suggested, as that seems to be the solution I'm looking for.


Multiple contents per Jekyll layout

Question: How can I specify two different renderables within the same post?
Here's what I'm going for.  I have a post with some screen shots and then the body of the post.
---
layout: post
title: App Thing
---

<-- some screen shots for the top-->

<-- the main content of the post -->
blah blah blah blah blah

I render it in the post layout which will render the title and the date. However, I want the screenshots to go above the time and date and the body of the post below:
---
layout: default
---

{{ screenshots }}

{{ page.title }}

 {{ page.date | date: "%B %-d, %Y" }}

    {% if page.author %}
      {{ page.author }}
    {% endif %}

  {{ content }}

Any ideas how to do this? I'm using Github Pages so I'm also limited to the plugins I can use...
Answer: Two "content" areas isn't really possible with Jekyll...only with tricks.
The easiest solution (which doesn't use plugins) would be the following:

Put the images into a list in the post's front matter:
---
layout: post
title: App Thing
images:
  - screenshot1.jpg
  - screenshot2.jpg
---

<-- the main content of the post -->
blah blah blah blah blah

In the layout file, replace your {{ screenshots }} placeholder by a loop over the list from the front-matter:
---
layout: default
---

{% if page.images %}

    {% for image in page.images %}

    {% endfor %}

{% endif %}

{{ page.title }}

 {{ page.date | date: "%B %-d, %Y" }}

    {% if page.author %}
      {{ page.author }}
    {% endif %}

  {{ content }}

The part with the loop will then be rendered to the following HTML:

Additional information:
On my blog, I have two posts about building image galleries with Jekyll, without using plugins. Maybe this will help you:

Generating an image gallery with Jekyll and Lightbox2
Jekyll / Lightbox2 image gallery, another approach

The approach used in the second link is similar to the one that I just described here.

EDIT:

But I'm concerned with customizing it for different posts. One post may have a panorama, and another may have 10 images side-by-side. Thats why I liked the idea of having a div with classes I can control however I want...

If it's just about some CSS classes, you can do that with my approach as well.
Change the front-matter so that each image has an additional property, in this example I called it class:
---
layout: post
title: App Thing
images:
  - url: screenshot1.jpg
    class: wi5
  - url: screenshot2.jpg
    class: whatever
---

<-- the main content of the post -->
blah blah blah blah blah

Then, change the loop in the layout file like this:
{% if page.images %}

    {% for image in page.images %}

    {% endfor %}

{% endif %}

The generated HTML:

Does that help?
You can add more properties to each image if you need to do more stuff.
Comment: Hmmm. I like this. But I'm concerned with customizing it for different posts. One post may have a panorama, and another may have 10 images side-by-side. Thats why I liked the idea of having a div with classes I can control however I want...
Answer: When the content in your content area has the same structure on every page you should define them as structured data like @christian-specht suggested. If you have several content areas in your page or post layout, that you want to contain any kind of generic html-content, you can define a specific page-variable for each content area and assign multiline html content to them.
In my case I was looking for a way to render individual content to the header section of my page layout and flow the regular content in the designated main content area.
---
layout: default
title: My page title
header_content: >-

    ...
    ...

    ...

---
# regular content goes here

The corresponding tags in the layout file looked like this:

    {{ page.header_content }}

    {{ content }}

Multiple contents per Jekyll layout


How to get the value of a constant and save it to the database

Question: I have a constant class like so
Class MyConstants
{
const TEST = "asd";
const TEST123 = "foo";
const TEST333 = "fooBar";
const TEST321 = "bar";
}

In my controller I get all constants and select 3 at random, the problem is I only get the key from the constant but I need the value
$allConstants = $this->getAllConstants();
$foo = array_rand($allConstants, 3);

dd($foo)

 array:3 [
  0 => "TEST321"
  1 => "TES"
  2 => "TEST123"
 ]

How can i get instead the value of the constant which for example would be foobar ?
I also then need to save them to the database. Should i Loop over them ?
$fooBarEntity->setData($foo);

Thank you for your help.
Comment: Possible duplicate of : [Can I get CONST's defined on a PHP class?](https://stackoverflow.com/questions/956401/can-i-get-consts-defined-on-a-php-class)
Answer: array_flip exchanges all keys with their associated values in an array.
Try this:
Class MyConstants
{
    const TEST = "asd";
    const TEST123 = "foo";
    const TEST333 = "fooBar";
    const TEST321 = "bar";
}

$reflection = new ReflectionClass(MyConstants::class);
$values = $reflection->getConstants();
$data = array_rand(array_flip($values), 3);
foreach($data as $item) {
    #$fooBarEntity->setData($item);
}
print_r($data);

Comment: Remember to always exercise caution when using `array_flip()`, as if the same value is present multiple times in the array, every corresponding key except the last one will be lost.


wordpress custom field content as popup

Question: I have a price stored in the custom field 'price'. clickbtn is class that gives it shape of button. I am trying to have only "click here to reveal price" text within the clickbtn...what I am trying to achieve is when the person clicks on the clickbtn a popup comes which should hold the content of the 'price' as well as open the link www.bookurl.com in a new tab.

      <?php echo get_field('price');?> Click Here to reveal price

Answer: You must use javascript for this, not PHP as tagged.
The simplest way, with simple JS :
<?php echo get_field('price');?>

   Click Here to reveal price

This way, on click, link disappears, price appears, and popup opens.
Comment: not working...the text from the field price is not displayed in popup or otherwise at all now
Comment: plus i want the pop window to have the code...thts not happening here
Comment: You want a REAL popup, a new window ? or a "popin" a fake popup, styled in CSS, inside the window ? Because I don't get the point of having the price of a product in a separate window...
Comment: And for the price never appearing, I guess you have a problem elsewhere (get_field('price') not working ?) because this code works : http://jsfiddle.net/yEM98/
Comment: yes i was a real pop...spoiler or reveal type u know when u click on it a window comes with the hidden text.
Comment: in the fiddle the click here to reveal text is replaced by the price. instead i want a pop to show the price
Comment: see with the css its giving problem http://jsfiddle.net/yEM98/3/ an extra empty bar come up plus after clicking the price is outside the clickbtn and not inside as it shud be
Comment: Well, I don't know what is the "clickbtn", as you've forgotten the  closing tag. Anyway, you've not styled the clickbtn, but only the link inside, so it's perfectly normal.
Comment: And you've also miswritten the  closing tag.
Comment: Anyway, I suggest you to learn how popups work in javascript. For example : http://www.quirksmode.org/js/popup.html
Comment: here it is http://jsfiddle.net/yEM98/4/ ...after clicking the black box disappears behind the price how do i get tht to remain
Comment: plus if i have loop showing more than 1 item then on clickingon any click here to reveal ...it reveals only the first ones' price not the book i clicked on http://jsfiddle.net/yEM98/7/
Comment: You have only 1 item in your example. Anyway, you're using html IDs so your problem is normal : you have to use classes if you have several items. You can't have several items having the same ID.
Comment: $post->id grabs the id for each post right i put echo $price outside the span the price fields are echoed correctly, but inside only the first's price is displayed no matter which one u click
Comment: anything plz any tip on how to get it working for each
Comment: I was not speaking of PHP "->id", but HTML id="xxx", which has to be unique.
Comment: i still don't get it...html id will be for css right...css is not the problem now i have the box in background for both...
Comment: my problem now is - when multiple items i get the price using getfield...outside span it displays correctly but when inside it-its displays the price of the last item whichever one u click.
Comment: btw the html id is unique right 'price' and 'price_ad' in this case
Comment: You said you had several items (several prices) don't you ? Then you have id="price" more that once, am I wrong ?
Comment: Anyway, just to be sure : have you understood each bit of the code I've posted ? Or is some of it like chinese for you (or russian if you're chinese!) ?
Comment: i have many items each has a price...for each item i pull the price using the get_field into the variable $price...which i want to display    when the corresponding "click here" is clicked.
Comment: to check i removed the line style="display:none" from the spanid=price and the correct price is displaced...but i can't figure out y with tht bit it reveals only the last enter item's price instead of the corresponding one's
Comment: itsgot to do with onclick getting applied to the reveal the last item instead of the correspoding one
Comment: how do i get it to select id= "price" of the particular "post id"
Comment: Ok, so you have several items, each one has a span with id=price ; so is there only one id named "price" in your entire page ? I let you answer...
Comment: Anyway, if you had only tried to understand my code, you would know that id="price" is not only used for CSS, but also for Javascript.
Comment: i figured tht i have to generate unqiue spanid 'price' for each item and then target tht particular one onclick. but i m unable to ...say the postid is65 then i m trying to get the span id="price65" for it to begenerated dynamically...but can't
Comment: http://jsfiddle.net/yEM98/14/ onclick doesn'twork in this though i have managedto create different ids for each item
Comment: plz check the check on localhost...output on jsfiddle is coming very different for http://jsfiddle.net/yEM98/14/
Comment: I really think you're missing some basic concepts of Web Programming, like server-side (PHP) VS client-side (HTML/JS/CSS) languages. JsFiddle, as a client-side host, doesn't understand PHP ; and the way you put PHP inside javascript doesn't have any sense. PHP's only role, as a server-side language, is to **generate** a HTML/JS/CSS page. Once the page is on your screen, there is no more PHP - your browser doesn't understand PHP at all.
Comment: ok seeing the code...can u tell me y the click is not longer working
Comment: No I can't, have you thought for yourself ? have you looked at the source code of your page ? is everything ok ?
Comment: i can't figure it out where i m wrong...i donno know javascript
Comment: Well, this is not the place to learn basics of Javascript, there are lots of websites for it... But at least give your code, your generated HTML (somewhere like right click > show source).
Comment: Do you know what is a function in programming ?
Comment: ye i do know what functions is :) http://myproject.byethost7.com/test1.php u can see the code in action here
Comment: Well... it's perfectly working now, at least for your last problem, isn't it ?
Comment: yes guy at another thread helped correct the code ...seems href shudn't be there as u put it

wordpress custom field content as popup


Como fazer para que um form surja na tela ao clicar num link?

Question: Estou tentando fazer com que meu form apareça no espaço em branco ao lado quando eu clico no link "DIGITAR GUIA DE CONSULTA".
Já tentei algo como: (mas não tive o resultado esperado)
   <frameset cols="100%">
         <frame src="link da página aqui"></frame>
       </frameset>

Answer: Tem essa opção... Veja se ajuda.

.lightbox {
 /** Esconde a classe lightbox */
 display: none;
 /** Estilo basico para a classe */
}
.lightbox:target {
    /** Aplica essa regras quando target ocorre na classe */
    display: inline-block;
    outline: none;
}
a{
    display:block;
}
input{
float:left;
}
.close{
    /**Classe para fechar a div, se quiser*/
    display:inline;
    padding-left:7px;
}
Digitação de Guias

Digitar Guia de Consulta

  <form id="form_1">
      <input type="text" value="Nome"/>

      <input type="text" value="Email"/>
      <input type="submit" value="enviar"/>
      X
  </form>

Digitar Guia de Exames
Avisos Importantes

Qualquer coisa comenta que ajustamos.
Comment: No caso, meu form é feito em uma página, e a minha página restrita é em outra. Explicando melhor.. Quando o usuário fizer o login, será direcionado para a página restrita. Nessa página restrita, contém o link para digitar a guia de consulta. (A Guia de Consulta é feita em uma página, pois a ideia era que ao clicar no link "guia de consulta", abrir uma janela na qual contém o form). Mas agora preciso fazer com que ao clicar no link, surja o form no espaço em branco. E essa opção que você me deu, não faz isso.
Answer: Você pode utilizar  ou ainda pode fazer uma requisição em ajax com jquery para isso segue abaixo link de tutorial para as duas verções

http://www.w3schools.com/tags/tag_iframe.asp
ou para jquery com ajax
http://api.jquery.com/load/
Comment: se deu certo marque como concluído , caso tenha mais dúvidas m avise.
Comment: Se fosse pra deixar o form fixo na parte em branco do site, seria muito útil. Mas não ficou do jeito que eu gostaria.
Comment: manda o link ou ss de como ficou e explique como vc gostaria que funcionasse
Comment: Eu não tenho nenhum site como exemplo. Vou tentar explicar o máximo possível. Eu tenho uma página onde ao clicar num link "digitar guia de consulta", o formulário a ser preenchido apareça no espaço em branco da tela.
Comment: sim com iframe funciona certinho , no espaço em branco vc cria um iframe sem bordas do tamanho do espaço em branco quando vc clikar no link vc carrega um outro html com o formulario dentro do iframe
Comment: Eu fiz conforme me explicou ali em cima, e apareceu o form dentro do iframe.
Comment: Vamos [continuar esta discussão no chat](http://chat.stackexchange.com/rooms/45013/discussion-between-inez-boldrin-and-jasar-orion).


Script Inserção no Banco PHP

Question: Estou tentando inserir dados vindos de um formulário no banco, mas não está salvando no BD. Não consegui detectar o erro. Qualquer ajuda será válida.
<?php
require('login/autenticacao_usuario.php');
require('login/verificar_acesso.php');
require('BDconexao/conexao.php');
require('Agencia/funcoesAgencia.php'); //Função cadastrarAgencia encontra-se nesse arquivo
?>

<!DOCTYPE html>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title></title>

    <link href="../vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">

    <link href="../vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">

    <link href="../vendors/nprogress/nprogress.css" rel="stylesheet">

    <link href="../vendors/iCheck/skins/flat/green.css" rel="stylesheet">

    <link href="../vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css" rel="stylesheet">

    <link href="../vendors/jqvmap/dist/jqvmap.min.css" rel="stylesheet"/>

    <link href="../vendors/bootstrap-daterangepicker/daterangepicker.css" rel="stylesheet">

    <link href="../build/css/custom.min.css" rel="stylesheet">

                Bem-vindo(a),

<?php echo ucfirst($_SESSION['usuario']);?>

Menu Geral

 Home

 Agências

Cadastrar Agência

Lista de Agências

 Gerentes

Cadastrar Gerente

Lista de Gerentes

 MIP por Agência

Minha Agência

Funcionários

Cadastrar Funcionário

Lista de Funcionários

Quadro de Eletricistas

Cadastrar Quadro

Visualizar Quadro

Turnos

Cadastrar Turno

Visualizar Turnos

 MIP

Ocorrências Previstas

Cadastrar Ocorrências

Visualizar Ocorrências

Ocorrências Realizadas

Cadastrar Ocorrências

Visualizar Ocorrências

        Agência: <?php echo ($_SESSION['agencia']);?>

                    <?php echo ucfirst($_SESSION['usuario']);?>

Perfil

Sair

Cadastrar nova agência

                    <form action="<?php cadastrarAgencia(); ?>" method="POST"  class="form-horizontal form-label-left">

                        Descrição Agência:*

                          <input name="descricao" type="text" class="form-control" placeholder="Ex: Consórcio Salvador" required="">

                        Estado:*

                          <select class="select2_single form-control" name="estado" tabindex="-1" required="">

                              <option value="">Selecione o Estado</option>
                              <option value="ac">Acre</option>
                              <option value="al">Alagoas</option>
                              <option value="am">Amazonas</option>
                              <option value="ap">Amapá</option>
                              <option value="ba">Bahia</option>
                              <option value="ce">Ceará</option>
                              <option value="df">Distrito Federal</option>
                              <option value="es">Espírito Santo</option>
                              <option value="go">Goiás</option>
                              <option value="ma">Maranhão</option>
                              <option value="mt">Mato Grosso</option>
                              <option value="ms">Mato Grosso do Sul</option>
                              <option value="mg">Minas Gerais</option>
                              <option value="pa">Pará</option>
                              <option value="pb">Paraíba</option>
                              <option value="pr">Paraná</option>
                              <option value="pe">Pernambuco</option>
                              <option value="pi">Piauí</option>
                              <option value="rj">Rio de Janeiro</option>
                              <option value="rn">Rio Grande do Norte</option>
                              <option value="ro">Rondônia</option>
                              <option value="rs">Rio Grande do Sul</option>
                              <option value="rr">Roraima</option>
                              <option value="sc">Santa Catarina</option>
                              <option value="se">Sergipe</option>
                              <option value="sp">São Paulo</option>
                              <option value="to">Tocantins</option>
                            </select>

                        Cidade:*

                          <input type="text" name="cidade" class="form-control" placeholder="Ex: Salvador" required="" >

                          <button type="submit" class="btn btn-success">Salvar</button>
                          <button type="reset" class="btn btn-primary">Limpar</button>

                    </form>

            Copyright © 2017  - Todos os direitos reservados

Arquivo Funções Agencia:
<?php

   function cadastrarAgencia(){

  if(isset($_POST['submit'])){

   $descricao = $_POST['descricao'];
   $estado = $_POST['estado'];
   $cidade = $_POST['cidade'];

  try{

 $pdo = Conexao::getInstance();
 $insere = $pdo->prepare("INSERT INTO agencia VALUES(null,:descricao_agencia,:estado_agencia,:cidade_agencia)");

    $insere->bindParam(':descricao_agencia',$descricao, PDO::PARAM_STR);
    $insere->bindParam(':estado_agencia',$estado, PDO::PARAM_STR);
    $insere->bindParam(':cidade_agencia',$cidade, PDO::PARAM_STR);
    $insere->execute();

        if($insere!=NULL){

            print "";

        }else{

            print "";

        }

}catch(PDOException $e){

       echo $e->getMessage();

                       }

                        }
      }

     ?>

Comment: Não apareceu nenhum erro ?
Comment: Não, só dá reload na página. Fiz alguns testes,me parece que os dados do form estão vindo como nulo.
Answer: Você não pode colocar na action do form a chamada da função php. Ele não reconhece. O correto é submeter o seu formúlario para a própria página do html e verificar se foi enviado post. Se sim dai chama a função cadastrarAgencia().
Altere o form action:
<form action="nome_arquivo_html_formulario" method="POST"  class="form-horizontal form-label-left">

No início do arquivo após os requires faça um teste se está sendo enviado um post.
<?php
require('login/autenticacao_usuario.php');
require('login/verificar_acesso.php');
require('BDconexao/conexao.php');
require('Agencia/funcoesAgencia.php'); //Função cadastrarAgencia encontra-se nesse arquivo
if(isset($_POST)){
  $this->cadastrarAgencia();
?>

Script Inserção no Banco PHP


Execute SQL Server Pass-Through Query From Access VBA

Question: I have an UPDATE pass through query saved in Access 2007. When I double-click on the pass through query it runs successfully. How can I get this query to run from VBA? I'd like it to run when my "splash screen" loads.
I'm currently using the following code:
CurrentDb.Execute "Q_UPDATE_PASSTHROUGH", dbSQLPassThrough
But I get the following message:

The pass-through query contains all the connection information and I've confirmed the SQL syntax is correct by running it multiple times, so not sure what I'm missing in my VBA call.
Answer: Use the QueryDef's Execute method:
CurrentDb.QueryDefs("Q_UPDATE_PASSTHROUGH").Execute

I don't think you should need to explicitly include the dbSQLPassThrough option here, but you can try like this if you want it:
CurrentDb.QueryDefs("Q_UPDATE_PASSTHROUGH").Execute dbSQLPassThrough

Answer: I recently ran into the same problem. While the above mentioned Execute method is working for most cases, some people (me included) experiencing a Run-time error '3001': Invalid Argument when using the parameter dbSQLPassThrough. This was also addressed in the answer above me and happens even in the simplest SQL-statements.
For those who are having the same problem, I recommend using the OpenQuery method as alternative.
A valid substitution for the following code
CurrentDb.QueryDefs("Q_UPDATE_PASSTHROUGH").Execute

would be
DoCmd.OpenQuery "Q_UPDATE_PASSTHROUGH"

I know this thread is 4 years old, however, searching for a solution for the not working Execute method on Google brings you directly to this thread which is why I thought it would be useful to add an alternative solution which solved this problem for me.
Comment: No. If you `.Execute` a saved query that is a PT query (i.e. has a Connect string), you don't need the parameter - Access knows it's a PT query and will not try to run it with the Access DB engine. In most cases it wouldn't work anyway, since the SQL dialects are different between Access and the server DB.
Comment: *experiencing a Run-time error '3001': Invalid Argument when using the parameter dbSQLPassThrough.* -- Does it also not work if you omit the parameter dbSQLPassThrough?
Comment: The `Execute` statement works if I omit the _dbSQLPassThrough_ parameter, but from my still very limited understanding of Access VBA I thought it is necessary to use it because otherwise the heavy SQL-statement be executed on my local machine instead on the SQL Server.
Answer: I confirm that the QueryDef's Execute method is the recommended way to achieve your goal.
CurrentDb.QueryDefs("Q_UPDATE_PASSTHROUGH").Execute

However, I can point out that in a similar case with Access 2010, using dbSQLPassThrough for the Options parameter caused a Run-time error '3001': Invalid Argument.


Meu innerText não está funcionando

Question:

<!DOCTYPE html>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Estudando eventos DOM</title>

        Interaja

Comment: [`innerText`](https://developer.mozilla.org/pt-BR/docs/Web/API/HTMLElement/innerText) não é uma função é uma propriedade, então `a.innerText('Clicou!')` esta errado deveria ser `a.innerText = 'Clicou!'`
Comment: `element.innerText` não é uma função, é uma propriedade. Você deve atribuir algo a ela usando `a.innerText = "texto"`
Comment: Por favor, esclareça seu problema ou forneça detalhes adicionais a fim de destacar exatamente o que você precisa. Da forma como está escrito atualmente é difícil dizer com exatidão o que você está perguntando.
Answer: Segue seu código com as devidas correções.
<!DOCTYPE html>

    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Estudando eventos DOM</title>

Interaja

Meu innerText não está funcionando


Theme hook not found on custom module

Question: I'm trying to create a module which adds a page, the controller works but I cannot render a twig template for it.
The page layout is displayed without the page I created and this warning is reported in the logs:
"Theme hook eu_calendar not found."
but I do have the hook defined
This is the controller:
class EuCalendarController extends ControllerBase {

    public function index() {
        return [
            '#title' => 'my title',
            '#theme' => 'eu_calendar',
            '#description' => 'description test',
        ];
    }
}

Module file:
function eu_calendar_theme($existing, $type, $theme, $path) {
    return [
        'eu_calendar' => [
            'template' => 'index',
        ],
    ];
}

I also tried adding variables like
function eu_calendar_theme($existing, $type, $theme, $path) {
    return [
        'eu_calendar' => [
            'variables' => [
                'test_var' => NULL,
            ],
            'template' => 'index',
        ],
    ];
}

What am I missing here?
And do I need to configure anything with the regions, I want my module to be displayed in the content region by default...
Any documentation or tutorial is also welcome, I read a bunch of them none of them is explaining the options and details.
Comment: You are missing render element/variables. Template is redundant.
Comment: @IvanJaros I tried adding variables, nothing changed. I want `/modules/eu_calendar/templates/index.html.twig` to be rendered so I thought 'template' => 'index' is about that...
Comment: You sure the file saved to the correct server?
Comment: I had saved the file as...`mymodule.theme` \*facepalm* Just to clarify, it's supposed to be saved in the **`mymodule.module`**.
Answer: myModule.module
function myModule_theme($existing, $type, $theme, $path) {
return array(
 'pagina_3' => array(
   'variables' => array(
     'titulo' => 'title',
     'descripcion' => 'description',
     'formulario'   => NULL
      ),
    'template' => 'pagina_3'
   )
  );

}

mymodule/templates/pagina_3.html.twig

{{ titulo }}

{{ descripcion }}

        {{ formulario }}

myModuleController.php
public function verPagina3() {

    $form = $this->formBuilder()->getForm('Drupal\myModule\Form\InsertarGastoForm');

    // Le pasamos el formulario y demás a la vista (tema configurado en el module)
        return [
            '#theme' => 'pagina_3',
            '#titulo' => $this->t('Formulario crear empresa'),
            '#descripcion' => 'Formulario para crear una nueva empresa en Drupal 8',
            '#formulario' => $form
        ];

   }

Comment: `'#titulo'`, `'#descripcion'`, `'#formulario'`. It's news to me that Render Arrays allow using Spanish words as properties.
Answer: I guess I couldn't be able to clear the caches or something. I changed the hook name, uninstalled the module and installed it back, cleared the caches, restarted php-fpm and memcached etc. and it started working somehow.
For reference this is how theming works, may help other newcomers like me:
First the theme and the variables that needs to be passed is defined inside the *.module file. The trick is the variables key, without it Drupal ignores the definition.
The key of the array is also the name of the twig file by default, which can be overridden with template. So no need to pass template if it's the same with the key.
The theme definition to be rendered is defined inside the controller with #theme. Any variable that is not defined in the theme definition are not sent to the template even it's sent in the controller.
So the final working code is:
Module: (modules/eu_calendar/eu_calendar.module)
function eu_calendar_theme($existing, $type, $theme, $path) {
    return [
        'index' => [
            'variables' => [
               'featured' => [],
               'events' => [],
            ],
        ],
    ];
}

Controller: (modules/eu_calendar/src/Controller/EuCalendarController.php)
namespace Drupal\eu_calendar\Controller;

use Drupal\Core\Controller\ControllerBase;

class EuCalendarController extends ControllerBase {
    public function index() {
        return [
            '#theme' => 'index',
            '#events' => ['event1', 'event2'],
            '#featured' => ['featured1', 'featured2'],
        ];
    }
}

Template: (modules/eu_calendar/templates/index.html.twig)

Featured Events

    {% for featured_event in featured %}

{{ featured_event }}

    {% endfor %}

Events

    {% for event in events %}

{{ event }}

    {% endfor %}

Comment: I just had the same thing in a Drupal 10 site... I built and installed loads of the module *without* a `.module` file... And then added the file with a correct theme hook but the hook never fired... I wonder if Drupal caches that there is no module file during install and then forever doesn't look for one again during cache clears?
Comment: I also experienced this in a Drupal 10 site.  Some combination of repeatedly uninstalling and reinstalling the module, running cron and clearing the cache eventually fixed it.  Clearing the cache was not, by itself, sufficient to fix the issue.
Comment: UPDATE:  For me, the problem returns again on the next cache clear.  Drupal can't see the template at times.
Comment: UPDATE-2:  I had to change the name of my module to fix this.  Now when I clear the cache, the problem doesn't come back.
Answer: This is the controller:
public function index()
{
    $build['myelement'] = array(
        '#theme' => 'eu_calendar',
        '#title' => 'my title',
        '#description' => 'description test',
    );
    return $build;
}

Module file:
function eu_calendar_theme($existing, $type, $theme, $path)
{
    return array(
        'euCalendar' => array(
            'template' => 'index',
            'path' => $path . '/templates',
            'variables' => array(
                'title' => NULL,
                'description' => FALSE,
            ),
        ),
    );
}

Answer: I had a similar issue, when implementing templates for a custom block in Drupal 10.1. I propose here two important lessons I have learnt while solving it.
Matching (some) strings
Theme name, which is the value of the array element labelled #theme defined in controller's class (file MyController.php), must exactly match the name of hook returned by hook_theme() (function my_module_theme(), declared in file my_module.module).
Please, let me stress about this, as in my case it was causing the error!
Indeed I was confused by that automatic substitution of dashes instead of underscores, and initially I was incorrectly putting dashes (e.g. my-module--my-entity--card) when declaring theme name inside controller's class (MyController.php), as I would do when naming template files. But hook's name returned by my hook_theme() function (my_module_theme() from my_module.module) had underscores in place of dashes (i.e. my_module__my_entity__card) - as per the common convention of using underscores for hooks names. This way I experienced the error "Theme hook my-module--my-entity--card not found.". Then, to solve it and finally pick up the my-module--my-entity--card.html.twig template file, I simply had to rewrite declaration of theme name in controller's class (MyController.php) to my_module__my_entity__card.
Please note that, as already written in another answer, programming hook_theme() to also returns an array element labelled template is needed only if you desire to apply a template with different filename (not the same as the theme - except for underscores, which are turned to dashes).
Rebuilding cache
As usual when working wiht Drupal's templates, you do have to refresh Drupal's cache (either by running the command drush cr, or through the web interface) after you have added any new Twig template files to your /templates directories. Later, if you have properly set options for development, you do not really need to refresh cache after jsut saving changes to templates.
It is also worth mentioning that you will need to update Drupal's cache as well, whenever you add/rename a variable (to be passed to the template) into section variables of the array returned by function hook_theme() in module's file.
If you add a variable to the hook_theme(), but omit to rebuild the cache before using that variable in templates, Drupal will not raise any error; it will just treat the variable as null, although your controller might have assigned values to that variable.

Theme hook not found on custom module


Winget sql logic error 0x87af0001 sql error or missing database when trying to update or list packages

Question: So, I have to update the windows package oh-my-posh, and I try to use the indicated command winget upgrade oh-my-posh. But the result is this:
sql logic error
0x87af0001 : sql error or missing database

I also get this when I try to list All the Packages installed.
Does anyone know how to solve it? Thanks.
Answer: The solution that worked for me was posted by user sercannaya on the official winget-cli github repo, issue #1999:

I was having the same problem recently. I deleted the "installed.db"
file and solved the problem.
The location of the file "installed.db":
%LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\StoreEdgeFD
Answer: Have you tried updating your sources?
winget source update --force in admin mode.
Are you using the latest client?
As of July 2022 the latest 1.3.1741 release candidate is out at GitHub.


pf - redirect rule does not work

Question: I'm using pf on FreeBSD 9.
sshd is up and listening on loopback only (127.0.0.1).
Trying to use redirect rule to allow network hosts to connect via ssh.
set block-policy drop
set skip on lo0
scrub in

no rdr on lo0 all
rdr on fxp0 inet proto tcp from any to (fxp0) port = ssh -> 127.0.0.1

block drop in log quick on ! lo inet from 127.0.0.0/8 to any
block drop log on fxp0 all
pass in quick on fxp0 inet proto tcp from any to 127.0.0.1 port ssh
pass out quick on fxp0 all keep state

This does not work for some reason and I see no related messages in pflog.
Tried also with rdr pass with same result.
I see this status from pfctl -ss:
all tcp 127.0.0.1:22 (192.168.0.40:22) <- 192.168.0.252:65105   CLOSED:SYN_SENT

When I turn logging for rdr, I see this:
rdr in on fxp0: 192.168.0.252.65105 > 127.0.0.1.22: Flags [S], seq 1927917349, win 65535, options [mss 1460,nop,wscale 3,sackOK,TS[|tcp]>

What is wrong with my setup?
How to get more log output?
Comment: I'm voting to close this question as off-topic because it's three years old and lacks sufficient information to find an answer
Answer: Have you checked your sshd listening addresses?
$ netstat -a | grep ssh
tcp4       0      0 *.ssh                  *.*                    LISTEN
tcp6       0      0 *.ssh                  *.*                    LISTEN

The first * means that sshd is listening on every local addresses on the machine including 127.0.0.1.

SSHD_CONFIG(5)
 ListenAddress
         Specifies the local addresses sshd(8) should listen on.  The fol-
         lowing forms may be used:

               ListenAddress host|IPv4_addr|IPv6_addr
               ListenAddress host|IPv4_addr:port
               ListenAddress [host|IPv6_addr]:port

         If port is not specified, sshd will listen on the address and all
         prior Port options specified.  The default is to listen on all
         local addresses.  Multiple ListenAddress options are permitted.
         Additionally, any Port options must precede this option for non-
         port qualified addresses.

If sshd is not listening on address 127.0.0.1, it is shown as CLOSED:SYN_SENT in pfctl -ss output.
netstat output after making sshd listen on 192.168.10.114 only.
$ netstat -a | grep ssh
tcp4       0      0 192.168.10.114.ssh     *.*                    LISTEN

While trying to ssh to this machine, pfctl -ss output is like below.
$ pfctl -ss
all tcp 127.0.0.1:22 (192.168.10.114:22) <- 192.168.10.107:50701       CLOSED:SYN_SENT

ssh connection is redirected to 127.0.0.1 by rdr rule - SYN packet is sent to 127.0.0.1:tcp/22 (SYN_SENT)
However, 127.0.0.1:tcp/22 is not open, it is shown as CLOSED.
Comment: or try sockstat to display listening sockets; ~]sockstat -4l | grep ssh

pf - redirect rule does not work


Minimizing Huber Loss

Question: Huber Loss is given as follows:

I'd like to proof $\gamma=median\{y_1,...y_N \}$ minimizes the Huber Loss so i've taken its first derivate for $\gamma\neq y_i$:

I've tried to proof that first derivate change its signal before and after the median, i mean $\frac{\partial R}{\partial \gamma}<0$ when $\lambda< median$ and $\frac{\partial R}{\partial \gamma}>0$ when $\lambda > median$ but i didnt get any satisfactory solution.
Answer: You have an error in the definition of Huber loss: $\delta$ should be before the parentheses in the second addend.
$$
R = \sum_{|y_i-\gamma| \leq \delta} \frac{1}{2}\left(y_i - \gamma\right)^2 + \sum_{|y_i-\gamma| > \delta} \delta \left(|y_i - \gamma| - \frac{\delta}{2}\right)
$$
But ultimately, there is a bigger problem here: unless I'm misunderstanding something, you cannot prove your theorem, because it's not true.
Consider $y = \{1, 2, 3, 4, 10\}$ and $\delta = 6$. For $\gamma = median(y) = 3$, the Huber loss is $R = 42$. However, for $\gamma = 4$, the Huber loss is $R = 25$, which shows that $median(y)$ does not minimise the Huber loss.

Minimizing Huber Loss


How to change the background color of the android calendar view?

Question: I am using the native calendar view present in android.I want to change the back ground colour of some of the dates present in the calendar view . I don't find any methods in the documentation . Can some one help me out ?
Comment: http://stackoverflow.com/questions/16556254/android-calendarview-for-showing-events
Answer: you need to build your own CustomCalenderView
extends the Native CalendarView and build the behaviour that you want to color the background .
or you can use this library : TimesSquare for Android
and think it provide what you are looking for .
and please give me feedback .
Hope That Helps .
Comment: Thanks ...Do u have any which method I should override ??Are there any other alternate ways ?Do you know any other third party lib which allows the developer to change the background color of the particular dates in the calendar ??


How to avoid multicolinearity in SVM input data?

Question: Do you know of any techniques that allows one to avoid and get rid of multicolinearity in SVM input data? We all know that if multicolinearity exists, explanatory variables have a high degree of correlation between themselves which is problematic in all regression models (the data matrix is not invertible and so on).
My question is actually a bit more subtle as relevant data has to be selected. In other words, multicolinearity must be avoided while keeping relevant input data. So in a way, I guess that my question is also about reducing the input data matrix dimension.
So, I've thought about PCA, which permits both reducing dimension and getting uncorrelated vectors (the PCs), but then I don't know how to deal with the eigenvector's signs.
Comment: Just a note that multicollinearity can exist even if there is no pair of variables that are highly correlated. Multicollinearity is a trait of sets of data. E.g., if you have 11 variables and one is a sum of the other 10, you will have perfect collinearity, but no high correlations:
Comment: Yeah you can. But try using the full data and then try reducing with different (sum total) eigenvalue thresholds and see if there is a significant difference. Because if you fit an SVM with a transformed basis you have to apply this transform on each new data point when used for prediction.
Comment: If multi-colinearity is high then when you plot the sorted eigenvalues of the SVD (of the standardized covariance matrix) you should see a number of small values near the end. You can zero these out, and form a basis with reduced dimension. I don't know why the eigenvalue's sign is a problem.
Comment: Also I don't think SVMs are too sensitive to multicollinearity, especially when used with kernels. If some dimensions are collinear, they will contribute identically to the pairwise kernel distances but the SVM will just seperate on the dimensions that do contribute. Multi-colinearity is more of an issue when $(X^tX)^{-1}$ is necessary for the fit/inference.
Comment: Ok, so If I consider a given dataset, I carry out a PCA on its covariance matrix, then extract de most significant PCs and use them as input data for my SVM. Am I right?
Comment: I'm using SVM to perform a C-classification. If for example I'm choosing to indicators that are correlated with each other, maybe this correlation will have an impact on classification. This correlation could overweight a given feature and then lead to misclassification. Idon't know if I'm right saying that...
Comment: Multi-collinearity reduces the effective dimensionality of your data. For an SVM this means it has less space to separate the classes into. However the  "kernel trick" can take a relatively low-dimensional space and map it into a much higher one where separation is simpler. So a modest rank input matrix may still be fine, in some models (linear regression) $(X^tX)^{-1}$ is necessary for both the fit and inference, so you can get into trouble. The SVM however only depends on kernel distances.
Comment: 'x1 <- rnorm(100)
x2 <- rnorm(100)
x3 <- rnorm(100)
x4 <- rnorm(100)
x5 <- rnorm(100)
x6 <- rnorm(100)
x7 <- rnorm(100)
x8 <- rnorm(100)
x9 <- rnorm(100)
x10 <- rnorm(100)
x11 <- x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10
dv <- rnorm(100)
junk <- data.frame(cbind(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,dv))
cor(junk)
library(perturb)
m1 <- lm(dv ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11)
colldiag(m1)'
Answer: Multicolinearity is not generally a problem for SVMs.  Ridge regression is often used where multicolinearity is an issue, as the regularisation term resolves the invertibility issue by adding a ridge.  The SVM uses the same regularisation term as ridge regression does, but with the hinge loss in place of the squared error.
Ridge regression has a link with PCA as explained by Tamino, essentially it penalises principal components with large eigenvalues less than components with low eigenvalues, so it is a bit like having a soft selection of the most important PCs, rather than a hard (binary) selection.
The important thing is to make sure that the regularisation parameter, C, and any kernel parameters are tuned correctly and carefully, preferably by minimising an appropriate cross-validation based model selection criterion.  This really is the key to getting good results with an SVM (and kernel methods in general).


Problemas com Thread em JavaFX

Question: Estou criando uma aplicação para receber as portas seriais em uso do computador usando a biblioteca jSerialComm.
Para isso, gostaria de ficar atualizando essa informação em um ComboBox. Porém não consigo implementar a Thread corretamente.
Utilizei o Service e o Task. Mas sem sucesso.
Segue o código:
import com.fazecast.jSerialComm.SerialPort;

import javafx.application.Application;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;

public class Main extends Application {
    private static ComboBox<String> cbPortas = new ComboBox<String>();

    @Override
    public void start(Stage primaryStage) {
        AnchorPane root = new AnchorPane();

        Label lblPort = new Label("Selecione a porta:");
        AnchorPane.setTopAnchor(lblPort, 10.0);
        AnchorPane.setRightAnchor(lblPort, 50.0);
        AnchorPane.setLeftAnchor(lblPort, 95.0);

        AnchorPane.setTopAnchor(cbPortas, 40.0);
        AnchorPane.setRightAnchor(cbPortas, 65.0);
        AnchorPane.setLeftAnchor(cbPortas, 65.0);

        Button btnConectar = new Button();
        btnConectar.setText("Conectar");
        AnchorPane.setTopAnchor(btnConectar, 100.0);
        AnchorPane.setRightAnchor(btnConectar, 50.0);
        AnchorPane.setLeftAnchor(btnConectar, 50.0);

        Button btnIniciar = new Button();
        btnIniciar.setText("Iniciar Controle");
        AnchorPane.setTopAnchor(btnIniciar, 150.0);
        AnchorPane.setRightAnchor(btnIniciar, 50.0);
        AnchorPane.setLeftAnchor(btnIniciar, 50.0);

        root.getChildren().addAll(lblPort,cbPortas,btnConectar,btnIniciar);

        Scene scene = new Scene(root,320,220);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        Service<Void> service = new Service<Void>() {
            @Override
            protected Task<Void> createTask() {
                return new Task<Void>() {
                    @Override
                    protected Void call() throws Exception {
                        //Background work
                        SerialPort[] portNames = SerialPort.getCommPorts();
                        for(SerialPort portName:portNames){
                            cbPortas.getItems().add(portName.getSystemPortName());
                        }

                        return null;
                    }
                };
            }
        };
        service.start();

        launch(args);

    }
}

Como proceder?
Answer: Acredito que o problema está na alteração dos itens do combobox que você está fazendo, vamos tentar usar um ObservableList.
Atributos:
private ObservableList<String> items;
private Service<Void> service;

Método start:
@Override
public void start(Stage primaryStage) {
    // [...] Código omitido
    items = FXCollections.observableArrayList();
    cbPortas = new ComboBox<String>(items);

    service = new Service<Void>() {
        @Override
        protected Task<Void> createTask() {
            return new Task<Void>() {
                @Override
                protected Void call() throws Exception {
                    //Background work
                    items.clear();
                    SerialPort[] portNames = SerialPort.getCommPorts();

                    for(SerialPort portName:portNames){
                        items.add(portName.getSystemPortName());
                    }

                    return null;
                }
            };
        }
    };
    service.start();

    root.getChildren().addAll(lblPort,cbPortas,btnConectar,btnIniciar);

    Scene scene = new Scene(root,320,220);
    primaryStage.setScene(scene);
    primaryStage.show();
}

O método main fica somente com o launch(args), ele é mantido por motivos de compatibilidade, tudo fica no método start. Esse service também só será executado uma vez, se sua intenção for executar periodicamente pode tentar o ScheduledService.

Problemas com Thread em JavaFX


Is a diagonal matrix with "$12$"s along the diagonal an identity matrix?

Question: Is C following an identity matrix?
$$A = \begin{bmatrix}
 2& -1 & 12 \\
 3 & 6 & -9\\
 1& 1& 3
\end{bmatrix}$$
$$B = \begin{bmatrix}
 9 & 5 & -21 \\
 -6 & -2 & 18\\
 -1& -1& 5
\end{bmatrix}$$
$$C = \begin{bmatrix}
 12& 0 & 0 \\
 0 & 12 & 0\\
 0& 0&12
\end{bmatrix}$$
I perform AB and BA and end up with C as the answer. I do know that an identity matrix must consist of only ones and zeros. All the diagonals are 12 and if you pull out 1/12, the identity would remain. Would it alone be considered the identity due the numbers being the same? I'm guessing no but am not sure.
Comment: No, $C$ is a "scalar matrix", that is, a constant multiple of the identity matrix.
Comment: You can easily check for yourself whether $C$ is the identity: check whether the equations $CM=MC=M$ are true for various $3 \times 3$ matrices $M$. The *very meaning* of the identity matrix is that these equations are true for ***all*** $3 \times 3$ matrices $M$, so all you need is one counterexample to know that $C$ is not the identity.
Comment: Geometrically $\lambda I$ is an homothety.
Answer: No $C$ is not an identity matrix.  But this type of matrix is sometimes called a scalar matrix.  See https://byjus.com/maths/scalar-matrix/
Comment: FYI: the provided link is blocked in EU.
Comment: Perhaps those in the EU can do what I did: Google "scalar matrix" and choose one of the references that is not blocked.  That one seems to be an educational site in India.
Answer: In this situation, $C$ is a scalar matrix that is, as you say, $12$ times the identity matrix, i.e. $C = 12I$. This is not the same thing as the identity, but it has some special properties in common with the identity matrix. For example, it commutes with any other $3 \times 3$-matrix, i.e. $CX = XC$ for any $X$.
Also, the fact that $AB = BA = C$ allows you write down the inverse of either $A$ or $B$ with ease:
$$
AB = C
\implies
A\, \bigl( \tfrac{1}{12} B \bigr) = \tfrac{1}{12} C = I,
$$
which shows that
$$
A^{-1} = \tfrac{1}{12} B
= \tfrac{1}{12} \begin{bmatrix}
 9 &  5 & -21 \\
-6 & -2 &  18 \\
-1 & -1 &   5
\end{bmatrix}
= \begin{bmatrix}
 \tfrac{3}{4}  &  \tfrac{5}{12} & -\tfrac{7}{4}  \\
-\tfrac{1}{2}  & -\tfrac{1}{6}  &  \tfrac{3}{2}  \\
-\tfrac{1}{12} & -\tfrac{1}{12} &  \tfrac{5}{12}
\end{bmatrix}.
$$


Performance between while(1) and blocking call

Question: I have a little app that consumes messages from RabbitMQ.
Currently its in a while(1) loop, it calls "Dequeue" and wait there forever for a message and then handles the message.
So i was thinking  is  the blocking call "Dequeue" a good idea or would a immediate DequeueNoWait(nothing there return immediate) not be better or even maybe a "Dequeue" with a timeout. There would of course be much more while iterations.
thanks
Comment: A spin wait should only be used if the expected time to wait is "very short". You're effectively keeping the CPU busy with nothing. In the case where doing this is cheaper than doing a context switch to another thread then it might be a good idea. If you wait for a long time it is not. Without knowing more about your case it is hard to give good advice. Do you have async versions of those methods?
Comment: Unfortunately it does not have async. That would have been very nice.
Comment: @Pintac it is very easy to write an async wrapper. Obviously an I/O thread must be sacrificed. But this is normal/acceptable and common in EDA (Event Driven Architecture, for example node.js). So the idea of an async wrapper is more about programming style and ease of use than performance or resource footprint.
Comment: Yeah if this was a very huge/important part to my system i would have most probably done one but seeing that this is a small maintenance task its really not worth the effort...
Answer: This is a classic problem. The best you can do is use a blocking Dequeue() with timeout so that more than just RabbitMQ messages can be processed. For example:

on Unix/Linux also process system signals such as SIGHUP or SIGINT
on terminal commands also accept user input to break out of the loop with a message "Press ESC to quit..." or something similar
if there are other input streams process those, too, in the same thread

The timeout should be set based on what you expect. For some system signals very strict timeouts are given before the process is blasted out of the water. For a console applications human users will not notice a 150 ms timeout, it will still look near-to-realtime to them.
If you don't block and don't use a timeout the CPU will consume unnecessarily resources to just loop through as fast as possible, without any benefit. Something like this is only advisable when timing is extremely important. But then you wouldn't use RabbitMQ either.

EDIT: more about the timeout

A 1 second timeout does not mean that a message is picked up in 1 second. Messages are still processed instantly, as they arrive. The timeout means that OTHER tasks are performed with at most 1 second delay (mean delay is half the timeout, so 0.5 seconds).
Comment: Yeah i was leaning towards  timeout. An in my case its a maintenance task that nobody looks at and if it takes 1s before a message gets picked up that is alright no rush :-)
Comment: Yip its the most it will wait for a message.


is every polynomial function absolutely continuous?

Question:
Is every polynomial function defined on a closed interval absolutely continuous ?

I think so because of fundamental theorem of calculus.
Comment: Absolutely! :-)
Answer: Yes.

Polynomial functions are $C^1$.
A $C^1$ function on a closed interval is Lipschitz.
Lipschitz functions are absolutely continuous.
Comment: One should emphasize that $C^1$ means *continuously* differentiable, not just *differentiable*, otherwise the second fact would be wrong.


Finding limit of sequence $a_n=\frac{\alpha(n)}{n}$

Question: Given sequence $a_n=\frac{\alpha(n)}{n}$, where $\alpha(n)$=total no. of primes by which $n$ is divisible, find $\lim_{n\to \infty}a_n$.
Example: $\alpha (8)=1$, as $2$ is the only prime by which $8$ is divisible.
Observing that $\alpha(n)\lt n$ for all $n\in \mathbb N$, the given sequence is bounded. Then I tried using the fact that every $n$ has prime factorisation.
But I don't know how to proceed further. Any hints?
Comment: Hint : Fix $k$. What is the smallest $n$ such that $\alpha(n) = k$? Look at $\frac kn$, how does it look for the first few values of $k$?
Comment: It won't give just a lower bound, it will very much give an upper bound, as the below answer illustrates. See, the point is that $\alpha(n)$ is much, much smaller than $n$, and one can quantify that, but I wanted you to see that with your own eyes for the first few values.
Comment: I will explain it. Since we must chat, can you come [here](https://chat.stackexchange.com/rooms/119549/teresa-lisbon-senior-agent-cbi) to understand this?
Comment: I know this has already been answered, but if one is stuck, it can be useful as motivation to see that since $\alpha(n)=1$ infinitely often, the limit must be $0$ if it exists. Then one could focus on trying to prove $\lim a_{n}=0$.
Comment: @TeresaLisbon: I tried with $k=5$ and then I think that $n:\alpha(n)=k$ is $18.104.22.168.11$ but I think that it will give only lower bound (something greater than $0$), which I think will not evaluate the limit.
Comment: @TeresaLisbon: I don't understand the $\log_2n$ part in below answer.
Answer: Hint: You can have a stricter bound than just $n$ for $\alpha(n)$. If every prime factor were a $2$ and repeated prime factors were allowed, then $\alpha(n) = \log_2(n)$, which is an upper bound because other prime factors have to be larger than $2$. Then, an upper bound on the limit is $$\lim_{n \to \infty}\frac{\log_2(n)}{n}$$
Comment: +1. Thanks a lot. That's an amazing solution. But I don't understand how $\alpha(n)=\log_2 (n)$. Clearly this is not true. Perhaps you meant $\alpha(n)\le\log_2 (n)$? And I verified it using Induction. But how did you come up with $\log_2n$? I'll be grateful if you please make me understand that.
Comment: I meant that $\log_2(n)$ is an upper bound, so $\alpha(n) = \log_2(n)$ in the "worst" case.
Answer: I am posting an answer here. I would like to thank @Teresa Lisbon who's helped me a lot to solve this exercise.
Since every natural no. $n$ has a prime factorization, suppose that $n=n_1^{p_1}n_2^{p_2}\cdots n_k^{p_k}$ for prime nos. $n_i$'s where $i\in\{1,2,3,\cdots,k\}$. It follows that $\phi(n)=k$ as for every $i\in\{1,2,3,\cdots,k\}$, we have prime no. $n_i$ such that $n_i|n$.
$\begin{align}
\log_2n &=p_1\log_2n_1+p_2\log_2n_2+\cdots+p_k\log_2n_k\\
        &\ge p_1\log_22+p_2\log_22+\cdots+p_k\log_22\\
        &=p_1+p_2+\cdots+p_k \ge 1+1+\cdots+1 \text{  ($k$ times)}=k\\
\implies &\log_2n\ge k= \phi(n)\\
\implies &0\le\frac{\phi(n)}{n}\le\frac{\log_2n}{n}\end{align}$ $\tag 1$
Since $n^{\frac 1{n}}\to 1$, by continuity of $\log_2n$ we have $\frac{\log_2n}{n}=\log_2(n^{\frac 1{n}})\to \log_2(1)=0$
By squeeze theorem in $(1)$, it follows that $\frac{\phi(n)}{n}\to 0$
Comment: Great! +1. By the way, you need to stick @TeresaLisbon together, otherwise it won't inform me. There was a space between Teresa and Lisbon when you wrote it. You will have to write it without spaces next time. Also, it is madam, you can say Senorita Teresa, I like the ring to that.
Comment: Sure, I'll remember that @TeresaLisbon. I have changed "Sir" to "Madam" in my earlier comment.Thanks a lot Senorita Teresa madam.
Comment: You are welcome!
Comment: @TeresaLisbon: Madam, I have posted my answer here.Thanks a lot for help.


WSI synchronization subpass dependency and link to color attachment output

Question: I think I do understand how Vulkan synchronization works, but I do have a problem of understanding the synchronization with the WSI.
The the Synchronization Examples, we can find this code
/* Only need a dependency coming in to ensure that the first
   layout transition happens at the right time.
   Second external dependency is implied by having a different
   finalLayout and subpass layout. */
VkSubpassDependency dependency = {
    .srcSubpass = VK_SUBPASS_EXTERNAL,
    .dstSubpass = 0,
    // .srcStageMask needs to be a part of pWaitDstStageMask in the WSI semaphore.
    .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
    .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
    .srcAccessMask = 0,
    .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
    .dependencyFlags = 0};

According to me, it should be something like that :
VkSubpassDependency dependency = {
    .srcSubpass = VK_SUBPASS_EXTERNAL,
    .dstSubpass = 0,
    // .srcStageMask needs to be a part of pWaitDstStageMask in the WSI semaphore.
    .srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE,
    .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
    .srcAccessMask = 0,
    .dstAccessMask = 0,
    .dependencyFlags = 0};

Indeed, since we are going to WRITE into the attachment, there is no need to use a WRITE_BIT (meaning make writes available) in the dstAccessMask.
But the true issue is in the srcStageMask.
I understand why the dstStageMask  is COLOR_ATTACHMENT_OUTPUT_BIT. It is because it is okay to have the prior stages working since we don't touch the attachment.
However, for the srcStageMask, I did not see anything about the link between WSI and the COLOR_ATTACHMENT_OUTPUT_BIT. To me, the layout transition must appear at the end of the presentation, and just before the beginning of the COLOR_ATTACHMENT_OUTPUT stage.
And the end of presentation, for me, should be represented by BOTTOM_OF_PIPE and not COLOR_ATTACHMENT_OUTPUT
Where am I mistaken?
Comment: Where does Window System Integration come up in this question? I don't see you creating a display or surface, or manipulating a swapchain in some way. So it's not clear where WSI is involved in this synchronization.
Comment: Yes indeed, my question is not asked correctly. I wanted to say that when you want to use the swapchain image that was presented before, you must use the subpass dependency given in the question to be sure that the layout transition happens at the good time. Else, you can fall in a case that you transition a layout during the presentation, that may lead to an Undefined Behaviour
Answer:
Indeed, since we are going to WRITE into the attachment, there is no need to use a WRITE_BIT (meaning make writes available) in the dstAccessMask.

I am not exactly sure of your logic here. It should be WRITE exactly because we are going to write to the attachment.
It would perhaps help describe what is happening here (from krOoze/Hello_Triangle/doc):

The VkSubpassDependency chains of the the semaphore (via pWaitDstStageMask). Then it performs its layout transition. Then it syncs with the Load Op. (Then Load Op happens in the subpass. And subpass vkDraws some stuff into the swapchain image.)
Now assumably (as is typical for first use of the swapchain image) our Load Op is VK_ATTACHMENT_LOAD_OP_CLEAR. That means VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT access.
So:

Presentation is gonna read the swapchain image, and submit a semaphore signal.
We chain our VkSubpassDependency to the signal (via pWaitDstStageMask). Semaphore signal already covers all memory accesses, therefore our srcAccessMask = 0.
The Dependency performs its implicit dependency to the Layout Transition (takes your src, and invents some internal dst), then Layout Transition happens, which reads the image and writes it back, then the dependency performs another implicit Dependency (invents some src that covers the layout transition, and uses your dst).
The Load Op happens in the subpass, and you have to make sure explicitly it happens-after everything above. So your dst in your Dependency must be VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT to cover the Load Op.

Now, there are three types of memory hazards: read→write, write→write, and write→read (and read→read is a non-hazard). In WWH something writes a resource, while some other write also writes it. It is not clear which write happens last, so the memory contents becomes garbage. In RWH and WRH read and write may happen at the same time. It is not clear if the read sees the unmodified memory, or the written one (i.e. it reads garbage).
Without an explicit dependency, the Layout Transition and the subsequent Load Op form a write→write hazard. Therefore dstAccessMask must not be 0 to resolve the hazard and make sure one write happens-before the second one.
(It is perhaps worth noting we introduce the VkSubpassDependency solely for the sake of the layout transition. Otherwise the semaphore wait would already be all that is needed. The default is srcStageMask = TOP_OF_PIPE, which means without explicit Dependency the layout transition could happen before the semaphore wait, i.e. before presentation finishes reading it; that would be a read→write hazard).

To me, the layout transition must appear at the end of the presentation, and just before the beginning of the COLOR_ATTACHMENT_OUTPUT stage. And the end of presentation, for me, should be represented by BOTTOM_OF_PIPE and not COLOR_ATTACHMENT_OUTPUT

We have little bit of choice here: pWaitDstStageMask = dependency.srcStageMask = ?
Now our situation is this:
vkBeginCommandBuffer();
[possibly vkCmdDispatch()?]
vkBeginRenderPass();
vkCmdDraw(); // does vertex shading + fragment shading, then color writes
vkEndRenderPass();
vkEndCommandBuffer();

vkQueueSubmit(.pwaitDstStageMask = ?);

If we use VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, then the semaphore wait does not block starting the hypothetical vkCmdDispatch() (VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT). And the Subpass Dependency src does not force it to finish neither. Great!
The Stage used should not be any earlier stage than VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT. E.g. with VK_PIPELINE_STAGE_ALL_COMMANDS the semaphore wait would unnecesserily block the vkCmdDispatch() as well as vertex and fragment shader of the vkCmdDraw. Meanwhile we need the swapchain image only when we actually need to write it at the Load Op (which you can imagine happens when the vkCmdDraw() gets to the point it needs to perform color writes).
Now, we could choose VK_PIPELINE_STAGE_BOTTOM_OF_PIPE. The semaphore blocks nothing (dstStage\pWaitDstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE means the same as "nothing"). Great! But the Subpass Dependency now blocks everything (srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE means the same as VK_PIPELINE_STAGE_ALL_COMMANDS). That means our vkCmdDispatch has to finish, before our subpass starts. Not so great...
So, the best practice is to use pWaitDstStageMask = dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT.
Comment: @AntoineMorrier If `pWaitStage=COLOR_ATTACHMENT` and `srcStage = TOP_OF_PIPE` that means the semaphore waits in `COLOR_ATTACHMENT`, but the layout transition could start at arbitrary point (e.g. even before the semaphore signals, and so when PE still reads the swapchain image). That means you have a read→write hazard. (BTW, your first comment got snipped or something.). My `srcStage` does not refer to dispatch. Actually it tries to avoid it. If the dispatch wasn't there, `srcStage` could be `BOTTOM_OF_PIPE`. But no reason to do that if there is a better way that works in all situations.
Comment: Okay, I understand for the first part. I thought WRITE_BIT only means "flush cache" and I did not think about reordering... Thanks for the explanation.

For the srcStage, I begin to understand, but there is something not clear. Why does the srcStage must be the same as the pWaitStage...

Let's say we do not have a vkCmdDispatch, why shouldn't we use `COLOR_ATTACHMENT` for pWaitStage, `COLOR_ATTACHMENT` for the dstStage and `TOP_OF_PIPE` for srcStage.

Since dstStage means here the COLOR_ATTACHMENT_WRITE for the renderPass.

The srcStage here refers to the presentation... So the issue..
Comment: I mean, the srcStage, In your case refers to the dispatch, but, in my case, it does not refers to anything (or the presentation). , so why we must use the same as the pWaitStage...
Comment: I understand the issue. So, in a simple case, the `srcStage` does not refer necessarly to a prior cmd... It can refers to a next stage... I think it is this part that I don't understand...
dstStage refers to the stage within the renderPass. But srcStage refers to what here...

To me, if you put TOP_OF_PIPE in srcStage, but COLOR_ATTACHMENT in dstStage, it means that the layout transition will not begin before the renderPass reached the dstStage without caring about what happen before the srcStage...
Comment: before the renderpass wanted say*
Comment: `srcStage` refers to any queue operation in the queue earlier in a submission order limited to that stage. Yes, that is exactly what `TOP_OF_PIPE` means. Except we do care what happens before. We must explicitly make sure that the Presentation Engine stops reading the swapchain image, before the Layout Transition rewrites the image. So we must ensure our semaphore wait happens-before the layout transition starts.
Comment: Yes, I do understand that, but I think I have a mis understanding . Simply put, you said `srcStage` refers to the prior draw call. My pipeline is like this :
drawCall -> presentation -> drawCall. In the second drawCall, the `srcStage`, to me will refer to the firstDraw call, and not to the presentation, however, the semaphore will be signaled when the presentation is over. I do understand that you must not transition your image BEFORE the presentation finished. Again, to me, in such a case, `dstStage` and `pWaitStage`, since they are equal to COLOR_ATTACHMENT... will refer to the same stage.
Comment: However, I do not understand why `srcStage` , if you make it equal to `COLOR_ATTACHMENT` too, will refers to the same stage as `pWaitStage` and `dstStage`...
I think I understand why `TOP_OF_PIPE` is not enough.
But I don't understand why `srcStage`, since, to me, it refers to the firstDrawCall, it will be helpful... Maybe it is because we put the same value as in `pWaitStage` ?
Comment: `dstStage` has nothing to do with it; that is already too late; transiton happens-before it. A Layout Transition (which is a R\W access) is defined to happen-between `src` and `dst` sync scopes of the Dependency. We want to enforce order presenting→(signal→wait→)transition→subpass. Only way to force presenting to happen-before transition is to form an Execution Dependency Chain. To do that the stage bits in `pWaitDstStageMask` must be a non-zero intersection with stages in `srcStage`.
Comment: Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/212149/discussion-between-antoine-morrier-and-krooze).


Adding a dataset to rdlc file

Question: Scenario:
I have an RDLC file - TestReport.rdlc
I have a form - Form1.cs
I have a ReportViewer - rptViewer
My datasource for the report will be an XML file or a datatable defined at run time (in button click event). Now when I am in design mode for the report how do I add the DataSource or DataSet to the report so I can "add" the columns/fields into the report?
Right now in the report when I click New -> DataSet I am asked to pick from Database, Service, Object or SharePoint but I want to use an object which exists in memory.
I am using VS2012.
Thanks,
Andrew
Answer: In case of XML, you have to create the schema for it and then add it to the report in the design view.
A little example is exaplained in this blog (it's old but still good to understand what you have to do).
If also the XML's schema is dynamic, the only solution I came out is about to create one paramater for each node/attribute of your XML and build one or more .rdlc files for every type of XML

Adding a dataset to rdlc file


Networking / Multipath dropping

Question: I'm having problem with few linux boxes running xen. They are acting as hypervisors and they are connected to SAN using multipath setup to provide storage to guest vms.
Every now and then one of two paths fails but it can be quickly restored by running:
multipath
multipath -ll

I need to get to the bottom of the issue and find out why this is happening. I have noticed that this doesn't occur when the hypervisor is not too busy (network and I/O wise). I have also eliminated possible hardware problem by moving all the services on to identical new chassis. I have collected few system logs which may indicate NIC module issue or kernel problem and failing multipath might be only a result of this!!?? Here is a bit of log which always shows up when multipath goes down:
kernel: BUG: soft lockup - CPU#0 stuck for 60s! [swapper:0]
kernel: BUG: soft lockup - CPU#2 stuck for 60s! [events/2:76]

I'll paste full logs at the end of this post to keep it easy to read. Now a little bit more about my setup:

Internet access is setup over eth0 and eth2 (bonded)
SAN multipath access is setup over eth1 and eth3

Server:

Supermicro SuperServer 6016T-NTRF
Intel(R) Xeon(R) CPU E5645
Intel Corporation 82576 Gigabit Network
CentOS release 5.7 (Final) 2.6.18-274.18.1.el5xen
filename:       /lib/modules/2.6.18-274.18.1.el5xen/kernel/drivers/net/igb/igb.ko
version:        3.0.6-k2-1
Log 01
Log 02

If anyone needs more details please get it touch. Any help will be much appreciated.
Comment: Try dedicating one cpu for `dom0`
Answer: Since this appears to be an iSCSI setup, there are a couple of areas where path failovers can occur.

Simple Ethernet flakiness. A packet got dropped, which triggered the failover to the other path rather than wait for retransmit and reassembly.
Less simple Ethernet problems. A switch-port flipped briefly, triggering a failover.
Something in the Multipath stack triggered a failover. Multipath is more sensitive to network oddities than regular ole TCP/IP, so won't wait as long to reestablish connections; it'll fail over instead.
Something in the network stack went wrong. There are a few possibilities here, but from the looks of your error message this is likely the problem.

Multipath setups are very sensitive to latency on the wire, and iSCSI + Ethernet is going to have more of that than a Fibre Channel environment. Some flapping is going to be normal.
As this seems to happen when the HVM is busy, this suggests that the kernel NIC paths are getting either congested with data or starved for CPU (possibly both), which is triggering multipath failover. There isn't a lot you can do about that, but you can narrow things down so you can better explain why it is doing what it is doing.
Server load is pretty easy, and sounds like you've already done that.
Diagnosing congestion is harder. If your network port bandwidth monitors aren't showing a lot of traffic, but the log entries you posted happen anyway, that is a sign that the server is clogging up internally. If you can actually grab a packet capture during one of these events, the time-stamped packet counts will tell you if it really is seeing 10 second gaps in passed traffic; a sure sign that the server is internally clogged.
Fixing the problem is likely to be driver-specific, with a possibility of some tuning of the TCP/IP stack tuneables.

Networking / Multipath dropping


How to set _optimizer_search_limit and _optimizer_max_permutations in Oracle10g

Question: I am working on a product that must support both MSSQL and Oracle (10g and 11g).  I have some very complex queries that seem to run without issue on MSSQL 2005/2008, but very, very slow with Oracle.  The CPU on the oracle server skyrockets for long periods of time, and it seems like the optimizer may be trying to find the best execution plan for the very complex query.  I did some Googling to figure out how to limit the amount of time the optimizer spends on this, and came up with _optimizer_search_limit and _optimizer_max_permutations.  Both of these parameters are hidden in Oracle 10g, and setting them in init.ora doesn't seem to make any difference.
How do I set these parameters in Oracle.
Or am I just totally barking up the wrong tree with the assumption that the optimizer is spending several minutes finding an execution plan?
Thanks.
Comment: `explain plan for your-precious-sql-statement;` see if running explian takes several minutes
Comment: Thanks.  I just tried this on a query that returns in a few seconds when using MSSQL and takes 2 hours with oracle.  The CPU on the server shoots to 100%, and it's been 15 minutes now with no execution plan returned.
Comment: You might want to move this question to http://dba.stackexchange.com/
Answer: Never heard of a query taking 15 minutes to optimize.
First, I'd be checking the alert log. There may be some block corruption on a system table that is causing an issue.
Second, do you have stats gathered for all the tables being queried. 10g introduced dynamic sampling, by which the database will go look at the table for some stats if there are none in the data dictionary. If you have lots of very large tables, then gathering stats dynamically could be slow.
You can see if you've got (recent) stats with this
<code>select table_name, last_analyzed from user_tables
</code>
If you are dealing with complex queries on large tables, then you should take some time to plan a stats gathering strategy.
Answer: That sounds like a bug that could have been solved by now.
How many tables in the join?
You could do 10053 trace to figure out what's going on with CBO.

ALTER SESSION SET TIMED_STATISTICS = TRUE;
ALTER SESSION SET MAX_DUMP_FILE_SIZE = '2048M';
ALTER SESSION SET SQL_TRACE = TRUE;
ALTER SESSION SET tracefile_identifier = trace1_10053;
ALTER SESSION SET EVENTS '10053 TRACE NAME CONTEXT FOREVER, LEVEL 1';

and then look in the trace file to check if your theory of CBO being stuck is valid. 12c has a limit of just 2000 _optimizer_max_permutations so it doesn't take a lot of time. In 10g-11g it used to be around 60k I believe.


Whats the best way to setup & populate my nstableview with json data?

Question: I'm sorry if this has already been answered. I'm a bit of a noob. From all the examples I've found I can't seem to work this out.
I'm building a mac osx application using Xcode 5. My interface that I've created in Interface builder has three tableviews. My data to populate these views is json format and it is being received successfully using NSURLConnection.
What is the best way to popular the tableviews? A lot of the tutorials I've followed use an arraycontroller that is dragged and dropped using IB. From what I understand I don't need an array controller and need to hand code controllers for each of tableviews. Is that correct? If so, please explain how I go about this and setup the bindings.
Also, when clicking on a column in tableview 1 I'm planning on making it adjust the data in tableview 2 & 3 so if that impacts anything please let me know.
Thanks in advance!
Update 6 Jan
Here is my code currently..
ContactsTableViewController.h
<code>#import <Foundation/Foundation.h>

@interface ContactsTableViewController : NSObject <NSTableViewDataSource, NSTableViewDelegate> {
    IBOutlet NSTableView *contactsTableView;
}

-(id) init;

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView;

-(NSView *) tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;

@end
</code>
ContactsTableViewController.m
<code>#import "ContactsTableViewController.h"

@implementation ContactsTableViewController

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
    NSLog(@"numberOfRowsInTableView called");
    return 1;
}

- (id) init {
    NSLog(@"init called");

    [contactsTableView setDelegate:self];
    [contactsTableView setDataSource:self];

    [contactsTableView reloadData];

    return self;
}

- (void) initme {
    NSLog(@"customfunc");
}

-(NSView *) tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {

    NSLog(@"viewForTableColumn called");

    NSTextField *result = [tableView makeViewWithIdentifier:@"name" owner:self];// result is now guaranteed to be valid,

    result.stringValue = @"My Name"; //[self.nameArray objectAtIndex:row];

    return result;

}

@end
</code>
In my appDelegate:
<code>- (void) awakeFromNib {
    NSLog(@"AWAKE");

    ContactsTableViewController *contactsController = [[ContactsTableViewController alloc] init];
}
</code>
Currently nothing is showing in the tableview and numberOfRowsInTableView & viewForTableColumn aren't getting called.
Answer: Look at the UITableViewDataSource, you need to implement the protocol in one of your classes, probable your view controller, implement the UITableViewDelegate to get row selection events in the same class.


Probability of radioactive decay

Question: It is given that the probability that one among two radioactive atoms will decay in an interval $x,x+dx$ and another one will decay in a time interval $y+dy$ is given by the following expression:
$$Ne^{-y\alpha-x\beta-\gamma\sqrt{xy}}dydx$$
where $\alpha, \beta>0$, and $\gamma~\epsilon~R$.
What would be the normalization factor, $N$ of the probability density function in the analytical form when it is defined only in the first quadrant?
Also, how do I numerically calculate the approx. probability that one of them decays prior to the other?
(Please do show me how to solve the integral)
Answer: N must be such that the integral, taking x and y each from 0 to infinity is 1.  In other words, integrate $e^{-y\alpha- x\beta- \gamma\sqrt{xy}}dydx$ from with x and y from 0 to infinity, $\int_0^\infty\int_0^\infty e^{-y\alpha- x\beta- \gamma\sqrt{xy}}dydx$, and N is 1 over that.  The probability that the second atom decays before the first is the integral with x going from 0 to infinity and y from 0 to x: $N\int_0^\infty\int_0^x e^{-y\alpha- x\beta- \gamma\sqrt{xy}}dydx$
Comment: Thanks for the answer! Although I knew the method of solving, I was unsuccessful in obtaining a definite answer. Also, how can I determine the expected value and standard deviation of decay time for both atoms in analytical form?

Probability of radioactive decay


Are some scales more instinctive than others?

Question: Thanks to this answer here, I now know the commonly accepted definition of a scale.
However, from my experience, not all scales feel instinctive. For instance, I think major and minor scales feel more instinctive than chromatic ones. This is actually an interesting distinction because I personally prefer major scales to minor ones, yet I feel they are both very instinctive. I also feel that microtonal scales are less instinctive than chromatic ones.
This answer seems to touch on this a bit. But that particular thread is more about "why seven notes in the major/minor scale?" as opposed to "can we rank scales by how". For instance, if microtonal scales were equally pleasing as the normal major scale, then that answer wouldn't make sense if I understand it correctly. So I think it might be possible to rank scales by how instinctive or natural or pleasing they are. I will use these terms interchangeably unless someone convinces me otherwise.
My Question:
What studies have been done to measure the instinctiveness of scales?
I cannot provide a definition of instinctive at the moment, but I would argue the second answer cited in my question has something close to what I am thinking of.
Comment: While this is an interesting question, it is probably not good here, as there is probably no scale that is more instinctive to everyone - it is entirely down to culture and upbringing. I'll not close just now, will watch the question and see if it needs it
Comment: I've forced myself to learn diminished scales, whole tone scales and other scale patterns, e.g. nine-note scales like this: C C# D# E F G G# A B

When I started practising them they felt really awkward and unfamiliar, but this has gone away with practice. So the distinction I'd make is between familiar (i.e. practised) and unfamiliar, rather than with instinctive and non-instinctive.
Comment: Do you define "instinctiveness" as sounding "good/right"?  (Assuming you are basing this off of the second answer you have cited)
Comment: Sure. I tried to find something to provide a definition, but I admit the answer I provided, at least for me, isn't a very strong definition.
Comment: OK, an interesting question.  I wonder what methods could be used to measure this.
Comment: I guess, *instinctive* is the wrong word: since Eastern and Western music have this huge differences, I don't assume any genetic dependency, but more one acquired from the environment. At least the German Wikipedia article defines physiological predisposition and independence from culture as necessary conitions for a human instinct.
Comment: @DrMayhem can you support your claim with evidence? If it is true, then that answers my question.
Comment: We already have quite a lot of posts on this topic, and Tim's answer here says it all. It is well documented in the industry - which is why there is no ubiquitous "sad" key or "happy" key, for example.
Answer: Nurture/nature. I feel that because in the Western world, most of what we listen to is major or minor, over time we've accepted this - it's become 'instinctive'. It would be different if one had listened to, say, Indian music for a long time. Then that would seem 'instinctive'. It's far more nurture than nature, if a loose definition of 'instinctive' is 'natural'. 400, 500 years ago, I doubt whether the stuff we now listen to would have been deemed 'instinctive'.
Comment: Do you have any references with scientific research to support this point of view?  More specifically, if no scales are innate / instinctive, fine. But what research that has proven this? I am not for or against this hypothesis. I just want evidence.
Comment: There is a vast amount of practical evidence "out there" that scales are not innate, if you don't restrict yourself to western music and 12-tone equal temperament tuning. Even in western music, 12TET was little more than a theoretical idea for most of the past 1000 years (i.e. the time-span where there are written records that can be interpreted reasonably unambiguously, as well as the evidence from historical instruments)
Answer: Back in the early days of Church canon, the third was a decidedly "outside"  note.  It occurred here and there, but it was by no means afforded the status we give it today.  It didn't sound "instinctive."
The only sounds/tones that are "instinctive" are the species danger sounds:  those sounds that alert us that something higher than us on the food chain is nearby;  those sounds that alert us that large rocks are in motion on the hillside above us;  those sounds that alert us that danger is near.
Nothing about the pleasantness or goodness/correctness of musical scales is "instictive."  It's all learned.  Bifurcated constructs such as consonance/dissonance are learned.
This is one of the major reasons why a "universal" theory of music has not emerged, despite the intense efforts over hundreds of years of a lot of brilliant musicians and philosophers to try to produce one.
Comment: Absolutely! The blue notes were unacceptable even 100 years ago. Including  the Devil's interval - b5. Now, we think they're great!
Comment: Unacceptable to whom?
Comment: Don't think many composers used the intervals, can't find examples of their use. Masters of the king's musik wouldn't dare.
Comment: They went out of fashion for a while, but J S Bach wasn't scared of the devil. Look at the end of BVW 715 - allegedly one of the causes of the authorities at Arnstadt  complaining of his "having hitherto made many curious variations in the chorales and mingled many strange notes in them, with the result that the congregation has been confused". Half a dozen consecutive chords with tritones near the end - and plenty of other "strange notes" besides.
Comment: The (lack of) use of the third in the early days of the Church was probably caused by an arbitrary decision by the Powers That Be, who decreed that "the interval of a third shall be two whole tones", i.e., a frequency ratio of 81:64 compared with a "pure" third of 5:4 or 80:64. That is horribly sharp to be useful harmonically, even to modern western ears which have learned to think that equal-temperament thirds (about 80.6 : 64) are "in tune".
Answer: Certain interval patterns do turn up in scale repositories more often than others; easy ones are perfect fifths, though as others have pointed out, this may be due to cultural training on what is appropriate, not instinct. A full analysis might start with the scale archive at:
http://www.huygens-fokker.org/scala/
(though note some of those are constructed or academic scales, so you'd need to filter for the "cultural" ones) and then plot which intervals turn up the most often.


How to implement a weight map for a U-Net

Question: I have a question regarding the convolutional neural network known as U-Net (see link below) and hope somebody can help me out.
https://lmb.informatik.uni-freiburg.de/people/ronneber/u-net/
In the paper, the authors mention a map with a pixel-wise loss weight to force the network to learn the border pixels. I assume this weight map is intended to initialize the weights but I have failed to find the code showing how these weight maps are used to initialize the weights of the U-Net. I am not familiar with Caffe and instead use Keras to implement the U-Net. My current code is partially based on https://github.com/zhixuhao/unet. In this implementation, no pre-computed weight map is included
Can somebody please point out to me how this weight map described in the paper was used to initialize the weights of the U-Net?
Any Help would be greatly appreciated!
Comment: While maybe a bit programming-heavy, imho still a reasonable question. See answer here: https://stats.stackexchange.com/a/577528/342937
Answer: The weight map is not related to the network weights but to the sample weights: during the training, you feed three pieces of information to the network, 1) the pixel intensities, 2) the pixel labels, 3) the pixel weights.
The loss function used is simply weighted cross entropy.
Comment: Thanks for your reply. But how are these pixel weights passed into the network? I was not able to find out how to pass in pixel weights into a Keras implemented ConvNet?
Comment: Probably along with the labels blob. Also, I don't know if Keras implements a weighted cross entropy directly, maybe you will have to implement it yourself [like this](https://stats.stackexchange.com/a/326020/163572)
Comment: What do you mean by the sample weights @JanKukacka?
Comment: weights of individual pixels (= samples)