Predictions after SMC

Question: I have a statistical model given by
$$
y_t\sim p(y_t|x_t, \theta)\\
x_t\sim p(x_t|x_{t-1},\theta)\\
\theta\sim p(\theta)
$$
where $y$ is the only observed component. Using a sequential Monte Carlo algorithm, I can obtain
$$
\{x_{1:T}^i, \, W_T^i\}_{i=1}^N,
$$
where the target density of the SMC algorithm is $p(x_{1:T}|y_{1:T})$ (i.e. without $\theta$).
My question is: if I want draws from the predictive distribution $p(y_{T+1:T+h}|y_{1:T})$, would the following procedure be correct:

Resample $x_{1:T}^i$ using multinomial sampling with probabilities $\propto W_T^i$ to obtain $\tilde{x}_{1:T}^i$
For each $i=1, \dots, N$, generate $\theta^i \sim p(\theta|\tilde{x}_{1:T}^i, y_{1:T})$
Generate the predictions $y_{T+1:T+h}^i\sim p(y_{T+1:T+h}|y_{1:T},\tilde{x}_{1:T}^i, \theta^i)$

The resulting array $\{y_{T+1:T+h}^i\}_{i=1}^N$ would then represent a draw from
$$
p(y_{T+1:T+h}|x_{1:T}, y_{1:T}, \theta)p(\theta|x_{1:T}, y_{1:T})p(x_{1:T}|y_{1:T})
$$
so I think it checks out. My main concern is the initial resampling, but I feel that would be necessary in order to get rid of the unequal weights. Is this the appropriate way to do it? Any other ways that might be better (in some respect)?
Comment: SMC targets a distribution that's conditional on knowing the parameter
Comment: @Taylor Yes, that is of course the canonical case. For my situation, however, there exists an algorithm that marginalizes over the parameters. See here: https://www.dropbox.com/s/9gbrk835gkfq07f/bognanni%20zito%202019%20smc%20seq%20varsv.pdf
Comment: yes you're correct, my apologies. Looks like they're using the resample-move approach
Comment: @Taylor Do you havs any thoughts on the suggested approach? An alternative, more general question would be if people ever do a final resampling step. Without it, plotting, for example, of the distribution of the latent variables doesn't make much sense I guess.
Comment: it's hard to know what you mean by appropriate, but it doesn't look like a terrible idea at first glance. Also, full disclosure, I have not read the paper carefully. There are many ways to resample, but multinomial-style is the most popular. And you're correct about the other thing: you can't really turn weighted samples into unweighted ones without (re-)sampling.
Answer: Yes, this would be correct. One justification would be the following. Let $\hat{Z}_T$ be the standard estimator of $p(y_{1:T})$ which is generated by the particle filter. Then, the set $\left( \{x_{1:T}^i, \, W_T^i\}_{i=1}^N, \hat{Z}_T \right)$ is "properly-weighted" for $p(x_{1:T}|y_{1:T})$ in the following sense: Let $\textbf{PF}(\{x_{1:T}^i, \, W_T^i\}_{i=1}^N)$ be the joint law of your particle system at time $T$. Proper weighting is the statement that for all sufficiently nice functions $g$, it holds that
\begin{align}
\mathbf{E} \left[ \hat{Z}_T \cdot \sum_{i = 1}^N W_T^i \, g (x_{1:T}^i) \right] = p(y_{1:T}) \cdot \int p(x_{1:T} | y_{1:T} ) \, g(x_{1:T}) dx_{1:T}.
\end{align}
Proving the correctness of your approach could be established by writing down the joint distribution of your predictive scheme as
\begin{align}
\Pi \left( \{x_{1:T}^i, \, W_T^i\}_{i=1}^N, k, \theta, y_{T+1:T+h} \right) &= \textbf{PF}(\{x_{1:T}^i, \, W_T^i\}_{i=1}^N) \\
&\cdot W_T^k \cdot p(\theta|x_{1:T}^k, y_{1:T}) \\
&\cdot p(y_{T+1:T+h}|x_{1:T}^k, y_{1:T}, \theta)
\end{align}
where $k$ is the index of the "selected particle". You can then use the proper weighting formulation to check that, under the joint law of $\Pi$, it holds for any $G$ that
\begin{align}
&\mathbf{E}_\Pi \left[ \hat{Z}_T \cdot G (x_{1:T}^k, \theta, y_{T+1:T+h}) \right] \\
= \, &p(y_{1:T}) \cdot \int p(x_{1:T}, \theta, y_{T+1:T+h} | y_{1:T} ) \, G (x_{1:T}, \theta, y_{T+1:T+h}) \, dx_{1:T} d\theta dy_{T+1:T+h},
\end{align}
i.e. that your proposed method is properly-weighted and hence appropriate for prediction purposes.

Predictions after SMC


linux + snmp + how to verify snmp.conf

Question: in my redhat linux machine I have the follwing snmp configuration
more /etc/snmp/snmpd.conf
#dlmod cmaX /usr/lib64/libcmaX64.so
rocommunity ttt 127.0.0.1

syscontact email@example.com

rocommunity ttt darapp01.pl.corp
rocommunity ttt  darapp02.pl.corp

syslocation UNKNOWN
trapcommunity ttt
trapsink  plice01.il.pl.corp ttt

.
so my target is to verify that snmp.conf configured right and snmp basic sanity as well
I just googled to see what command can check the current  snmp configuration
and I find this:
  snmpwalk -v 2c -c   ttt -O e 127.0.0.1|more
  SNMPv2-MIB::sysDescr.0 = STRING: Linux machine01
  DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (560475) 1:33:24.75
  SNMPv2-MIB::sysContact.0 = STRING: email@example.com
  SNMPv2-MIB::sysName.0 = STRING: machine01
  SNMPv2-MIB::sysLocation.0 = STRING: UNKNOWN

.
.
.
there are a lot of details from the command output
but not understand what actually need to capture from the output in order to be sure that my snmp.conf is OK
second question - what is the string rshedona from the file?
Answer: your snmpd.conf works because snmpwalk return a result.
The string rshedona is the name of the community you have chose.
rocommunity rshedona 127.0.0.1
...
rocommunity rshedona darapp01.pl.corp
rocommunity rshedona  darapp02.pl.corp

and is the string you have writen in the command snmpwalk :
  snmpwalk -v 2c -c   rshedona -O e 127.0.0.1|more

-v is the version of snmp -c the community -O the output options
By default, snmpwalk return the result of  the system MIB.

linux + snmp + how to verify snmp.conf


Typed logic vs many-sorted logic

Question: I am confused as to what is the difference between many-sorted logic and typed logic.
Are they the same thing? If not, what are the differences?
Answer: Many-sorted first-order logic is exactly the same thing as first-order logic over a simple type theory without any type constructors. You may want to look into the first four chapters Jacobs' book Categorical logic and type theory to see how it plays out exactly.
Chapter 4 of that book describes predicate logic over simple type theory, and when you remove all the simple type constructors then you arguably get exactly many-sorted first-order logic. The only difference is maybe one of presentation. In the type theoretical version formulas with free variables will always appear together with a context $x:A,y:B,...$ which declares the sorts of the variables. In other presentations it might be that you have a different stock of variables for each sort, so that they do not have to be explicitly declared. The deductive system in Jacobs book is a sequent calculus. Classical logic books typically use an axiomatic system, or maybe natural deduction. But the theorems which you can prove are the same.

Typed logic vs many-sorted logic


Show that a subspace of a totally disconnected space is also totally disconnected.

Question: The question is:
Show that a subspace of a totally disconnected space is also totally disconnected.
Definition:
A topological space $X$ is totally disconnected if for any two distinct points $x,y \in X,$ there is a separation $X = U \cup V$ of $X$ with $x \in U $ and $y \in V.$
Definition:
A separation of a space is a cts. function $f: X \rightarrow \{0,1\}$ with $\{0,1\}$ has the discrete topology.
In terms of open sets, a separation of $X$ is an expression $X = U \cup V$ where $U \cap V = \emptyset $ and $U,V$ are both open in $X.$
My questions are:
1- How to prove this statement ?
2- What is the difference between a Hausdoff space and a totally disconnected space?
Could anyone help me answer these questions please?
Comment: What happens if you assume you can find a subspace of a totally disconnected space that isn't itself totally disconnected?
Answer: Let $Y \subseteq X$ and let $y_1, y_2$ be distinct points of $Y$. As these are distinct points of $X$, $X=U \cup V$ with $y_1 \in U, y_2 \in V$ and $U,V$ open and disjoint. But then $U'=U \cap Y$ and $V' = V \cap Y$ are open in $Y$ with the same properties.
For Hausdorff spaces we only know $U \cap V = \emptyset$ but nothing about their union. There are many connected Hausdorff spaces, like $\Bbb R$ and $[0,1]$ etc. But totally disconnected implies both disconnected and Hausdorff. It's a heavier condition. Examples include zero-dimensional spaces like $\Bbb Q$ and the irrationals, and the Cantor set.
The usual definition of $X$ being totally disconnected is that all subspaces of $X$ of size $>1$ are disconnected. This seems like a weaker condition than the one you use. It's clearly implied by it, though.
Answer: Suppose that $X$ totally disconnected and that $Y\subset X$. Take $x,y\in Y$ (with $x\neq y$). Since $X$ is totally disconnected, there is a seperation of $X=U\cup V$, with $x\in U$ and $y\in V$. But then $Y=(U\cap Y)\cup(V\cap Y)$ is a separation of $Y$, $x\in U\cap Y$, and $y\in V\cap Y$.
Note that Hausdorff means that for any two distinct elements $x$ and $y$ of $X$, there are open disjoint subsets $U$ and $V$ of $X$ such that $x\in U$ and $y\in V$. Nothing is said about $U\cup V$. Being totally disconnected means that you can write $X$ as the union of two open subsets $U$ and $V$ of $X$ with $x\in U$ and $y\in V$. It's a much stronger condition.


Centos 5.4 wont boot

Question: I have three disks in a centos server but it won boot,I have no grub at all.I tried to install grub with super grub and fix the system with rescatux but in vain.Is there a way to boot into centos?Here is the report
<code>============================= Boot Info Summary: ===============================

 => install-mbr/Testdisk is installed in the MBR of /dev/sda.
 => Lilo is installed in the MBR of /dev/sdb.
 => Grub2 (v1.97-1.98) is installed in the MBR of /dev/sdc and looks at sector
    1 of the same hard drive for core.img. core.img is at this location and
    looks for (md/0)/boot/grub on this drive.
 => Syslinux MBR (5.00 and higher) is installed in the MBR of /dev/sdd.

sda1: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info:
    Operating System:
    Boot files:

sda2: __________________________________________________________________________

    File system:       swap
    Boot sector type:  Unknown
    Boot sector info:

sda3: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info:
    Operating System:  CentOS release 5.3 (Final)
    Boot files:        /etc/fstab

sdb1: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info:
    Operating System:
    Boot files:

sdb2: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info:
    Operating System:
    Boot files:

sdb3: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info:
    Operating System:
    Boot files:

sdc1: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info:
    Operating System:
    Boot files:

sdc2: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info:
    Operating System:
    Boot files:

sdc3: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info:
    Operating System:
    Boot files:

sdd1: __________________________________________________________________________

    File system:       vfat
    Boot sector type:  SYSLINUX 6.03 2014-10-06................................................2....0............A20 gate n
    Boot sector info:  Syslinux looks at sector 32832 of /dev/sdd1 for its
                       second stage. SYSLINUX is installed in the /multiboot
                       directory. No errors found in the Boot Parameter Block.
    Operating System:
    Boot files:        /multiboot/rescatux-0.40b11/efi/boot/bootia32.efi
                       /multiboot/rescatux-0.40b11/efi/boot/bootx64.efi

============================ Drive/Partition Info: =============================

Drive: sda
</code>
Comment: CentOS 5 reaches end of life this quarter, and this particular server hasn't had updates for almost a decade. You're better off to just build a new server on a currently supported OS and migrate the application. Then make sure someone is actually doing regular maintenance on it.
Comment: Try to choose the second disk as first for boot in BIOS settings.
Answer: You can try the rescue mode on a CentOS installation disk.
https://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-rescuemode-boot.html
Comment: I tried it but it does not work
Comment: It helps when you add the results of this tests in your question...

Centos 5.4 wont boot


Android app terminates after certain time when minimized

Question: I have this app which parses SMS and then converts them into Audio. My app users usually minimize the app and runs it all the time. But my app is getting terminated after sometime. How can i make sure my app will run till a user "terminates" it. Since the core functionality of the app is to convert SMS to audio, i need it running all the time.How can i do this ?
My current MainActivity.java
<code>public class MainActivity extends AppCompatActivity {

    TextView txtGateway, txtTime, txtAmount;
    Speakerbox speakerbox;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //textView = findViewById(R.id.txt_message);
        speakerbox = new Speakerbox(getApplication());
        txtAmount = findViewById(R.id.tv_amount);
        txtGateway = findViewById(R.id.tv_gateway);
        txtTime = findViewById(R.id.tv_time);
        requestSmsPermission();

    }

    @Override
    public void onResume() {
        LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter("otp"));
        super.onResume();
    }
    @Override
    public void onPause() {
        LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter("otp"));
        super.onPause();
    }
    private BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equalsIgnoreCase("otp")) {
                final String message = intent.getStringExtra("message");
                String gateway = intent.getStringExtra("gateway");
                String time = intent.getStringExtra("time");
                String amount = intent.getStringExtra("amount");
                speakerbox.play(message);
                txtGateway.setText(gateway);
                txtTime.setText(time);
                txtAmount.setText(amount);

                // message is the fetching OTP
            }
        }
    };

    /**
     * Requesting multiple permissions (storage and location) at once
     * This uses multiple permission model from dexter
     * On permanent denial opens settings dialog
     */
    private void requestSmsPermission() {
        Dexter.withActivity(this)
                .withPermissions(
                        Manifest.permission.RECEIVE_SMS,
                        Manifest.permission.READ_SMS,
                        Manifest.permission.SEND_SMS,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .withListener(new MultiplePermissionsListener() {
                    @Override
                    public void onPermissionsChecked(MultiplePermissionsReport report) {
                        // check if all permissions are granted
                        if (report.areAllPermissionsGranted()) {
                            //  Toast.makeText(getApplicationContext(), "All permissions are granted!", Toast.LENGTH_SHORT).show();
                        }

                        // check for permanent denial of any permission
                        if (report.isAnyPermissionPermanentlyDenied()) {
                            // show alert dialog navigating to Settings
                            showSettingsDialog();
                        }
                    }

                    @Override
                    public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
                        token.continuePermissionRequest();
                    }
                }).
                withErrorListener(new PermissionRequestErrorListener() {
                    @Override
                    public void onError(DexterError error) {
                        Toast.makeText(getApplicationContext(), "Error occurred! ", Toast.LENGTH_SHORT).show();
                    }
                })
                .onSameThread()
                .check();
    }

    /**
     * Showing Alert Dialog with Settings option
     * Navigates user to app settings
     * NOTE: Keep proper title and message depending on your app
     */
    private void showSettingsDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("Need Permissions");
        builder.setMessage("This app needs permission to use this feature. You can grant them in app settings.");
        builder.setPositiveButton("GOTO SETTINGS", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
                openSettings();
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.show();

    }

    // navigating user to app settings
    private void openSettings() {
        Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        Uri uri = Uri.fromParts("package", getPackageName(), null);
        intent.setData(uri);
        startActivityForResult(intent, 101);
    }
}
</code>
Comment: Then its a memory issue. You need to use a service as suggested in the answer.
Comment: Please share the stacktrace of crash
Comment: It doesnt crash. OS silently kills the app
Comment: Try to use a foreground service.
Answer: Use a foreground service to ensure that your app is not killed by Android. On newer version of Android, app's background process gets killed after sometime. Having a foreground service will ensure that your app stays active. Keep the service on background thread and not on the main thread.
Read more at:
https://developer.android.com/guide/components/services
and
https://androidwave.com/foreground-service-android-example/
Comment: So do we need to initiate the foreground service from my MainActivity ?
Comment: You can initiate it from any activity or also using broadcast.
Comment: Right now i have a BroadcastReceiver registered on my MainActivity. Basically waits for SMS from certain Number and displays it in my main activity. I would like the message to displayed in a foreground activity without OS killing it.
https://www.youtube.com/watch?v=FbpD5RZtbCc
Is this the correct way to implement it ?
Answer: Activities are used for user facing parts of your application. Use service instead. Most likely, your application is getting terminated by os due to low memory situation.
Answer: Use service for the core functionality if you want to run all the time in background.If user is not using your app actively yet app is taking RAM memory then OS will terminate the app to avoid out of memory.
Comment: But i read in the new android OS, even services will be terminated after sometime. Is there any solution ? Also how can i convert my current Activity into a service ? Any reference would be appreciated


index.html change to index.xhtml

Question: When trying to logout my application I'm having the following error message :
com.sun.faces.context.FacesFileNotFoundException: /index.xhtml Not Found in ExternalContext as a Resource

To logout I'm going though the following steps inside PhaseListener.beforePhase(PhaseEvent phaseEvent) :
// Redirect to index.html
NavigationHandler nh = fctx.getApplication().getNavigationHandler();
String action_outcome = "/index.html";
nh.handleNavigation(fctx, null, action_outcome);

My web.xml is as follow :
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        id="WebApp_ID"
        version="3.0">

        <context-param>
              <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
              <param-value>.xhtml</param-value>
          </context-param>

          <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
          </servlet>

      <filter-mapping>
        <filter-name>Seam Filter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      <filter-mapping>
        <filter-name>trinidad</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
      </filter-mapping>

      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.seam</url-pattern>
      </servlet-mapping>

          <welcome-file-list>
            <welcome-file>index.html</welcome-file>
          </welcome-file-list>
          <security-constraint>
            <display-name>Restrict raw XHTML Documents</display-name>
            <web-resource-collection>
              <web-resource-name>XHTML</web-resource-name>
              <url-pattern>*.xhtml</url-pattern>
            </web-resource-collection>
            <auth-constraint/>
          </security-constraint>
          <login-config>
            <auth-method>BASIC</auth-method>
          </login-config>
</web-app>

I do not have index.xhtml in my app, but I do have and want to keep it index.html file.
Why is my outcome_action given to NavigationHandler rename to index.xhtml ?
How could I avoid it ?
Answer: The NavigationHandler expects a JSF page, not a non-JSF page. Moreover, you're there actually not sending a real redirect at all, on the contrary to what the code comment says there. You're just performing a forward here.
Performing a real redirect would be the solution to your problem. It's to be done as below:
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(ec.getRequestContextPath() + "/index.html");

See also:

What is the difference between redirect and navigation/forward and when to use what?
How to navigate in JSF? How to make URL reflect current page (and not previous one)

Unrelated to the concrete problem, doing authorization job in a phase listener stinks. Have you considered a servlet filter?
See also:

Limitations of using a PhaseListener instead of a Servlet Filter for authorization
Failing to redirect from JSF phaselistener
How to invalidate session in JSF 2.0?
Comment: Your solution is working and thanks for your advices and links.  I'll take the time to read them.

index.html change to index.xhtml


The advantages of recurrent neural network(RNN) over feed-forward neural network (MLP)

Question: Assume we use both RNN and MLP for the same task, and each network is well trained. Since RNN uses more information than MLP, theoretically its performance should be better than MLP. Are there any exceptions? If so, why?
Comment: A helpful link: https://www.quora.com/Why-are-feed-forward-neural-networks-currently-more-powerful-than-recurrent-neural-networks
Answer: Theoretically, MLP can approximate any function, to an arbitrary precision, therefore there is no need for RNN. However that doesn't mean it is usable in a wild. Assuming we are talking about time series input, textbook answer would be that you can feed your time series in feed forward network, by having a input layer containg also inputs from previous time points. Therefore effectively transforming time series problem, into feed forward problem. However you will have to choose length of your input beforehand, and you will not be able to learn functions that depends on the inputs happening long time ago. You can solve this problem by having a RNN, that can theoretically, store information from arbitrarily long time ago, in it;s context layer. In practice however, you will have gradient exploding/vanishing problem.
Comment: Great answer!  Recently I found in my task RNN is slight worse than MLP but the gradient of the params are not exploding/vanishing during training, so I guess there might be some other reasons that hurt RNN's performance. Do you have any suggestions?
Comment: You might be just overfitting/underfitting
Comment: When I increased the training batches for RNN, the performance improved. Does that mean underfitting? Is there any other method to avoid it?
Answer: For purposes of discussion I'll assume you are using RNN for the typical use case of time series analysis, where the recurrence operation allows response to depend on a time-evolving state; for example the network can now detect changes over time. This is exactly the added capability you'd want a Recurrent Neural Network for, in this example. That part it sounds like you know.
The downside, is it can be much more difficult to train and has multiple issues with convergence. For example, the backpropegation "signal" tends to decay exponentially over "time". The choice of learning algorithm can be more limited. (SGD can't obviously throw out intermediate timesteps without serious modifications).
There are other methods that address some of these issues; for example Long-Short Term Memory, which basically uses a gating approach to build a recurrent circuit that can be "set" or "cleared".
Even if you aren't talking time series (e.g. Recurrent neural network have also been used with convolutional layers to extend the effective pixel neighborhood.) you will still have similar convergence and exponential backprop decay issues.
Comment: The hidden units of RNN contains historical information from previous states, while MLP only uses local contexts. That's why I said "uses more information".


How to create an in-house Spark package repository?

Question: How can I create an in-house repository for Spark packages?  I would like to create an in-house repository that I could use via spark.jars.repositories.
Is this just a Web server and some JAR files, or do I need to install some software, configure metadata, etc.?
Answer: Spark expects jars in maven-style coordinates. You can choose one of the maven repository managers listed here https://maven.apache.org/repository-management.html like Apache Archiva (open source) or JFrog Artifactory Open Source (open source).
If you are happy to upload artifacts manually you can go for a simple webserver with a WebDAv module as shown here https://gist.github.com/EronWright/d856aad6302e0c18ccd96164540a653c.


Como recuperar dados de um SUM com where diferente?

Question: Tenho uma tabela de horários de ponto de trabalho, que possui a data_inicio, data_fim, usuario_id e extra que indica se é hora extra ou não.
Eu já tenho uma query que traz a soma em segundos trabalhados por ano, mês, usuário dos últimos 6 meses.
Porém agora também preciso trazer a somatória de segundo trabalhados regulares e em horas extras (extra = 1).
SELECT
        us.nome as usuario,
        MONTH(tb.data_inicio) AS mes,
        YEAR(tb.data_inicio) AS ano,
        SUM(TIMESTAMPDIFF(SECOND, tb.data_inicio, tb.data_fim)) AS total_segundos,
        COUNT(DISTINCT DAY(tb.data_inicio)) AS total_dias

FROM `horario_ponto` tb

INNER JOIN `usuario` us ON us.id = tb.usuario_id

WHERE tb.data_inicio > (LAST_DAY(NOW() - INTERVAL 6 MONTH) + INTERVAL 1 DAY)

GROUP BY usuario, ano, mes
ORDER BY ano DESC, mes DESC, usuario ASC

Já tentei de diversas formas já parece não existir uma solução sem que a query tenha que ser reescrita dentro de uma subquery.
Existe alguma forma de:
SUM(TIMESTAMPDIFF(SECOND, tb.data_inicio, tb.data_fim)) AS total_segundos_regulares, receber algum parametro que discrimine tb.extra = 0 e num outro:
SUM(TIMESTAMPDIFF(SECOND, tb.data_inicio, tb.data_fim)) AS total_segundos_extra receba o tb.extra = 1?
Answer: Você pode somar com IF dentro de seus SUM'S.
SELECT
        us.nome as usuario,
        MONTH(tb.data_inicio) AS mes,
        YEAR(tb.data_inicio) AS ano,
        SUM(IF(extra = 0,TIMESTAMPDIFF(SECOND, tb.data_inicio, tb.data_fim),0)) AS total_segundos_regulares,
        SUM(IF(extra = 1,TIMESTAMPDIFF(SECOND, tb.data_inicio, tb.data_fim),0)) AS total_segundos_extras,
        COUNT(DISTINCT DAY(tb.data_inicio)) AS total_dias
FROM `horario_ponto` tb
INNER JOIN `usuario` us ON us.id = tb.usuario_id
WHERE tb.data_inicio > (LAST_DAY(NOW() - INTERVAL 6 MONTH) + INTERVAL 1 DAY)
GROUP BY usuario, ano, mes
ORDER BY ano DESC, mes DESC, usuario ASC

Verifica os campos extra e soma em dois alias separados.


Repeated measures correlation as mixed model

Question: I'm writing this question to better understand how to set up a mixed model to estimate a linear relationship between two variables from repeated observations.
Suppose the variables $X$ and $Y$ are observed on $n$ individuals at $k$ time points each. The observations $x_{i,t}$ change linearly over time according to a random intercept model:
$$
x_{i,t} = x_{i,0}+\beta\, t+\varepsilon_{i,t}^x,\quad x_{i,0}\sim \mathcal{N}(\mu,\sigma^2),\quad i=1,\ldots,n
$$
The observations $y_{i,t}$ are linearly related to the $x_{i,t}$:
$$
y_{i,t}=\gamma ( x_{i,0}+\beta\, t)+\varepsilon_{i,t}^y,
$$
where, for simplicity, I assumed that $\gamma$ is independent of $t$.
If I haven't made a mistake a simple simulation of the model can be achieved in R by the following code.
set.seed(1)

n <- 30 #number of subjects
t <- c(0,1,3,12) # time points
b <- .2 # coefficient beta
c <- -2 # coefficient gamma

x0 <- rnorm(n,10,1) # random intercepts

x <- unlist(lapply(t, function(t){x0+b*t}))
y <- c*x

df<-data.frame(x=x+rnorm(4*n,0,1), y=y+rnorm(4*n,0,1), t=rep(t,each=n), ID=rep(seq.int(1,n),4))

Plotting the data manifestly shows the linear relationship at each of the four time points.
require(ggplot2)
ggplot(df,aes(x=x,y=y,col=as.factor(t)))+
  geom_point()+
  geom_smooth(method='lm', se = F)

Consequently, fitting linear models for each time point separately yields estimates for $\gamma$.
lapply(t,function(tp)summary(lm(y~x,d=df, subset = t==tp)))

A blind pooling of the data in a multiple regression
summary(lm(y~x+t,df))

reveals highly significant effects of $x$ and time
 Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -8.18658    1.24738  -6.563 1.51e-09 ***
x           -1.16335    0.12010  -9.686  < 2e-16 ***
t           -0.22201    0.03772  -5.885 3.87e-08 ***

but fails to take into account the dependence between observations from the same subject.
A simple mixed-effects model with random effects for subjects
require(nlme)
summary(lme(y~x+t, random=~1|ID, d=df))

yields highly variable estimates for $\gamma$
Fixed effects: y ~ x + t
                 Value Std.Error DF    t-value p-value
(Intercept) -17.333357 1.2615782 88 -13.739424  0.0000
x            -0.270954 0.1183723 88  -2.289001  0.0245
t            -0.364641 0.0278553 88 -13.090550  0.0000

which, despite the larger data basis, are considerably less precise than the single-time estimates.

Question How can one formulate a model to pool the data from the separate time points to obtain an even better estimate for $\gamma$?

I am aware of the rmcorr package, which claims to answer the question above. However, having looked the code of the package, it seems to compute a linear model for the pooled data without accounting for correlations. If the package is indeed applicable, I wold be grateful for an explanation.
Edit 16 May 2019:

Cleared up notational confusion between $\beta$ and $\gamma$.
Removed error $\varepsilon_{i,t}^x$ from the model equation for
$y_{i,t}$.
Answer: AFAIK a full (restricted) maximum likelihood estimation approach for this model is not possible with neither nlme nor lme4. But you could, for example, do it under a Bayesian approach using either STAN or JAGS.
As a alternative you could do a two-stage approach in which you first fit a mixed model for x, and the you plug-in the subject-specific fitted values in a linear regression for y. E.g.,
 fm <- lme(x ~ t, data = df, random = ~ 1 | ID)
 lm(y ~ 0 + fitted(fm), data = df)

Comment: Thanks for your comment pointing out inconsistencies in my question. I would like indeed to recover $\gamma$, the relation between $y$ and $x$. The error $\varepsilon_{i,t}^x$ is thought to be observation error in $x$ but is assumed not to impact on $y_{i,t}$, hence the R code is correct. I edited my question.
Comment: That's an interesting approach, thank you! How would I set up such a model in STAN, presumable using the rstan interface?
Comment: Yes, you could do it with **rstan**.
Comment: Thanks. Do you happen to know of a reference or book where the two-stage approach you suggest is explained and its theoretical properties are analysed?
Comment: I don't have a reference for this particular two-stage combination, but in general this is a solution that is used to fit joint models with standard software procedures. Hence, search for "joint models two-stage approach".


In pigeonhole principle, what is the expected number of holes with no pigeons

Question: I am trying to understand pigeonhole principle and I am trying some random queries to further my understanding (https://en.wikipedia.org/wiki/Pigeonhole_principle)
In pigeonhole principle, what is the expected number of holes which did not have any pigeons?
How do i get an intuition around this?
Thanks
Comment: The question relies on a missing premise. The pigeonhole *principle* doesn't involve any reference to any random process by which we might derive an expectation. It says something along the lines of "if n objects are put into m slots, with n > m > 0, then at least one slot must contain more than one object". That's the principle and it applies *no matter how objects are allocated to slots". You could always allocate all $n$ objects to one slot, or always allocate all $n$ objects to the emptiest available slot (breaking ties arbitrarily), but it wouldn't change the principle in any way.
Comment: Presumably you mean to specify some manner of allocating objects to slots, but that's nothing to do with the principle.
Answer: As Kodiologist correctly writes, the Pigeonhole Principle is a combinatorial observation about the Balls into Bins problem when there are more balls than bins. Presumably, as a matter of terminology, you meant to ask about the expected number of empty bins in the ball into bins problem.
Suppose you have $m$ bins and $n$ balls. The probability that a specific bin will remain empty is $\left(1 - \frac{1}{m}\right)^n$. This is also the expectation of the event that is 1 if it is empty, and 0 otherwise. By linearity of expectation, you can just sum this up for all bins. The expectation of the number of empty bins is therefore $m \left(1 - \frac{1}{m}\right)^n$
Answer: The pigeonhole principle is a combinatorial rather than probabilistic statement. So, it makes no claims about expected value, just about cases in which collisions may happen, collisions must happen, or collisions must not happen. For example, if you have more holes than pigeons, then at least one of the holes will end up empty.


Sending value of drop down with description and numbers used for calculating total

Question: I have a form that I don't have control of the php of to edit. I need it so that when it sends the value it sends the description of the item but I needed the value to add the prices for the total field. Is there a way to set up so I can send the description of the item but still keep the value as numbers so it adds the total?

      <select class="form-dropdown validate[required]" onchange="code(1)" style="width:150px" id="input_7" name="q7_ticketOptions">
        <option>  </option>
        <option value="300"> VIP Floor Seats - $300.00 </option>
        <option value="40"> Section 101 Upper Level - $40.00 </option>
        <option value="60"> Section 101 Mid Level - $60.00 </option>
        <option value="150"> Section 101 Lower Level - $150.00 </option>
        <option value="40"> Section 102 Upper Level - $40.00 </option>
        <option value="60"> Section 102 Mid Level - $60.00 </option>
        <option value="150"> Section 102 Lower Level - $150.00 </option>
        <option value="40"> Section 103 Upper Level - $40.00 </option>
        <option value="60"> Section 103 Mid Level - $60.00 </option>
        <option value="150"> Section 103 Lower Level - $150.00 </option>
        <option value="20"> Section 104 Upper Level - $20.00 </option>
        <option value="60"> Section 104 Mid Level - $60.00 </option>
        <option value="20"> Section 107 Upper Level - $20.00 </option>
        <option value="60"> Section 107 Mid Level - $60.00 </option>
        <option value="40"> Section 108 Upper Level - $40.00 </option>
        <option value="60"> Section 108 Mid Level - $60.00 </option>
        <option value="150"> Section 108 Lower Level - $150.00 </option>
        <option value="40"> Section 109 Upper Level - $40.00 </option>
        <option value="60"> Section 109 Mid Level - $60.00 </option>
        <option value="150"> Section 109 Lower Level - $150.00 </option>
        <option value="40"> Section 110 Upper Level - $40.00 </option>
        <option value="60"> Section 110 Mid Level - $60.00 </option>
        <option value="150"> Section 110 Lower Level - $150.00 </option>
        <option value="40"> Section 111 Upper Level - $40.00 </option>
        <option value="60"> Section 111 Mid Level - $60.00 </option>
        <option value="150"> Section 111 Lower Level - $150.00 </option>
        <option value="40"> Section 112 Upper Level - $40.00 </option>
        <option value="60"> Section 112 Mid Level - $60.00 </option>
        <option value="150"> Section 112 Lower Level - $150.00 </option>
        <option value="20"> Section 113 Upper Level - $20.00 </option>
        <option value="60"> Section 113 Mid Level - $60.00 </option>
        <option value="40"> Section 114 Upper Level - $40.00 </option>
        <option value="60"> Section 114 Mid Level - $60.00 </option>
        <option value="40"> Section 115 Upper Level - $40.00 </option>
        <option value="60"> Section 115 Mid Level - $60.00 </option>
        <option value="20"> Section 116 Upper Level - $20.00 </option>
        <option value="60"> Section 116 Mid Level - $60.00 </option>
        <option value="40"> Section 117 Upper Level - $40.00 </option>
        <option value="60"> Section 117 Mid Level - $60.00 </option>
        <option value="150"> Section 117 Lower Level - $150.00 </option>
        <option value="40"> Section 118 Upper Level - $40.00 </option>
        <option value="60"> Section 118 Mid Level - $60.00 </option>
        <option value="150"> Section 118 Lower Level - $150.00 </option>
      </select>

     Quantity*

      <select class="form-dropdown validate[required]" onchange="code(2)" style="width:150px" id="input_23" name="q23_quantity">
        <option>  </option>
        <option value="1"> 1 </option>
        <option value="2"> 2 </option>
        <option value="3"> 3 </option>
        <option value="4"> 4 </option>
        <option value="5"> 5 </option>
        <option value="6"> 6 </option>
        <option value="7"> 7 </option>
        <option value="8"> 8 </option>
        <option value="9"> 9 </option>
        <option value="10"> 10 </option>
      </select>

    Total     $

      <input type="text" name="q22_total" id="cost" onfocus="this.blur()" style="width:50px"/>

Here is the Javasript:

Answer: Well if you are saving all these  calculations in the database than first of all you should create a table 'ticket_options', in which you should feed it in two columns e.g.
column1 for 'q7_ticketOptions',columns2 for 'ticketRates'
<select class="form-dropdown validate[required]" onchange="code(1);,showUser(this.value);" style="width:150px" id="input_7" name="q7_ticketOptions">
 <option  selected="selected"  disabled="disabled">Choose TicketOptions</option>
        <?php
       $sql=mysql_query("select * from ticket_options order by id ASC");
        while($val=mysql_fetch_array($sql))
         {
         ?>
        <option> <?php print $val['q7_ticketOptions']; ?>
        </option>
        <?php  } ?>
   </select>

Choose ticketOptions

Than creat this function in the head section of your page:


What statistical test would I use with 2 groups and a control to show significant difference?

Question: Question I would like to answer: To encourage more referrals, the product team is running an experiment on the iOS app, called "ios_referral_experiment", that tests adding new links to the referral invite page. The experiment has 3 groups: the "control" group has no new link; the "tab_only" group has a new navigation tab that links to the page; and the "tab_settings" group has both a new navigation tab and a new link in the settings. What are the results from this experiment and what would you  recommend?
I have a table that looks  like so:
event_type                          test_group                         Total_Impressions
referrer_page_invite_action          control                            1892
referrer_page_invite_action          tab_only                           4009
referrer_page_invite_action          tab_settings                       2995
referrer_page_viewed                 control                            25382
referrer_page_viewed                 tab_only                           63372
referrer_page_viewed                 tab_settings                       44473

My goal is to determine if the split_test_group have significant differences on total impression when compared to control. I would do two seperate tests for each event_type variables.
I was thinking a simple t-test but was unsure and would appreciate any help.
Comment: Thanks for the edit. But what happened to the counts $25383, 63372, 44473$ in your original data table. It is not possible to compare Total Impression counts with each other without knowing the total number of subjects on each of the rows of your table. (Are the three groups now of the same size? If so, what size?)
Comment: I did not mean to delete that...sorry. Updated. Would your answer still follow given the updated info?
Comment: Yes, but instead of saying 'independent', now I'd re-phrase to say that the proportions of impressions in the three groups are not the same.
Comment: Okay - so the rows of your TBL would be the 'event_type' and the columns would be the 3 groups im measuring against.
Answer: Comment:
You don't explain your experiment or its goals, and the labels
in your data table are cryptic. However, it looks as if you may have
a $2\times 3$ contingency table TBL of counts, with $142\,124$
subjects altogether.
TBL = rbind(c(1892,4009,2995),c(25383,63372,44473)); TBL
      [,1]  [,2]  [,3]
[1,]  1892  4009  2995
[2,] 25383 63372 44473
sum(TBL)
[1] 142124

If this accurately describes your data, then a chi-squared test
rejects the null hypothesis that row and column categories are
independent, with P-value near $0.$
chisq.test(TBL, cor=F)

        Pearson's Chi-squared test

data:  TBL
X-squared = 32.542, df = 2, p-value = 8.583e-08

Pearson residuals in the first two cells of the first row show
large absolute values, indicating that the largest discrepancies,
between the observed counts in TBL and the six expected counts
(computed on the assumption that the null hypothesis is true),
are in these two cells of the table. The sum of squares of these
six residuals is the test statistic $32.542.$
chisq.test(TBL, cor=F)$res
          [,1]      [,2]       [,3]
[1,]  4.471824 -3.211960  0.4370811
[2,] -1.155538  0.829984 -0.1129436

Note: If this is not a correct interpretation, please edit your Question
for clarity. [As you question stands, I see no role for a t test.]

Addendum:  Here is basically the same chi-squared test as above
but organized to focus on three proportions (which are apparently not all the same).
Inv=c(1892,4009,2995)
View = c(25383,63372,44473)
Tot = Inv + View

        3-sample test for equality of proportions
        without continuity correction

data:  Inv out of Tot
X-squared = 32.542, df = 2, p-value = 8.583e-08
alternative hypothesis: two.sided
sample estimates:
    prop 1     prop 2     prop 3
0.06936755 0.05949748 0.06309514

Comment: Sorry for the confusion - I added more context and simplified the data table. The goal is come up with a  method that can accurately determine which 'test_group' has the best influence on more 'referrals'. The table I posted is the sum of each group (does not include individual users/time info).


How to import zeromq libraries in cmake?

Question: I'm just starting to learn how to work with zeromq libraries and using them in different C++ projects.
The sample code that I wrote (actually copied from there tutorials)is this:
//  file: main.cpp
//  Hello World client in C++
//  Connects REQ socket to tcp://localhost:5555
//  Sends "Hello" to server, expects "World" back
//
#include <zmq.hpp>
#include <string>
#include <iostream>

int main ()
{
    //  Prepare our context and socket
    zmq::context_t context (1);
    zmq::socket_t socket (context, ZMQ_REQ);

    std::cout << "Connecting to hello world server…" << std::endl;
    socket.connect ("tcp://localhost:5555");

    //  Do 10 requests, waiting each time for a response
    for (int request_nbr = 0; request_nbr != 10; request_nbr++) {
        zmq::message_t request (5);
        memcpy (request.data (), "Hello", 5);
        std::cout << "Sending Hello " << request_nbr << "…" << std::endl;
        socket.send (request);

        //  Get the reply.
        zmq::message_t reply;
        socket.recv (&reply);
        std::cout << "Received World " << request_nbr << std::endl;
    }
    return 0;
}

and by building the output of this file with the command below:
g++ main.cpp -o test -lzmq

the file will be generated with no problem.
The problem that I have is that I want to build the file using CMake.Thus, I've written a CMakeLists.txt file as below:
cmake_minimum_required(VERSION 3.6)
project(test2)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lzmq")

set(SOURCE_FILES main.cpp)
add_executable(test2 ${SOURCE_FILES})

The part that I thought will be enough to build the program is -lzmq but even with that piece included, I get the following error messages:
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::error_t::error_t()':
/usr/include/zmq.hpp:62: undefined reference to `zmq_errno'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::error_t::what() const':
/usr/include/zmq.hpp:66: undefined reference to `zmq_strerror'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::message_t::message_t()':
/usr/include/zmq.hpp:107: undefined reference to `zmq_msg_init'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::message_t::message_t(unsigned long)':
/usr/include/zmq.hpp:114: undefined reference to `zmq_msg_init_size'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::message_t::~message_t()':
/usr/include/zmq.hpp:129: undefined reference to `zmq_msg_close'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::message_t::data()':
/usr/include/zmq.hpp:180: undefined reference to `zmq_msg_data'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::context_t::context_t(int)':
/usr/include/zmq.hpp:204: undefined reference to `zmq_init'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::context_t::~context_t()':
/usr/include/zmq.hpp:225: undefined reference to `zmq_term'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::socket_t::socket_t(zmq::context_t&, int)':
/usr/include/zmq.hpp:251: undefined reference to `zmq_socket'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::socket_t::close()':
/usr/include/zmq.hpp:283: undefined reference to `zmq_close'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::socket_t::connect(char const*)':
/usr/include/zmq.hpp:314: undefined reference to `zmq_connect'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::socket_t::send(zmq::message_t&, int)':
/usr/include/zmq.hpp:321: undefined reference to `zmq_send'
/usr/include/zmq.hpp:324: undefined reference to `zmq_errno'
CMakeFiles/test2.dir/main.cpp.o: In function `zmq::socket_t::recv(zmq::message_t*, int)':
/usr/include/zmq.hpp:331: undefined reference to `zmq_recv'
/usr/include/zmq.hpp:334: undefined reference to `zmq_errno'

Should I set another kind of variable in the CMake file or have I installed the library in a wrong directory? or is there anything else that I should have mentioned?
and The system witch I'm working on is Ubuntu 14.04
Answer: CMake doesn't include direct support for 0mq and 0mq doesn't include direct support for CMake. But, 0mq does support pkg-config and we can use this to help us. Since you mentioned that you're on Ubuntu 14.04, make sure you've done sudo apt-get install libzmq3-dev to install the 0mq libraries, headers, and the pkg-config .pc file.
Then use the following CMakeLists.txt which I've modified from your version above. (I've commented all my changes inline.)
## i have cmake 3.5
cmake_minimum_required(VERSION 3.5)
project(test2)

## use this to globally use C++11 with in our project
set(CMAKE_CXX_STANDARD 11)

## load in pkg-config support
find_package(PkgConfig)
## use pkg-config to get hints for 0mq locations
pkg_check_modules(PC_ZeroMQ QUIET zmq)

## use the hint from above to find where 'zmq.hpp' is located
find_path(ZeroMQ_INCLUDE_DIR
        NAMES zmq.hpp
        PATHS ${PC_ZeroMQ_INCLUDE_DIRS}
        )

## use the hint from above to find the location of libzmq
find_library(ZeroMQ_LIBRARY
        NAMES zmq
        PATHS ${PC_ZeroMQ_LIBRARY_DIRS}
        )

set(SOURCE_FILES main.cpp)
add_executable(test2 ${SOURCE_FILES})

## add the include directory to our compile directives
target_include_directories(test2 PUBLIC ${ZeroMQ_INCLUDE_DIR})
## at the 0mq library to our link directive
target_link_libraries(test2 PUBLIC ${ZeroMQ_LIBRARY})

Now you can make your project.
❯ make
[ 50%] Building CXX object CMakeFiles/test2.dir/main.cpp.o
[100%] Linking CXX executable test2
[100%] Built target test2

If you want to see what's happening under the hood, do a verbose make.
❯ make VERBOSE=1
/usr/bin/cmake -H/home/nega/foo -B/home/nega/foo/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/nega/foo/build/CMakeFiles /home/nega/foo/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/nega/foo/build'
make -f CMakeFiles/test2.dir/build.make CMakeFiles/test2.dir/depend
make[2]: Entering directory '/home/nega/foo/build'
cd /home/nega/foo/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/nega/foo /home/nega/foo /home/nega/foo/build /home/nega/foo/build /home/nega/foo/build/CMakeFiles/test2.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/nega/foo/build'
make -f CMakeFiles/test2.dir/build.make CMakeFiles/test2.dir/build
make[2]: Entering directory '/home/nega/foo/build'
[ 50%] Building CXX object CMakeFiles/test2.dir/main.cpp.o
/usr/bin/c++     -std=gnu++11 -o CMakeFiles/test2.dir/main.cpp.o -c /home/nega/foo/main.cpp
[100%] Linking CXX executable test2
/usr/bin/cmake -E cmake_link_script CMakeFiles/test2.dir/link.txt --verbose=1
/usr/bin/c++      CMakeFiles/test2.dir/main.cpp.o  -o test2 /usr/lib/x86_64-linux-gnu/libzmq.so
make[2]: Leaving directory '/home/nega/foo/build'
[100%] Built target test2
make[1]: Leaving directory '/home/nega/foo/build'
/usr/bin/cmake -E cmake_progress_start /home/nega/foo/build/CMakeFiles 0

If you look at the compile line, you'll notice that

C++11 support was added (with the -std=gnu++11 flag)
There's no -I/path/to/zmq flag. That's because Ubuntu dumps zmq.hpp in to /usr/include and CMake is smart enough to know that is a default path, so it does nothing

If you look at the link line, you'll notice that libzmq.so has been included via it's full path. Some people don't like that (myself included) and prefer -L/lib/dir -lmylib instead. Using the full path is "the CMake way", and you'll actually come to appreciate it as you grow with CMake and use it for larger and more complicated projects (you still might not like it though.)
Also note, that since you're on Ubuntu we could have cheated and used dpkg -L libzmq3-dev to find the locations of the files we're interested in then added them to your original CMAKE_CXX_FLAGS line, but that's cheating and more importantly, not portable.
Comment: I encountered an error on Mac OS X and on Ubuntu until I installed the most recent version of ZeroMQ using `sudo apt install libzmq5` [Ubuntu] or `brew install zmq` [OS X]
Answer: A cmake config file has been added to libzmq github repository Jan 7, 2017 here.
This is not included in the latest release (4.2.1) yet, but I belive it should be in the next release.
I have installed the head version using cmake and then installed cppzmq, which uses find_package(ZeroMQ REQUIRED) to locate libzmq. All worked like a charm.
EDIT: The cmake config file is included in release 4.2.2 here. Then it was moved to directory builds/cmake at release 4.2.4. I didn't test it again but find_package(ZeroMQ REQUIRED) should just work since ibzmq 4.2.2.
Comment: Indeed, that's the way to go if you have the ability to use the HEAD or the upcoming release. If you're stuck using system packages then my previous answer is the way to go. It also can be extrapolated to any library that has pkg-config support but not cmake config support.
Comment: I found that in order to get the cmake config file instealled you must compile using cmake instead of `./configure` as shown in the INSTALL doc.
Answer: This works as well
 cmake_minimum_required(VERSION 3.6)
 project(test)
 add_executable(c main.cpp)
 target_link_libraries(c zmq)


Remove duplicate messages

Question: How to remove any duplicate messages of a certain type.
For example when performing 2 searches using the search api module before rendering the page the message "To perform a search you must enter at least 3 characters" may be displayed twice.
Answer: Use the following function to remove any duplicate messages of a certain type:
/**
 * @param $type - the type of messages that should be checked
 *
 * Removes any duplicate messages from the messages session
 */
function remove_duplicate_messages($type) {
  $stack = array();
  if(isset($_SESSION['messages'][$type])) {
    foreach($_SESSION['messages'][$type] as $k => $msg) {
      if(in_array($msg, $stack)) {
        // Message is already set - remove it
        unset($_SESSION['messages'][$type][$k]);
      } else {
        // Add message to stack
        $stack[] = $msg;
      }
    }
  }
}

Example use:
remove_duplicate_messages('warning');

Remove duplicate messages


citation for the notion that mathematical models require assumptions

Question: I'm going to walk through some logic that I believe I've heard somewhere before...but I can't remember where and I am interested in citing it.  Does anyone know where I could cite this type of thinking and its conclusion?
Also, I am interested in whether this line of reasoning is correct, or if there are some holes in it.

I am studying a deterministic process and I want to build a mathematical model for how it works, both for inference and for prediction.
The process has the following inputs and outputs.
Input: $p$ binary predictors and I know that nothing outside these $p$ predictors influences the outcome.  I'll imagine $p \approx 100$ to create the right flavor of problem.
Output: 1 binary outcome
So, if I observed all $2^p$ possible inputs and their resultant outputs (assuming no measurement error), there would be nothing to do - I would know everything there is to know about this process.
But, I can't really observe all the possible inputs when $p$ is more than about 5 or 6 and I'm interested in situations where $p$ is around 100.
So, let's imagine a slightly more realistic situation (but only slightly!).
Imagine I observed "only" $2^p - 1$ inputs and their resultant outputs.  How would I predict the output for the final possible input?
It seems there must be at least two possible rules -- one that, if it were true, would give a 0 for the last set of input and one that, if it were true, would give a 1 for the last set of input.
And there's no way to choose between them without seeing the last input!
I can only choose between the two (or maybe there are more?) rules based on a priori beliefs about which rules are reasonable/likely/good/useful and which are not.
Though this setup seems fanciful, I would argue it's the easiest possible situation in which a model could be fit.

The outcome was binary, and any continuous response could be simplified with binarization.
There are no unknown inputs. I could ignore some of them to return to the situation where most statistical modeling efforts exist -- some inputs are unknown and their effects are sopped up into the residual error term or similar.
The inputs are binary.  Any continuous valued input could be binarized without losing information by turning it into a set of "greater than this cutoff?" "greater than that cutoff?" binary values.
Answer: This idea is essentially the "no free lunch" theorem: if you make no assumptions, then anything is possible, and predicting anything is impossible. As a corollary, no predictive algorithm is uniformly better than another algorithm across all datasets.
There are many posts about the theorem on this site; there's also the website no-free-lunch.org. The standard citation there seems to be:

Wolpert (1996). The Lack of A Priori Distinctions Between Learning Algorithms. Neural Computation 8 (7), 1341-1390. (doi) (Google scholar)

But, of course, predictive inference is not a hopeless task. We just need to make assumptions that we think are reasonably likely to be true; this is the idea of inductive bias.


Confusion relating to Cronbach's $\alpha$

Question: I am confused about how to use Cronbach's $\alpha$.

Do we have to use it in sample survey before the final survey? Or is $\alpha$ calculated based on the final survey data?
Similarly, what does the set of questions measuring a construct mean? Does it mean that the questions are mutually exclusive or do all the questions are to be used together (mutually inclusive) to measure the underlying construct?
Answer: I'll answer these questions out of order:
Similarly, what does the set of questions measuring a construct mean? Does it mean that the questions are mutually exclusive or do all the questions are to be used together (mutually inclusive) to measure the underlying construct?
Imagine that you want to measure someone's innate ability to learn languages. That isn't something that you can observe directly. However, there might be several questions or tests availble that people think reflect this ability. But do they?
Alpha is a measure of internal consistency reflecting the variation that is shared in a set of observed variables. If a set of observed variables (e.g your questions or tests that supposedly reflect language ability) share a lot of variation, it might then be reasonable to interpret them as all reflecting some shared, underlying cause that you cannot (or have not) observed directly.
The reason for asking multiple questions about the same underlying, unobserved construct is that their individual errors will (hopefully) be indepdendent (and kind of cancel each other out - though this is a simplification), helping you to focus in on the variation that is shared. This can be more formally tested with the appropriate latent variable model (latent trait, latent profile, factor analysis, latent class).
Do we have to use it in sample survey before going for final survey? or is value of Alpha calculated based on the final survey data?
Once you have designed an instrument (some set of questions intended to measure the same underlying contruct), you should evaluate it during the pilot phase and make any neccessary adustments before applying the instrument more widely. You would then also evaluate the psychometric properties of the instrument (including alpha) in the full, final sample.
Answer: Regarding your first question: Both. You use it as part of the pilot testing in order to improve the survey. You report it on the final survey as part of its psychometric properties.
I am not sure I understand your second question, but the idea is to include all the questions that measure a particular construct. A survey might include one or more constructs.


error in filling form in using jqueryin a chrome extension?

Question: I am trying to fill up form using jquery in a webpage inside a chrome extension.This is my code:
(new.js)
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){
 y=tab.url;
         $.get(y, function(data)    //function for parsing the webpage
    {
                          //console.log(data);
                          $(data).find('input').each(function() {
                              //alert("inside");
                              if($(this).attr('id')=="email") {
                                  alert($(this).attr('id'));
                                  $("#email").val("xxx");
                              } //console.log($(this).text());

                          });
                      });
});

and the webpage have many forms and I want to fill value into one input whose id id email.This is html code of webpage:
<form id="login_form" action="https://www.facebook.com/login.php?login_attempt=1" method="post" onsubmit="return window.Event && Event.__inlineSubmit && Event.__inlineSubmit(this,event)">
  <input type="hidden" name="lsd" value="AVq0D9ew" autocomplete="off" />

        Email or Phone

        Password

        <input type="text" class="inputtext" name="email" id="email" value="" tabindex="1" />

        <input type="password" class="inputtext" name="pass" id="pass" tabindex="2" />

          <input value="Log In" tabindex="4" type="submit" id="u_0_l" />

            <input id="persist_box" type="checkbox" name="persistent" value="1" checked="1" class="uiInputLabelInput uiInputLabelCheckbox" />
            Keep me logged in

          <input type="hidden" name="default_persistent" value="1" />

        Forgot your password?

  <input type="hidden" autocomplete="off" name="timezone" value="" id="u_0_m" />
  <input type="hidden" name="lgnrnd" value="225331_eElR" />
  <input type="hidden" id="lgnjs" name="lgnjs" value="n" />
  <input type="hidden" autocomplete="off" id="locale" name="locale" value="en_US" />
</form>

P.S.I don't have much experience with jquery so spare me if this question doesn't meet the criteria of SO.
This is my manifest file:
"name": "password",
 "description": "password",
 "version": "0.1",
 "background": {"scripts": ["jquery-1.11.1.js","new.js"], "persistent": false},
 "options_page": "options.html",
 "permissions": ["downloads","tabs","activeTab","history","http://*/",
        "https://*/","http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=6645369"],
"content_scripts": [
    {
      "matches": ["http://*/", "https://*/" ],

      "js": ["new.js"]
    }
  ],
 "manifest_version": 2}

Comment: `$("#email").val("xxx");` should be enough
Comment: Why are you iterating through the data if you're not using anything from it?
Comment: Your question is ok . can you give what is `y`?
Comment: y is the url of the webpage?
Answer: How about simplifying your code into this:
 //function for parsing the webpage
$.get(y, function(data)
{
    $("#email").val("xxx");
});

Comment: But the above one should also work.Btw this also isn't working.I don't know why but this is the case..
Answer: $("#email").val("xxx");

should be enough
Demo
Comment: If a problem in a question cannot be reproduced, don't leave such an answer, but cast a close vote, or flag it as 'offtopic' > 'typo/cannot be reproduced'.
Answer: I suspect this is what you want:
$.get(y, function(data) {
    var value = $(data).find("#email").text();
    $("#email").val(value);
});

Comment: I am trying to do this inside chrome extension.I thought the error might be in the in the jquery code but Can it be possibly because I am doing this inside chrome extensions?
Comment: I don't know much about Chrome extensions, but I don't see why that should make much of a difference. What does the Javascript debugger say?
Answer: try to target directly the specified element, in this case #email,
$("#email").val("xxx");


How to determine a null and alternative hypotheses and interpret F-test results, a specific example

Question: I'm trying to figure out how to interpret the ftest in 1.2(iv) of the attached sheet.  What is the alternative hypothesis being assumed, and what is the null hypothesis being assumed?
Is the interpretation here that, given the t-value from the F-test, there is a chance that this value is not the real mean?

An online T calculator seems to show that there is about a 10% chance of seeing a value smaller than -.933, and approx 10% chance of seeing a value greater than .933, standard errors from the mean.

Doesn't this mean that there is more than a 10% chance that the proposed value of .1 is the right value, and that we should reject the null?
Thanks.

You're correct, I did mix up the null and alternative. In addition, the formula from the notes shows the null is the subtracted value in the numerator which would have tipped me off if i saw it earlier.
Comment: Also extrapolating from iii, it appears that the value .1 falls within our 95% confidence interval for the true mean of b0. So how do we fail to reject the null? This isn't a test of whether a change is significant, in which case I would understand failure to reject the null; it's a test of whether a value is probable.
Comment: If you want an answer to the question in your comment, either add it to your question (via an edit), or post a new question.
Answer: You've mixed up the null and alternative hypotheses. In this case, the null hypothesis is that  $\alpha = 0.1$. Since the P-value is greater than 0.05, we do not reject it.
This is just a variation on the usual theme in hypothesis testing in regression. Normally, when we test whether a coefficient is statistically significant, the (generally unstated) null hypothesis is that the value is zero. In this case, the null hypothesis is that the value is some other fixed value. The procedure is still essentially the same.


How to provide free tagging ability when saving nodes using services

Question: A content type is going to be saved , this type contains a taxonomy term reference field named field_ucectgry . I'm developing an app so the user can create new node types remotely. Services module is used to provide a REST service for that.
Now for filling field_ucectgry during node creation I must pass the term ID , but the problem is that this field must has free tagging ability which means new tokens for this field is accepted.
So , how can I provide the ability of free tagging for my program?
PS: this is the structure of the field in node :
Answer: In D7, a taxonomy term reference field with the autocomplete widget uses JSON like this:
<code>"field_tags":{"und":"Foo,Bar"}"</code>
When it is an autocomplete, the term name needs to be used instead of the term id for free tagging it will simply create the term.
Comment: This error show up:

An illegal choice has been detected. Please contact the site administrator.
Comment: this is my implementation :
"field_ucemake":{"und":"AGCO"}


Calculate arctangent expression without using a calculator

Question: I need help calculating the following:$$\arctan \frac{21 \pi}{\pi^2-54}+\arctan \frac{\pi}{18} + \arctan \frac{\pi}{3}$$
I don't know how to start, can anyone give me any information what should I do? Thank you
By the way, I have to calculate it without any use of a calculator, and without use of Maclaurin series.
Comment: And what does calculator says?
Comment: Note that $\arctan x + \arctan y = \arctan(\frac{x+y}{1-xy})$. What happens if you do this with the latter  two terms?
Answer: The arctangent addition formula gives
$$\arctan \frac{\pi}{18} + \arctan \frac{\pi}{3}=\arctan\frac{7\pi/18}{1-\pi^2/54}=\arctan\frac{21\pi}{54-\pi^2}$$
Thus the expression is of the form $\arctan z+\arctan-z$, and since $\arctan$ is an odd function the expression equals $0$.
Answer: Using $$\arctan x+\arctan y\stackrel{!}{=}\arctan\tan(\arctan x+\arctan y)\\=\arctan\frac{\tan\arctan x+\tan\arctan y}{1-\tan\arctan x\tan\arctan y}=\arctan\frac{x+y}{1-xy}$$(the conditions under which $\stackrel{!}{=}$ is valid are left as an exercise, but they apply to the examples we'll consider), we have $$\arctan\frac{\pi}{18}+\arctan\frac{\pi}{3}=\arctan\frac{21\pi}{54-\pi^2}.$$Since $\arctan x$ is odd, the final sum is $0$.


Hide StockGraph in AmCharts

Question: I use amcharts library and I draw some StockGraphs on stockPanel and I want to allow show and hide any graph on the panel by cheeking/uncheeking check box. How could I show and hide StockGraph in amcharts?
Answer: You can show or hide single graphs by using the functions hideGraph() or showGraph().You need to pass the graph as parameter. (it has to be an AmGraph object)

Hide StockGraph in AmCharts


How to locate the peak of the convolution of two log-concave distributions?

Question: The convolution of two log-concave distributions is also log-concave. It follows that it has a single local maximum. Assume that $f$ and $g$ are two log-concave distributions and that you know where the maximum is located for each. Is there an easy algorithm to locate the maximum of the convolution $f*g$? That is, minimizing the number of evaluations of the convolution, since it is numerically expensive.
Comment: Personally, I'd start a search near the sum of the modes. There might be a way of getting useful bounds out of the log-concavity to allow a bounded search, but I can't say I know of one.
Answer: Given that the convolution is log-concave, one could use a simple Newton-Raphson algorithm, which is difficult to beat when it works.
Comment: The derivative of a convolution has a nice property: http://math.stackexchange.com/questions/177239/derivative-of-convolution, this should ease the derivative calculation.
Comment: That requires numerical evaluation of the derivative of the convolution. Is there a way to circumvent this?
Comment: Not really? You can use non-derivative based methods, but they will usually involve many more evaluations of the target function, and really are more useful when your function is $not$ log-concave, so I don't think that's what you want. It seems like you could use information about $f$ and $g$ to get a reasonable starting value though.


in direct2d drawing dimensions change after window resizing

Question: I am a beginner, and I have made a program in direct2d using c++ in visual studio 2015, just a very basic program that draws a white square on a black background , and it does show the square in a small window. But the problem is that if the user maximizes that window the vertical dimension of the drawing becomes elongated and the square becomes rectangle.
This is the screenshot of the window before maximizing it:
enter image description here
And this is the screenshot of the window after maximizing it:
enter image description here
What am I doing wrong ?
 here is my code and thanks in advance:
ID2D1HwndRenderTarget* pRT = NULL;
ID2D1Factory* pD2DFactory = NULL;
ID2D1SolidColorBrush* pBlackBrush = NULL;
ID2D1SolidColorBrush* pRedBrush = NULL;
HRESULT hr;
RECT rc;
POINT pt;

void draw(){
  pRT->BeginDraw();
  pRT->FillRectangle( D2D1::RectF((FLOAT)rc.left,
     (FLOAT)rc.top,(FLOAT)rc.right, (FLOAT)rc.bottom),pBlackBrush);
  pRT->FillRectangle( D2D1::RectF((FLOAT)pt.x,
     (FLOAT)pt.y,pt.x + 50.0f  ,pt.y + 50.0f),pRedBrush);
  hr = pRT->EndDraw();
}

int APIENTRY wWinMain(/* wWinMain parameters */){

 /*
 ...
 window making
 ...
 */

 hr = D2D1CreateFactory(
   D2D1_FACTORY_TYPE_SINGLE_THREADED,&pD2DFactory );

 // Obtain the size of the drawing area.
 GetClientRect(hWnd, &rc);

 // Create a Direct2D render target

 hr =pD2DFactory->CreateHwndRenderTarget(
    D2D1::RenderTargetProperties(),
    D2D1::HwndRenderTargetProperties(
       hWnd,D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top)
    ),
    &pRT
 );
 if (SUCCEEDED(hr)){
   pRT->CreateSolidColorBrush(
      D2D1::ColorF(D2D1::ColorF::White),
      &pRedBrush
   );
   pRT->CreateSolidColorBrush(
      D2D1::ColorF(D2D1::ColorF::Black),
      &pBlackBrush
   );
 }
 pt.x = 0;
 pt.y = 0;

 while (1) {
   PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE);
   if (msg.message == WM_QUIT) break;
   if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)){
     TranslateMessage(&msg);
     DispatchMessage(&msg);
   }

   draw();
 }
}

Comment: I don't think anything is elongated, most likely you just see old rendered results, with new rendering results on top of them. So when you resize you repeatedly draw over and over existing window contents. I'd suggest to handle window messages correctly, specifically WM_PAINT.
Answer: It seems like you don't resize the render target when your window resizes. I expect you run into similar problems not just from maximizing, but when you resize your window too? See https://learn.microsoft.com/en-us/windows/desktop/LearnWin32/dpi-and-device-independent-pixels#resizing-the-render-target.
Code snippet from the linked document:
void Resize()
{
    if (pRenderTarget != NULL)
    {
        RECT rc;
        GetClientRect(m_hwnd, &rc);

        D2D1_SIZE_U size = D2D1::SizeU(rc.right, rc.bottom);

        pRenderTarget->Resize(size);
        InvalidateRect(m_hwnd, NULL, FALSE);
    }
}

You'll want to call this by catching WM_SIZE.


How to find url of content-type?

Question: I am new in Drupal
I have an article website, and it has some category like History, Sport, Graphic, Music and etc.
But when I add some content-type for each of these and when I visit that post, I can't find the URL path of them. for example when I post a new Sport article that it's title is "Ronaldo's regimen" and when I click on save button on drupal, drupal show me an article that its URL is this :

www.example.com/content/ronaldos-regimen

I need to add a link to my menu for each catagory, something like this:

Sport | History | Graphic | Music

(I use pathauto module)
Comment: Do you want the path to have an alias such as this: www.example.com/sports/ronaldos-regimen? If so please provide more information about your categories. Are they different node content types, or are they taxonomy terms on the article type? Provide as much information about categories as possible.
Comment: @J.Reynolds They are different node content, each category has it's own content type
Answer: While creating node, Check on Provide a menu link. Add Menu link title and select Parent item where you want to add the current node.
That's it
Comment: thanks.can I do this by view module? I create a path and put it menu but does not word [in view  module]
Comment: @Kermani Sorry I don't understand. What do you mean 'does not word [in view module]' ?
Comment: Sorry that was does not work
Comment: @Kermani No problem, please add details to your post like what exactly you want and what you have tried.
Answer: There is no such thing as url of content-type in Drupal. However, you may be looking for:

default URL template for content type is at http://example.com/admin/config/search/path/patterns
URL of particular node is configured on URL path setting tab in node edit form.
Menu link, as described in another answer.

And if you want a listing
of nodes from a content type, taxonomy term, or anything like that, use Views. Views allows you to create listing pages, with (almost) any URL you want for them.
Answer: You need to do two things if I understand you correctly.
You need to set up Pathauto patterns for your content, and you need to set up a few views.
Pathauto:
You can get really complicated with this, but as you are just starting do it the easy way.
Go to: admin/config/search/path/patterns
This will show you the pathauto pattens page. In the section content paths, for each of your content types add something like the following:
CONTENT_TYPE_OR_CATEGORY/[node:title]

So, for sports content or category type you will add:
sports/[node:title]

This means that when you create a new sports node it will get a URL alias that is a combination of the category and the title of the node.
Make sure to go to the Pathauto tab: Delete aliases, and delete all content aliases. Then go to Bulk Generate tab and generate content aliases before you continue.

Views:
When you navigate to 'sports/ronaldos-regimen' it will take you to that article, but what if you just type in 'sports' as the URL. You probably want to have a list of articles of type sports.
For each of your content types you create a view. (if you have a lot of different content types this will not work and you will have to use contextual filters, but for now lets assume you only have 5 or 6 different content types).
For sports you set:

the view's Title to 'Sports'
the path to 'sports'
the Menu to 'Sports', and set the menu it must appear in to main
menu.
add a Filter Criteria of Content:type, and set it to sports type

Do the same for all the views (you can make sure your sports view is to your liking then clone the view for the other categories and make changes)

How to find url of content-type?


How to parse POST request in JSON format in rails

Question: I'm trying to send a POST request in JSON via curl in ruby on rails. I would like to know how can I parse this request in a controller and save it in database. I've created controller and model for a player.
Below is the curl command -
curl -i -X POST -H "Content-Type: application/json" "localhost:3000/app/v2/player" -d '{
"url": "app/v2/players.json",
"para": {
    "player": {
        "player_id": 51275,
        "email": "firstname.lastname@example.com",
        "total_won": "1890000.00",
        "pr_costs": "29.00",
        "payment_method": "VISA",
        "games": [
            {
                "name": "AvsB",
                "matches": 1,
                "value": 1100,
                "category": "Cricket",
                "subcategory": "Test",
                "tags": [
                    "Aus",
                    "Melbourne"
                ],
                "game_id": 12
            },
            {
                "name": "CvsD",
                "matches": 1,
                "value": 790,
                "category": "Cricket",
                "subcategory": "T20",
                "tags": [
                    "T20",
                    "20over",
                    "worldcup"
                ],
                "game_id": 7
            }
        ]
    }
}
}'

Below is my player controller-
module App
module V2
    class PlayersController < ApplicationController

  def create

    @player = Player.new(params[[:para][:player][:player_id]].first)
    if @player.save
        render json: @player, status: 201, location: @player

    else
        render json: @player.errors, status: 422
    end
  end

private

def player_params
  #params.require(:player).permit(:url, :player_id, :email, :total_won, :pr_costs, :payment_method)
  params.fetch(:url,:para, {}).permit(:player_id, :email, :total_won, :pr_costs, :payment_method)

end
    end
end
end

Below is my player model -
class Player < ActiveRecord::Base
has_many :games, dependent: :destroy
validates :player_id, presence: true
attr_accessor :url,:para

end

Currently I'm getting below error while initiating the curl command -
 TypeError (no implicit conversion of Symbol into Integer):
 app/controllers/app/v2/players_controller.rb:21:in `[]'
 app/controllers/app/v2/players_controller.rb:21:in `create'

Any pointers on how I can read JSON data and create records for players in create function and related games would be appreciated. I've not created the model for games but it'll be similar in structure to JSON data. Also one player has many games and a game will belong to a Player.
Thanks in advance!
Comment: why do you have an extra `[]` in the `params`
try `params[:para][:player]`
Answer: This is badly structured.
[[:para][:player][:player_id]]

It basically means (in part) there's an array that contains the player symbole
[:player]

and you want to get the ':player_id(th)' entry of that array or string... which is where you're getting the error ("How do I convert a symbol into an integer for the array?")
[:player][:player_id]

you probably want...
params[:para][:player][:player_id]

There's no 'first' because there's no array in the :player_id entry.
Comment: if I use `@player = Player.new(params[:para][:player][:player_id])` , I get an error that says `ArgumentError (When assigning attributes, you must pass a hash as an argument.):
  app/controllers/app/v2/players_controller.rb:21:in `create' ` Could you please advise what I am doing wrong here ?
Comment: drop `[:player_id]` as that's just one element.  If you drop it, you're now passing a hash.  You'll probably get another error because you're passing additional parameters that aren't useful but we'll have made progress
Comment: Or do a comprehensive `player_params` method (reinstate `require`) and then reference `player_params` instead of the params directly.
Comment: Thank you, but how do I write my player_params method to permit parameters. The one that I've written clearly doesn't represent my json structure. `params.require(:player).permit(:url, :player_id, :email, :total_won, :pr_costs, :payment_method)`, and it doesn't include games as well. Any pointers will be helpful!
Comment: Is 'games' an ActiveRecord table?  There's a many-to-one between `games` and `players`?
Answer: As it always happens, I figured it out myself. Below is what I used for player_params function. There could be other ways as well, but this certainly worked for me.
params.require(:player).permit(:url,:para =>[:player =>[:player_id, :email, :total_won, :pr_costs, :payment_method,:games =>[:name, :matches, :value, :category, :subcategory, :game_id ]]])

@SteveTurczyn thanks for pointing me in the right direction


Limit of $\sin(\pi \sqrt{4n^2+n})$

Question: We can notice that $\sqrt{4n^2 + n} = \sqrt{4n^2(1+ \frac{1}{4n})} = 2n\sqrt{1+\frac{1}{4n}}$. Therefore
$$\lim_{n \to \infty} \sin (2n\pi \sqrt{1+ \frac{1}{4n}}) \text{ will be an even number}$$
Because the square root becomes $1$ and we end up with an even number: $\sin(\text{even number})$
And sine of an even number is $0$. But apparently that is not the right answer.
Comment: See https://math.stackexchange.com/q/1372176/394456
Comment: The reasoning is wrong because the linear part of $\sqrt{4n^2+n}$ is absorbed by the sine, and a constant term remains.
Comment: Thanks for the link
Comment: @YvesDaoust I do not understand what you mean. What linear part? Thanks
Comment: Find the oblique asymptote of $\sqrt{4n^2+n}$.
Answer: When $n\to\infty$, we have
$$
\sqrt{4n^2+n} = 2n\sqrt{1+\frac{1}{4n}}
= 2n\left(1+\frac{1}{8n} + o\!\left(\frac{1}{n}\right)\right)
= 2n + \frac{1}{4} + o(1) \tag{1}
$$
using the Taylor expansion of $\sqrt{1+x}$ for $x$ around $0$. Recalling that $$\forall a,b,\qquad \sin(a+b)=\sin a \cos b + \cos a \sin b \tag{2}$$ we get
$$\begin{align*}
\sin(\pi\sqrt{4n^2+n}) &=\sin\left(2n\pi + \frac{\pi}{4} + o(1)\right) \\
&= \sin(2n\pi) \cos\left(\frac{\pi}{4} + o(1)\right)
+ \cos(2n\pi) \sin\left(\frac{\pi}{4} + o(1)\right) \\
&= 0 + \sin\left(\frac{\pi}{4} + o(1)\right) \\
&\xrightarrow[n\to\infty]{} \sin\frac{\pi}{4} = \boxed{\frac{1}{\sqrt{2}}}
\end{align*}$$
using continuity of $\sin$ (as $\frac{\pi}{4} + o(1)\xrightarrow[n\to\infty]{}\frac{\pi}{4}$).
Comment: To the downvoter: why? Any reason for the downvote?
Comment: Welcome to the club of the victims of mysterious downvotes and +1.
Answer: Consider that
$$\sin(\pi\sqrt{4n^2+n})=\sin(\pi\sqrt{4n^2+n}-2\pi n)=\sin\left(\frac{\pi n}{\sqrt{4n^2+n}+2n}\right)\to\sin\frac\pi4.$$
Comment: @Ahmad: the limit for reals doesn't exist and is just uninteresting.
Comment: Because, implicit in the question is the fact that $n$ is an integer. (First, notation-wise, $n$ is usually used to denote integers, and $x$ reals; second, because otherwise the OP's sentence about even numbers cannot be interpreted at all.) @Ahmad
Comment: What about $n = \frac{-1 +\sqrt{1+16k^2}}{8}$ for all $ k \in \mathbb{N}$, for which we have that $sin( \pi \sqrt{4n^2 +n}) = \sin (\pi k) = 0$ ?
Comment: @Ahmad Is this $n$ you define an integer, for $k\in\mathbb{N}$?
Comment: why is the limit consider just the integer cases ? why not all of $\mathbb{R}$ ?

Limit of $\sin(\pi \sqrt{4n^2+n})$


Need a hint: Prove / Disprove: There is an entire function $f(z)$ so that for every $z \in \mathbb C$, $z=x+iy$, $|f(z)|=e^{-x^2-y^2}$

Question: Need a hint: Prove / Disprove: There is an entire function $f(z)$ so that for every $z \in \mathbb  C$, $z=x+iy$, $|f(z)|=e^{-x^2-y^2}$.
Any hint or direction on how to think on this type of questions will be of great assistance.
Thank you!
edit:
Solution I thought of, not sure if correct.
Assume such entire $f$ exists, so that $|f(z)|=e^{-x^2-y^2}=e^{-(x^2+y^2)}$. Let $C_R$ be a circle centered at $z=0$ and with radius $R$. Assume WLG $R>1$. So $f$ is holomorphic there, and non-constant. So by the maximum principle we get that $max |f(z)|$ is obtained when $|z|=R$, so $\sqrt {x^2+y^2}=R$. So $max |f(z)|=e^{-R^2}$, but we know that $z=1 \in C_R$ and it is clear that $e^{-R^2} \lt e^{-1}$, so $e^{-R^2}$ is not the maximum. Contradiction. So such $f$ does not exist.
Comment: .....Liouville?
Comment: What are x and y? The real and imaginary part of z?
Comment: I guess so, the original question doesn't include that either.
Comment: So can I just say $|f(z)| \leq 1$ so it is constant, but for $z=1$ and $z=2$, $|f(1)| \neq |f(2)|$, contradiction for $f$ being constant?
Answer: It can be seen that $f(z) \neq 0$ for all $z$, hence an analytic branch of $\log f$ can be defined, with real part $$ \log |f(z)|=-x^2-y^2 .$$
Since the real part of an analytic function has to be harmonic we see that such $f$ doesn't exist.
Answer: Solution I thought of, not sure if correct.
Assume such entire $f$ exists, so that $|f(z)|=e^{-x^2-y^2}=e^{-(x^2+y^2)}$. Let $C_R$ be a circle centered at $z=0$ and with radius $R$. Assume WLG $R>1$. So $f$ is holomorphic there, and non-constant. So by the maximum principle we get that $max |f(z)|$ is obtained when $|z|=R$, so $\sqrt {x^2+y^2}=R$. So $max |f(z)|=e^{-R^2}$, but we know that $z=1 \in C_R$ and it is clear that $e^{-R^2} \lt e^{-1}$, so $e^{-R^2}$ is not the maximum. Contradiction. So such $f$ does not exist.
Comment: so by "circle" you mean "closed disc" ? also why did you use $1$ where you could have just used $0$ (which is where $|f|$ is maximal by hypothesis)
Comment: Yes. And I dunno, doesn't really matter.
Comment: yeah it's fine, it just sounds strange in the grand scheme of things.
Answer: The hypothesis says that $f$ has a removable singularity at infinity, and so is entire on the sphere. Thus it is constant—0 in fact—by Liouville, contradicting the hypothesis.


Convolution to find Pr(X +Y >1)

Question: I have been hunting around on the internet for days to find an example I can easily relate to but without successes. It would really appreciate some help with the following;
Joint pdf;
$f(x,y)=2(x+y)$ for $0<x<1$ and $0<y<x$, $0$ otherwise.
I found the conditional pdf to be;
$f(y|x)=2(x+y)/3x^2$ for $0<x<1$ and $0<y<x$, $0$ otherwise.

Question;

I now need to find;
$Pr( X + Y >= 1)$
I believe I need to sub;
$f(y|x)=2(x+y)/3x^2$, into;
$f_Z(z) =\int_{0}^z f_{Y|X}(z-x|x)f_{X}(x)\,\mathrm dx$
Which I get $f_Z(z) = 2z^2$
However I am not sure what the support for $f_Z(z)$ should be?
What is the general procedure to figure the support range out for transformations?
In a previous post it was suggested to think of the support range as $0<y<x<1$ but I haven't been able to see past this.
Note this is just a practice exam question.
Comment: Make a drawing showing the event $X+Y\ge 1$ as a region $R$ in the $x,y$-plane, then solve the double integral $\iint_R f(x,y) dy dx$.
Comment: Please add the `[self-study]` tag & read its
[wiki](http://stats.stackexchange.com/tags/self-study/info).
Comment: Well thinking about that another way, would this be correct?

$1 - PR(X+Y<1) = \int_{0}^{1}\int_{0}^{1-x} 2*(x+y) dydx = \frac{1}{3}$
Comment: By deleting your previous version of this question, you have made the comment thread inaccessible to most readers.  When you make changes, please just edit your question rather than creating new versions.  In the meantime, you will find problems *exactly* like this one solved, with extensive explanations and illustrations, at http://stats.stackexchange.com/questions/180715 and by searching for terms like [pictures of integration](http://stats.stackexchange.com/search?q=integration+picture+votes%3A1+is%3Aanswer).
Comment: Hi whuber, even with the link you have provided, I am struggling to five a comparable example. The examples I am finding are when both x and y have independent ranges. I've gotten quite frustrated with this problem as you can probably gather. Just really looking forward to a clear cut answer. Thanks...
Comment: I think the above won't work because I am not taking into account y < x. So for X + Y > 1 and y<x would the integration range be x to 1 for Y and 0.5 to 1 for X?
Answer: You have the joint distribution so you only need to integrate over the region desired for the given probability. That region looks like this:

The shaded area fulfills the conditions you are looking for, specifically
$$Pr(X+Y\geq1)=\int_{.5}^{1}\int_{1-x}^{x} 2(x+y) dydx \approx .6667$$
Edit:
I am using the image to conceptually understand the boundaries of $x$ & $y$ for the desired probability. This means that the red region contains all of the possible values of $x$ & $y$ as if $0<x<1$, $0<y<1$. Although we want $y<x$ so $y$ can only come arbitrarily close to $x$ (so $x$ is our upper bound for $y$). Since we always want $x+y>1$, then we need $y>1-x$ (our lower bound for $y$). We know that $y<x$, so the only possible values of $x+y>1$ are when $x>.5$ (our lower bound for $x$). Then $x$ can be up to $1$ (our upper bound).
Comment: (1) Could you explain the relevance of shading the entire unit square?  (2) I suspect the OP might appreciate an explanation of how you found the integration region, because that seems to be the conceptual block behind the question.
Comment: Hi Travis thanks for taking the time to answer. I've got a firmer grip on how to go about these questions now. Thank you for your time.

Convolution to find Pr(X +Y >1)


Creating a menu based on cck field

Question: I would like to build a custom menu structure based on cck fields.
lets say I have 2 fields in which I will type the menu item.

parent item = field_category
child item= field_subcategory

So in a node create form i use for 'field_category' apples or pears and for 'field_subcategory' green or red.
These items will also be made terms(i have a 3rd field containing tags that are equal to all menu items)
my menu structure is like:

apples

green
red

pears

green
red

my terms are: apples, pears,red, gree.
Then part 2:
These items must be linking to a term or multiple terms.

apples --> links to term apples

green --> links to term apples AND green
red --> links to term apples AND red

pears

green
red

I suspect i wuould need a custom module to do so, but i am not a programmer...so I really hope someone has a solution with contrib.
Comment: I'm not confident enough to create an answer of this, but I believe the Views module may be exactly what you're looking for. Resource: http://nodeone.se/sv/node/20
Comment: Please always mention or tag your posts with version numbers.
Answer: If you're only concerned about taxonomy term fields, then I reckon that you should investigate the taxonomy_menu or similar family of modules. In fact, looking at your other post, I suggest that you go through the entire list of taxonomy modules on Drupal in general :)
Comment: problem with taxonomy menu = I can create term on the fly into parent/child relation. taxonomy menu does not work for me on this one because it needs to have some pre-created struture.

Creating a menu based on cck field


Static Frontpage

Question: I'm a seasoned front-end developer and extremely new to Drupal.
I've just created a new instance of Drupal 8 and all I am trying to do is create a static one pager for a client who needs a simple web presence before building the full Drupal8 site in the new year.
Using a purchased theme, all I need is to create and route a static homepage, but I'm not sure where to begin.
Can someone point me in the right direction.
Thanks
Answer: Add a node of the type page and fill it with the static html:
/node/add/page

Then go to
/admin/config/system/site-information

and configure the "Default Front Page". If the page you've created earlier is the first node, then this is /node/1.
Comment: Thanks 4k4, I've seen this already, I was thinking there might have been a different way in doing this, but if this is the best way, then great!
Comment: That's how you do it in UI. You can do more adjustments in the theme in a page template with the name `page--front.html.twig`. You could use this also for static html.
Comment: Also the Drupal 8 User Guide has a chapter that goes over content creation and setting it to the front page: https://www.drupal.org/docs/user_guide/en/content-chapter.html
Answer: I'd say the easiest way to make a static (but CMS editable) frontpage is to make a Basic Page node (page) and set that URL at the frontpage in the CMS settings (admin/config/system/site-information). For example, node/1.
We tend to do this with a dedicated custom node type so that we can add extra fields (eg an image field that can be styles for a carousel, or entity references for promoting frontpage blog posts, etc).
Comment: Thanks NIck, same as 4k4's answer and again, if this is the best way then thanks. Going to mark his as correct answer as he was first to answer. So close :)
Comment: Heh - he beat me to it by a minute :)

Static Frontpage


Some hint to prove that $\ell^{1}$ with $\ell^{\infty}$ norm is Banach space?

Question:
I need show that $l^{1}$ with $l^{\infty}$ is normal space and Banach
   space.

For Normal space, I arguing about that $\ell^{1}$ norm and $\ell^{\infty}$ is equivalent.
For Banach space: I try show that $\ell^{1}$ is closed in $\ell^{\infty}$.
But am not sure the right way of proof.
Please give me a hint about intuition how to prove them.
Answer: You can't do that, because $\ell^1$ is not closed in $\ell^\infty$. The sequence $x=\left(\frac1n\right)_{n\in\mathbb N}$ belongs to $\ell^\infty\setminus\ell^1$. But, if, for each $n\in\mathbb N$, $x_n$ is the sequence$$1,\frac12,\frac13,\ldots,\frac1n,0,0,\ldots,$$then $(\forall n\in\mathbb N):x_n\in\ell^1$ and $\lim_{n\to\infty}x_n=x$ in $\ell^\infty$.


Negation of quantified expressions

Question: Can someone explain the difference between ¬∀x P(x) and ∀x ¬P(x), and also why
¬∀xP (x) ≡ ∃x ¬P (x) can't be written as ¬∀x P(x) ≡ ¬∃x P(x) and vice versa.
Thanks.
Answer: Let the universe of discourse be bricks, that is, all our quantifiers are over the set of all bricks ($x$ is a brick). Let $P(x)$ be the statement that $x$ is red.
$\neg \forall x P(x)$: not all bricks are red,
$\forall x \neg P(x)$: all bricks are not red.
It should be apparent that the first statement is true but the second is false. However, the first statement is equivalent to
$\exists x \neg P(x)$: there is a brick that is not red,
but not
$ \neg \exists x P(x)$: there is not a red brick.
These statements are obvious once written out in plain English instead of possibly unfamiliar symbols.
Comment: I'm glad you understand it! Note that I purposefully left the explanation vague so the reader must supply it.
Comment: Yeah, it took me a while to get my head around the first two.
Comment: Thankfully it seems like you understand English to the point where the subtle syntactic differences in those sentences still holds meaning to you.

Negation of quantified expressions


How do I create a grouped exposed filter on a block?

Question: I have both a "Galery" content type and a "Galery category" taxonomy. The taxonomy only has two terms, 'Video' and 'Photo' (picture).
When I create a Galery content type, I need to choose the galery category.
I created a view that would display an exposed form, that would allow the user to either pick one of the 2 available categories. A colleague helped me setting up a grouped search and customizing it. Here is how it looks:

However, when testing it, we realized nothing was displayed. Moreover, the <Any> choice does display everything, so I think I've wrongly set something.
If this helps, I'm using "better exposed form" with the "autosubmit" and "use ajax" functions enabled.
What is happening and how should I fix it?
Thank you in advance
Answer: In your view, make sure your exposed filter is not the gallery type field itself, but 'Has taxonomy term' filter with the taxonomy group vocabulary selected and then set the exposed grouped filters the same way.
Answer: Without trying to recreate your grouped search, I think it might be a logic error where your search will show all the results for Label <Photo> is one of "Photo" taxonomy term AND Label <Video> is one of "Video" taxonomy term.
What happens if you combine both of them into one item, where Label <Type> is one of "Photo" OR "Video" taxonomy terms? (If necessary, you can allow users to search both terms at once by allowing multiple selections on the single exposed taxonomy filter.)
Comment: I had to dig a little but I made it work, thanks!