Indecomposable vector space

Question: Let us define $V$ as a quotient space $\mathbb{K}[t]/(p^m)$, where $p$ is an irreducible polynomial. Condsider the linear operator $\phi\in Hom_{\mathbb{K}}(V,V)$, which sends each $q+(p^m)$ to $tq+(p^m)$.
I want to prove that there are no such subspaces $V_1,V_2\subset V$ that $\phi(V_i)\subset V_i$ and $V_1 \bigoplus V_2=V$.
First, I tried to show that there are no subspaces, invariant under $\phi$ (we admit $m\ge2$), but it is not true (really, $\{p^{m-1},tp^{m-1},t^2p^{m-1},...\}$ generates an invariant subspace $\ne V$).
Could you give me any hint?
Answer: You can compute all $\phi$-invariant subspaces.
Assume that $W$ is $\phi$-invariant. Then $W$ is actually an ideal of $V$.
In fact for $q\in \mathbb{K}[t]$ we have that $qW=q(\phi)(W)\subset W$.
Let $p^k$ be the smallest power of $p$ that divides all elements of $W$.
Then there is $p^kf\in W$ such that $(f,p)=1$. This implies that $(f,p^m)=1$. Using Euclid's algorithm there are $a,b\in \mathbb{K}[t]$ such that $fa+p^mb=1$. Therefore $p^k=p^k(1-p^mb)=p^kfa\in W$. This shows that $W$ is the ideal generated by $p^k$.
But now the result follows be cause all the $\phi$-invariant subspaces of $V$ are nested $\{0\}\subset p^{m-1}V\subset p^{m-2}V\subset...\subset pV\subset V$.
Therefore, the only way to choose two of them with intersection only at $0$, is $V=V\oplus \{0\}$.

Indecomposable vector space


Why is minimize_scalar not minimizing correctly?

Question: I am a new Python user, so bear with me if this question is obvious.
I am trying to find the value of lmbda that minimizes the following function, given a fixed vector Z and scalar sigma:
def sure_sft(z,lmbda, sigma):
     indicator = np.abs(z) <= lmbda;
     minimum = np.minimum(z**2,lmbda**2);
     return -sigma**2*np.sum(indicator) + np.sum(minimum);

When I pass in values of lmbda manually, I find that the function produces the correct value of sure_stf. However, when I try to use the following code to find the value of lmbda that minimizes sure_stf:
minimize_scalar(lambda lmbda: sure_sft(Z, lmbda, sigma))

it gives me an incorrect value for sure_stf (-8.6731 for lmbda = 0.4916). If I pass in 0.4916 manually to sure_sft, I obtain -7.99809 instead. What am I doing incorrectly? I would appreciate any advice!
EDIT: I've pasted my code below. The data is from: https://web.stanford.edu/~chadj/HallJones400.asc
import pandas as pd
import numpy as np
from scipy.optimize import minimize_scalar

# FUNCTIONS

# Calculate orthogonal projection of g onto f
def proj(f, g):
    return  ( np.dot(f,g) / np.dot(f,f) ) * f

def gs(X):

    # Copy of X -- will be used to store orthogonalization
    F = np.copy(X)

    # Orthogonalize design matrix
    for i in range(1, X.shape[1]):            # Iterate over columns of X
        for j in range(i):                    # Iterate over columns less than current one
            F[:,i] -= proj(F[:,j], X[:,i])    # Subtract projection of x_i onto f_j for all j<i from F_i

    # normalize each column to have unit length
    norm_F=( (F**2).mean(axis=0) ) ** 0.5     # Row vector with sqrt root of average of the squares of each column
    W = F/norm_F                              # Normalize

    return W

# SURE for soft-thresholding
def sure_sft(z,lmbda, sigma):
    indicator = np.abs(z) <= lmbda
    minimum = np.minimum(z**2,lmbda**2)
    return -sigma**2*np.sum(indicator) + np.sum(minimum)

# Import data.
data_raw =  pd.read_csv("hall_jones1999.csv")

# Drop missing observations.
data = data_raw.dropna(subset=['logYL', 'Latitude'])

Y = data['logYL']
Y = np.array(Y)
N = Y.size

# Create design matrix.
design = np.empty([data['Latitude'].size,15])

design[:,0] = 1
for j in range(1, 15):
    design[:,j] = data['Latitude']**j

K = design.shape[1]

# Use Gramm-Schmidt on design matrix.
W = gs(design)
Z = np.dot(W.T, Y)/N

# MLE
mu_mle = np.dot(W, Z)

# Soft-thresholding
# Use MLE residuals to calculate sigma for SURE calculation
sigma = np.sqrt(np.sum((Y - mu_mle)**2)/(N-K))

# Write SURE as a function of lmbda
sure = lambda lmbda: sure_sft(Z, lmbda, sigma)

# Find SURE-minimizing lmbda
lmbda = minimize_scalar(sure).x
min_sure = minimize_scalar(sure).fun #-8.673172212265738

# Compare to manually inputting minimized lambda into sure_sft
# I'm s
act_sure1 = sure_sft(Z, 0.49167598, sigma) #-7.998060514873529
act_sure2 = sure_sft(Z, 0.491675989, sigma) #-8.673172212306728

Comment: can you reproduce the error in code which we can run?
Comment: I believe you mean `scipy.optimize.minimize_scalar` right?
Comment: I imported at the very top of my code:
    from scipy.optimize import minimize_scalar
Answer: You're actually not doing anything wrong. I just tested out the code and confirmed that lmbda has a value of 0.4916759890416824 at the end of the script. You can confirm this for yourself by adding the following lines to the bottom of your script:
print(lmbda)
print(sure_sft(Z, lmbda, sigma))

when you run your script you should then see:
0.4916759890416824
-8.673158394698172

The only thing I can figure is that somehow the routine you were using to print out lmbda was set up to only print a fixed number of digits of floating point numbers, or somehow the printout was otherwise truncated.


Why does matrix condition number change drastically when a constant is added?

Question: If I create a regression model design matrix with 3 uncorrelated variables, I get a small condition number as expected. MWE:
<code>> import numpy as np, pandas as pd
> n = 1000
> X = pd.DataFrame()
> X['x1'] = np.random.normal(size=n) * 500
> X['x2'] = np.random.normal(size=n) * 200
> X['x3'] = np.random.normal(size=n) * 300
> print(np.linalg.cond(X))

2.4566193714711306
</code>
But if I add a constant to the design matrix (as expected in python statsmodels), my condition number blows up:
<code>> import numpy as np, pandas as pd
> n = 1000
> X = pd.DataFrame()
> X['x0'] = [1] * n
> X['x1'] = np.random.normal(size=n) * 500
> X['x2'] = np.random.normal(size=n) * 200
> X['x3'] = np.random.normal(size=n) * 300
> print(np.linalg.cond(X))

497.654501825216
</code>
Accordingly, I have an extremely high condition number and warning of multicollinearity when I estimate my model even though none of my predictors (or constant) are correlated. Why does the design matrix's condition number change drastically when a constant is added?
Comment: I wonder what happens when you drop all the "00" from the scaling constants :-).
Answer: Combining several questions/comments, I believe I have the answer. This is just a scaling problem.
The condition number is the ratio of the largest eigenvalue in the design matrix to the smallest. This large condition number results from scaling rather than from multicollinearity. If we have just one variable with units in the thousands (ie, a large eigenvalue) and add a constant with units of 1 (ie, a small eigenvalue), we'll get a large condition number as the ratio (and statsmodels warns of multicollinearity because it has a sensitive threshold and uses the unstandardized design matrix for calculating the condition number).


How to use function with variables in javascript

Question: How to use function with variables in JavaScript:
function incrementValue()
{

    var date = new Date();
    var lr = "LR";
    var citycode = '<?php echo $citycode; ?>';
    var branchcode = '<?php echo $brcode; ?>';
    var Month = ("0" + (date.getMonth() + 1)).slice(-2);

    var year = ((date.getFullYear().length) === 1)? (date.getFullYear()) : 0  + (date.getFullYear() %100);
    var cdate = ("0" + date.getDate()).slice(-2);
    var value = parseInt(document.getElementById('lro').value);
    value = isNaN(value) ? 0 : value;
    value++;
    document.getElementById('lro').value = citycode + lr + year + Month +    cdate + branchcode + value;

}

My php file button code:
<input type="submit" onclick="incrementValue()" name="save123"  value="save" class="btn green">

I'm getting some error on script.
Comment: What are the errors that you get ?
Comment: Use your browser console to find out errors
Comment: Please show us the errors. We can't help you if you don't show us all the info.
Comment: If i'm remove the function tag the script is works fine. if i am use the script it shows nothing.
Answer:
If i'm remove the function tag the script is works fine. if i am use the script it shows nothing.

Putting it in a function means nothing will happen until you call the function.
You call the function when a submit button is clicked.
Clicking a submit button will also submit the form.
Submitting a form will load a new document … which will erase the DOM changes you made.
It sounds like you should be moving your logic server side.


How to find volume of the region $\{(x,y,z)|\,0 \le (x-1)^2+y^2 \le z(1-z)\}$?

Question: I need to find the volume of the region :
$$R=\{(x,y,z)| \space 0 \le (x-1)^2+y^2 \le z(1-z)\}$$
I don't understand the region. Is it the volume outside the cylinder and inside a sphere? Can you give me some hints in order to set up the integral?
Answer : $\frac{\pi}{6}$
Comment: It looks like you have a sphere.  Expand the right side, bring the $z$ terms to the other side, complete the square, and you will have what is recognizably the equation of a sphere.
Answer: The left inequality is always true for sum of squares is greater than zero.
The right inequality represents a sphere of radius $\frac{1}{2}$.  Hence the volume of the region is $\frac{4}{3}\pi(\frac{1}{2})^3 = \frac{\pi}{6}$.


What is the proper way to compare discrete set of data to a continuous probability distribution?

Question: I have a set of data points that I an trying to approximate with a few different probability distributions such as the gaussian or student t distributions to see which fits best.
The first step to doing this is plotting the distribution of points themselves. As per my last question, I centered the points around zero and normalized the variance = 1. Now I would like to plot these points to compare to continuous distributions. How does one do this?
I am currently using a histogram method in which I split up the points into $x$ buckets and plot the height of each bucket. Now I realize this doesn't make sense because the resulting distribution of points in the histogram is entirely dependent on the value I choose for $x$.
What is the proper way of doing this? There must be a fundamental concept I'm missing.
Answer: It sounds to me like your primary difficulty is in binning the data properly.  Please pardon me if this is not your question.
You want the total area of the rectangles comprising the histogram to be 1.  If you take rectangle height to be the number of data points in the corresponding bin, then the total area will not be 1.  Instead, you will have
$$
\text{area}=(\text{bin width})\times(\text{total number of data points)}.
$$
The general principle for handling distributions of binned data properly - which even allows you to deal with variable-width bins - is that rectangle area, rather than rectangle height, should be proportional to the number of data points in the bin.  For the fixed-width case, the height of each rectangle should be computed as
$$
\text{height}=
\frac{(\text{number of data points in bin})}{(\text{total number of data points})\times(\text{width of bin})}.
$$
If you follow this procedure, then, within reason, the resulting distribution should be relatively insensitive to the number of bins you decide to use.  Of course, if you use too many bins, most bins will be empty and you'll get a very spiky distribution, which won't be very illuminating.  If you use too few bins, the distribution will be too coarse-grained.  The Wikipedia page on histograms describes some commonly used rules, such as Sturges' formula, for deciding how many bins to use.
For testing goodness of fit, you should follow the suggestions in Michael Chernick's answer.
Answer: Problems like this have been discussed many times.  There are numerous goodness of fit tests to use.  When you bin the data the chi square test is the test to use.  The idea is that you have a distribution that should have frequencies close to those observed from the data.  The hypothesized distribution should exhibit close agreement with the data in terms of the bin frequencies.  The test decides this by computing for each bin the squared difference of the observed with the expected dividing it by the expected and summing over all the bins.  When the distribution hypotheses is the distribution sampled the test statistic has an approximate chi square distrbution.
Answer: If all you need is an estimate, there are numerous ways to go about it. One such way would be to produce a Q-Q plot of the data vs. the expected distributions (normal, t, etc.). If you are wondering if the data is a normal, you could run Shapiro-Wilk test as well.
Both of these methods are very easy to implement in R or SAS (R is free with open-source code that is easy to find at http://cran.r-project.org/


JSP, JSTL, Check NaN

Question: I have a JSP in which I am using <fmt:formatNumber>. The problem is that we don't know that the value coming to JSP will be a number or a String. If a string is coming it throws NumberFormatException.
I tried to look in JSTL, but no success, somewhere it was mentioned if I check value == value it returns false if String but no success. Please see the code below.
<fmt:formatNumber type="currency" currencySymbol="$" maxFractionDigits="2" minFractionDigits="2" >${primary.value}</fmt:formatNumber>

Any help would be appreciated.
Thanks in advance.
Comment: It would help if you included more code so that the problem can be seen in context.  Also, why do you not have control over what the value is?
Comment: The value is coming from different vendor which is why we don't have any control
Comment: Possible duplicate of http://stackoverflow.com/questions/12482062/check-string-for-only-numbers-using-jstl
Answer: This might be a solution to your problem. You'll get an exception when you try to add a String to 0.
<c:catch var="catchString">
  <c:set value="${0 + primary.value}" />
</c:catch>
<c:choose>
<c:when test="${not empty catchString}">
  ${primary.value}
</c:when>
<c:otherwise>
  <fmt:formatNumber type="currency" currencySymbol="$" maxFractionDigits="2" minFractionDigits="2" >${primary.value}</fmt:formatNumber>
</c:otherwise>
</c:choose>

Comment: It worked...but do we have any other solution..I am asking so coz we have around 30 such fields..If you can suggest any JSTL or anything like that,then number of code lines would be less.
Comment: Can you not put those fields in a loop?
You could use a ternary to get rid of the c:choose-tag.
Comment: I am using below mentioned less code      `
${primary.value}

       ${primary.value}
     `
Answer: Another solution is to create a custom tag library to check wether you're dealing with a String or with a number, or even to manually format your number (your choice).
I don't have time to work out the example for you but I found this
Tutorial
where they explain step by step on how to implement everything.
Edit: More info @Oracle
I hope you get it to work, if not let me know and I'll try to help you out tomorrow.

JSP, JSTL, Check NaN


NGINX 22.214.171.124/Debian 8 - custom installation, client_temp a file rather than a directory

Question: I've run into a weird issue.  I have a custom configured and compiled version of NGINX (I wanted a couple extra compile time modules installed).  For whatever reason, it's creating client_temp as a file rather than a directory, and that's causing a 500 internal server error whenever I try uploading a file.
My configuration:
--prefix=/opt/nginx --sbin-path=/usr/local/sbin/nginx
--conf-path=/opt/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=www-data --group=www-data
--with-http_ssl_module --with-http_realip_module
--with-http_gunzip_module --with-http_gzip_static_module --with-threads --with-file-aio
--with-ipv6 --with-http_v2_module
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m64 -mtune=native' --add-module=../ngx_cache_purge-2.3
--add-module=../headers-more-nginx-module --add-module=../ModSecurity-nginx

As you can see, I do specify a path for client_temp: --http-client-body-temp-path=/var/cache/nginx/client_temp, yet it's a file rather than a directory.
Do I need to manually create client_temp as a directory and remove the file?  Or is there another way to remedy the situation?
Comment: Create the directory first, and set any permission as needed.  Then try it.
Comment: Glad that worked for you. I have answered the question below.
Comment: That did the trick!  I'll upvote/mark as answer if you wish to turn the comment into an answer post
Answer: In these cases, its sometimes easier/better to create the client_temp directory first, and set its permissions/ownership, and then launch the Nginx service.  This will insure the folder exists, and its permissions set is appropriate for accepting uploaded files.

NGINX 1.1.3.3/Debian 8 - custom installation, client_temp a file rather than a directory


all positive integers satisfying the following series

Question:
Find all positive integers $n>1$ such that the following series is divisible by $n$:
  $$1^n + 2^n + 3^n + \ldots + (n-1)^n.$$

I started with considering separate cases for even and odd values of $n$ but couldn't make any progress, and on searching I found following conjecture:

If $n$ is a prime, then
  $$n \mid 1^{n-1}+2^{n-1} + \ldots + (n-1)^{n-1} + 1,$$

but I am not able to understand the proof.
It seems the above is by fermat
Comment: Welcome to MSE. Your question is phrased as an isolated problem, without any further information or context. This does not match [many users' quality standards](http://goo.gl/mLWc8), so it may attract downvotes, or closed. To prevent that, please [edit] the question. [This](http://goo.gl/PlJyVQ) will help you recognise and resolve the issues. Concretely: please provide context, and include your work and thoughts on the problem. These changes can help in formulating more appropriate answers.
Answer: Suppose $n$ is odd. Consider the sum modulo $n$. Then
$$(n - k)^n \equiv (-k)^n \equiv (-1)^n k^n \equiv -k^n.$$
So, each term of the sum pairs uniquely with another term of the sum which is its negative. So, when $n$ is odd, the sum should be $0$ modulo $n$, i.e. divisible by $n$.
Otherwise, consider the case where $n$ is even. Then $n = 2^km$ for some odd $m$, and positive integer $k$. Consider the sum modulo $2^k$. Note that $k \le n$, hence if $r$ is an even number between $1$ and $n - 1$, then $2^k \mid r^n$.
Otherwise, if $r$ is an odd number in the range $1$ to $n - 1$. Then $r^n$ is odd, and there are an odd number of such terms. So, adding all the terms modulo $2^k$, we obtain an odd number, implying that the sum cannot be $0$ modulo $2^k$, and hence it can't be $0$ modulo $n$.
Therefore, the sum is divisible by $n$ if and only if $n$ is odd.


Using an appserver.io SessionBean in a plain php script

Question: I am looking for a way to replace select functionality in an existing application with appserver.io SessionBeans, but I fail to find an example on how to access a SessionBean in a plain php class.
I have a super simple Singleton SessionBean from the examples:
<?php

namespace MyVendor\MyApp;

/**
 * @Singleton(name="MySingletonBean")
 */
class MySingletonBean extends \Stackable
{
    protected $counter = 0;

    public function raiseMe()
    {
        return $this->counter++;
    }
}

Implementation inside a Servlet is pretty straight forward and works like a charm, but I can't find any documentation on getting access to this in a plain php file outside a Servlet.
I'd expect it so be rather simple like:
<?php

use MyVendor\MyApp\MySingletonBean;

class IndexController extends App
{
    /**
     * maybe some funky annotations...
     *
     * @var \MyVendor\MyApp\MySingletonBean
     * @EnterpriseBean(name="MySingletonBean")
     */
    protected $mySingletonBean;

    public function index() {

        // and then servlet style...
        echo $this->mySingletonBean->raiseMe();

        // ... or like this?
        echo MySingletonBean::getInstance()->raiseMe();
    }
}

Can someone please point me into the right direction?
Thank you,
Peter
Answer: As SessionBeans exists as real PHP objects inside the container it is not possible to access them from e. g. a PHP-FPM application. To do so, we've implemented a client, that returns a proxy to the session bean and allows you to execute it's methods. Additional it is necessary to configure the persistence container itself, because by default, we've deactivated remote connections for security reasons.
So, the first thing you should do, is to install the appserver-io/rmi package as Composer requirement in your project, e. g.
$ composer install appserver-io/rmi

after that, you've to configure a server, that allows remote access to the persistence container, e. g. you can add the following XML snippet to the <container name="combined-appserver"> in etc/appserver/appserver.xml file
<server
    name="persistence-container"
    type="\AppserverIo\Server\Servers\MultiThreadedServer"
    worker="\AppserverIo\Server\Workers\ThreadWorker"
    socket="\AppserverIo\Server\Sockets\StreamSocket"
    requestContext="\AppserverIo\Server\Contexts\RequestContext"
    serverContext="\AppserverIo\Appserver\Server\Contexts\StandardServerContext"
    streamContext="\AppserverIo\Server\Contexts\StreamContext"
    loggerName="System">

<params>
    <param name="admin" type="string">email@example.com</param>
    <param name="transport" type="string">tcp</param>
    <param name="address" type="string">127.0.0.1</param>
    <param name="port" type="integer">8585</param>
    <param name="workerNumber" type="integer">4</param>
    <param name="workerAcceptMin" type="integer">3</param>
    <param name="workerAcceptMax" type="integer">8</param>
    <param name="documentRoot" type="string">webapps</param>
    <param name="directoryIndex" type="string">index.pc</param>
    <param name="keepAliveMax" type="integer">64</param>
    <param name="keepAliveTimeout" type="integer">5</param>
    <param name="errorsPageTemplatePath" type="string">resources/templates/www/error.phtml</param>
</params>

<environmentVariables>
    <environmentVariable condition="" definition="LOGGER_ACCESS=Access" />
</environmentVariables>

<connectionHandlers>
    <connectionHandler type="\AppserverIo\WebServer\ConnectionHandlers\HttpConnectionHandler" />

</connectionHandlers>

<accesses>

    <access type="allow">
        <params>
            <param name="X_REQUEST_URI" type="string">.*</param>
        </params>
    </access>
</accesses>

<modules>

    <module type="\AppserverIo\WebServer\Modules\AuthenticationModule"/>
    <module type="\AppserverIo\WebServer\Modules\VirtualHostModule"/>
    <module type="\AppserverIo\WebServer\Modules\EnvironmentVariableModule" />
    <module type="\AppserverIo\WebServer\Modules\RewriteModule"/>
    <module type="\AppserverIo\WebServer\Modules\DirectoryModule"/>
    <module type="\AppserverIo\WebServer\Modules\AccessModule"/>
    <module type="\AppserverIo\WebServer\Modules\CoreModule"/>
    <module type="\AppserverIo\Appserver\PersistenceContainer\PersistenceContainerModule" />

    <module type="\AppserverIo\WebServer\Modules\DeflateModule"/>

</modules>

<fileHandlers>
    <fileHandler name="persistence-container" extension=".pc" />
</fileHandlers>

</server>

below the message-queue server configuration.
Finally you can connect to the persistence container and call the raiseCounter() method of the ASingletonProcessor SessionBean of our example application with
<?php

use AppserverIo\RemoteMethodInvocation\RemoteConnectionFactory;

require_once __DIR__ . '/vendor/autoload.php';

$connection = RemoteConnectionFactory::createContextConnection();
$connection->injectPort(8585);
$connection->injectAddress('127.0.0.1');
$connection->injectTransport('http');
$connection->injectAppName('example');

$session = $connection->createContextSession();
$session->setSessionId(md5('test'));
$proxy = $session->createInitialContext()->lookup('ASingletonProcessor');

echo $proxy->raiseCounter() . PHP_EOL;

The example uses a dummy Session-ID generated with md5('test) which is for testing purposes only. In a real life application you will use the default PHP Session-ID for example.
Hope that give's you an good impression how things could go :)


Is $L^p$($\Omega$) for $\Omega$ locally compact (in terms of radon measure) separable?

Question: I have read in my script, that for $\Omega$  locally compact and sigma-compact
$L^p$($\Omega$) is separable in terms of radon measure.For $\Omega$  Lebesgue-measurable $L^p$($\Omega$) is separable too, but about locally compact I didnt find any answer.
Answer: $\Omega$ locally compact does not imply that $L^p(\Omega)$ is separable. Note that the discrete topological space on any set is locally compact. Take $\Omega$ to be an uncountable set equipped with the discrete topology and define a measure on $\mathcal{P}(\Omega)$ by setting $\mu(\{x\}) = 1$ for any $x \in \Omega$.
Then $L^p(\Omega, \mu)$ is not separable. Indeed if $f \in L^p(\Omega, \mu)$ then $f$ has countable support so for any countable set $\{f_j \in L^p(\Omega, \mu) \mid j \geq 1\}$, $\mathcal{A} = \bigcup_{j \geq 1} \mbox{supp}(f_j)$ is countable and in particular there exists $x \in \Omega \setminus \mathcal{A}$. Then $g(y) = \mathbb{1}_x(y) \in L^p(\Omega, \mu)$ and it is easily verified that $g$ is distance at least $1$ from each of the $f_j$s and hence $\{f_j \in L^p(\Omega, \mu) \mid j \geq 1\}$ is not dense.
Comment: Under the given conditions $L^{p}$ need not be separable. Some comments that may throw some light on the question: if the Borel sigma algebra is generated by a countable number of sets then $L^{p}$ is separable w.r.t. any Borel sigma finite measure. In particular if the topology is second countable the conclusion holds.
Comment: @mathclear even adding the assumption that the measure is radon is not enough since $\mu$ in my answer is a radon measure.
Comment: I have edited my post , because the separability (in script) in case of
$\Omega$ locally compact and sigma compact is in terms of radon measure. So I see, that it is important to say , which measure I use .
If we look the above question under "radon measure" , then I suppose, that the space above ($L^p$($\Omega$) for $\Omega$ locally compact and radon measure) not necessary separable. Otherweise the prof. wouldn't take extra condition "sigma compact".


Best indian payment gateway which has recurring payment option

Question:  I am developing an Ruby on Rails web application which include monthly subscription in India. So if you suggest me some India payment gateway which has recurring billing option then it would be very helpful. I know paypal and recurly payment gateways are has this option but my problem is they are not accepting money in Indian currency. So now payPal updating their API which is currently accepting only US business. So please suggest me some of the payment gateway in India or any other gateways.

Suppose if I use paypal will it debit the amount in Indian Rupee or what is there payment process flow?
I am doing lot of R&D in this but please help because i'm new to payment process.

Thanks for all of your reply.
 Is that possible to make recurring payment using Indian payment gateways?
Answer: Check this payment gateway
Payza
TimesofMoney
Answer: Paypal offers the option to choose your currency.
If you choose INR (Rupees) as your currency then no matter in which currency you receive the payment, it will automatically be converted to INR and then transferred to your bank account because due to RBI regulation, Indian are not allowed to have any kind of money balance online. The conversion rates offered by Paypal are just a little lower than the market rates.
I still recommend you to go with Paypal as it is preferred by most of the people.
If you don't want to go with paypal then you can look at Payza, Skrill/money bookers, payoneer etc
Comment: Thanks for your response. check this https://www.paypal.com/cgi-bin/webscr?cmd=p/sell/mc/mc_intro-outside. i think paypal won't accept indian currency. we should make transaction only in US currency? is that true. if yes then how will they make money conversion. please help me..
Comment: They will accept payment in USD and then convert it to INR according to market rate (currently 1 usd is worth about 53 INR) and pay you in INR (Rupees).
Answer:
CCAvenue.com: Probably the biggest 3rd party player providing the best of services. Also the most expensive.
Users: Flipkart
EBS.in: Second best player. Prices can be negotiated. Preferred choice of most startups these days due to the prices and good quality.
Users: Sanjay Goel
Direcpay
ICICI Payseal
HDFC
Payu.in
Zaakpay.com
Comment: [see this too](http://www.onside.in/top-10-trusted-online-payment-gateways-for-ecommerce-websites-in-india/)
Comment: None of these support Recurring options within India


Extract the string in a struct of arrays

Question: I have a struct of arrays.
ci = tdfread(pathToData, delimiter)

disp(ci) give this
                 time: [11513x19 char]
                  bid: [11513x1 double]
            bid_depth: [11513x1 double]
      bid_depth_total: [11513x1 double]
                offer: [11513x1 double]
          offer_depth: [11513x1 double]
    offer_depth_total: [11513x1 double]

I can loop through the structure of arrays for the doubles fine, but time code below ci.time(row) just returns the first character of the string not the whole  string. How do I get the whole string per row?
foundOpen = false;
row = 1;
while(false == foundOpen)
   t = ci.time(row)
   Bid = ci.bid(row)
   Ask = ci.offer(row)
   dt = datetime(t)
   h = hour(dt)
   if h > 12
       foundOpen = true;
   end

   row = row + 1;
end

Comment: In MATLAB, passing a single subscript to an array is called [linear indexing](http://www.mathworks.com/help/matlab/math/matrix-indexing.html#f1-85511). For vectors the behavior is as expected since they only have one dimension. However, unlike the rest of your variables, `time` is a 2d array and not a vector, so in each iteration of your loop you are addressing a single value rather than the row. See MATLAB's [matrix indexing documentation](http://www.mathworks.com/help/matlab/math/matrix-indexing.html#f1-85544). You want the [`:` operator](http://www.mathworks.com/help/matlab/ref/colon.html).
Answer: Try using the colon operator:
ci.time(row, :)


Cantor-Bendixson rank of a closed countable subset of the reals, and scattered sets

Question: I am reading the notes in the following link, and I am a bit unclear about the connection between scattered sets, countable sets, and sets for which the Cantor-Bendixson derivative is eventually the empty set.
http://www.cs.man.ac.uk/~hsimmons/DOCUMENTS/PAPERSandNOTES/CB-examples.pdf
On page 3, the author says: A closed set X (of the reals) is scattered if $X^{\alpha}=\emptyset$, where $\alpha$ is the Cantor-Bendixson rank of $X$.
From what I could find, scattered means that any proper subset contains isolated points. However, for a countable subset of the reals, the Cantor-Bendixson-derivatives eventually vanish. As well, if I understand the definition of scattered correctly, a converging sequence together with its limit would be a closed, non-scattered set (the set with only the limit point in it will not have isolated points), but the CB-derivatives still eventually vanish. It seems to me that a closed set of the reals has vanishing CB-derivatives if and only if it is countable.
Am I misreading  the definition of scattered?
Comment: Don't forget that what you quoted from page 3 is about *closed* sets. A countable subset of $\mathbb R$ need not be scattered, as pointed out in Brian M. Scott's answer, but a countable closed set of reals is scattered.
Comment: So closed set of reals are scattered if and only if they are countable, right?
Comment: Yes, because the Cantor-Bendixson analysis can remove only countably many points.  So if you start with an uncountable closed set, there will be a perfect (hence uncountable) closed set of points that never get removed.
Comment: @Markus A bit OT, but do you still have the notes you link in the question. The webpage does not load anymore, and I would like to see them.
Answer: You've misunderstood a couple of things. First, it's not true that the Cantor-Bendixson derivatives of a countable set of reals necessarily vanish: every C-B derivative of $\Bbb Q$ is $\Bbb Q$, since $\Bbb Q$ has no isolated points to remove.
Secondly, a space is scattered if every subset contains at least one point that is isolated in that subset considered as a space in its own right. A simple sequence with its limit point is scattered: if the limit point is $p$, the point $p$ is isolated in the set $\{p\}$.
It's true, however, that a closed subset of $\Bbb R$ is scattered (equivalently, has vanishing C-B derivative) if and only if it is countable.
First, no uncountable subset of $\Bbb R$ is scattered. This follows from the fact that $\Bbb R$ is second countable. Let $\mathscr{B}$ be a countable base for the topology, and let $A\subseteq\Bbb R$ be uncountable. Let $$\mathscr{B}_0=\{B\in\mathscr{B}:B\cap A\text{ is countable}\}\;,$$ and let $A_0=A\setminus\bigcup\mathscr{B}_0$. Clearly $\bigcup\mathscr{B}_0$ is countable, so $A_0$ is uncountable. If $x\in A_0$, and $U$ is any open nbhd of $x$, then there is a $B\in\mathscr{B}$ such that $x\in B\subseteq U$. Clearly $B\notin\mathscr{B}_0$, so $B\cap A$ is uncountable, and therefore $B\cap A_0$ is uncountable as well. In particular, $x$ is not isolated in $A_0$. Thus, $A_0$ has no isolated points, and $A$ is not scattered.
Secondly, if $A\subseteq\Bbb R$ is countable and not scattered, then $A$ contains a countable infinite subset $A_0$ with no isolated points. Such a set is order-isomorphic to $\Bbb Q$ and therefore not closed.
Comment: @Markus: Yes, vanishing C-B derivative is equivalent to being scattered. Scattered subsets of $\Bbb R$ must be countable, and countable closed subsets must be scattered. You're welcome!
Comment: @Markus: Yes, but at that point in your question you didn't limit yourself to closed sets.
Comment: But $\mathbb{Q}$ is not closed. Doesn't the CB-derivative of a *closed*, countable set always vanish?
Comment: I see, thank you. So to make sure I understand, vanishing CB-derivative is equivalent with a set being scattered, and there are scattered (and necessarily countable), but not closed subsets of the reals (a converging sequence without the limit, for example). I guess I was confused because the author could as well have used countable instead of scattered, since he was talking about closed sets anyway. Thanks again, this was very helpful!
Comment: @BrianM.Scott: I'm having a bit of trouble seeing the equivalence between scattered and vanishing C-B derivative; I've asked a question [here](http://math.stackexchange.com/questions/1478247/vanishing-cantor-bendixson-derivative-if-and-only-if-scattered), and would really appreciate your insight. Thanks!
Comment: Isn't every C-B derivative of $\mathbb{Q}$ equal to $\mathbb{R}$?
Comment: I think I just realised the problem: your definition is different than the one in Wikipedia!
Comment: @Bcpicao: No, it isn't. What you're missing is that the Wikipedia article defines C-B rank only for **spaces**, not for subsets of spaces. Thus, the C-B rank of $\Bbb Q$ with its usual topology is computed by repeatedly taking derived sets *in the space* $\Bbb Q$, not in $\Bbb R$.
Answer: Here's a fun exercise on scattered sets: Show that a subset of the real line is scattered iff it is countable G-delta set (G-delta means countable intersection of open sets).
Comment: I've been trying to solve this for a few days but haven't had any luck, would you mind giving a hint? Brian's answer shows scattered $\implies$ countable, and I know closed $\implies G_\delta$  but can't get much further...


access to translation in form label

Question: Currently, when I create a form using the FormBuilder, Symfony (3.3.5) show me a warning in the profiler that tell me there are no translation message for the given locale.
I followed the instructions in the symfony's documentation, but the problem still persistant.
My translation file is located here: app/Resources/translations/properties.fr.yml
and my config.yml file looks like this:
parameters:
    locale: fr
framework:
    translator:
        fallbacks: ['%locale%']
        paths:
            - '%kernel.project_dir%/app/Resources/translations'
the file just contains this:
properties:
    zipcode:
        label: 'Code postal du bien'

and finally the form is created like this:
$property = new Properties();
$form = $this->createFormBuilder($property)
  ->add('zipCode', Type\IntegerType::class, array(
    'attr' => array(
      'min' => '10000',
      'max' => '99999'
    ),
    'label' => 'properties.zipcode.label'
  ))
  ->getForm();

Why my translation file is not used ?
Answer: You should add an attribute to your field like this:
$property = new Properties();
$form = $this->createFormBuilder($property)
  ->add('zipCode', Type\IntegerType::class, array(
    'translation_domain' => 'yourDomain',
    'attr' => array(
      'min' => '10000',
      'max' => '99999'
    ),
    'label' => 'properties.zipcode.label'
  ))
  ->getForm();

Replace "yourDomain" by your domain (file name). Hope this will help.
Answer: The deault translation domain is 'messages'. So you could change properties.fr.yml to messages.fr.yml. Another possibility is to change the translation domain like so:
public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults([
       'data_class'         => 'Acme\Entity\DemoEntity',
       'translation_domain' => 'properties'
    ]);
}

access to translation in form label


RecordSetDestination SSIS

Question: What is the major use of recordset destination in SSIS?I heard that it is an in-memory,so the variable which is holding the data is it in raw format?  Can someone explain the explain me the real time project use of Recordset destination?
Answer: A recordset destination can be used for just about anything you can think of.  Some common uses I hear is to use the recordset in a foreach loop.  Say you want to export several "categories" from a transaction table.  Perhaps you get a recordset of the categories that exist and then call a new dataflow to export that category as it's own file.  Or perhaps date ranges, months, etc.
One way I use it is in a script task to perform an action on the data that SSIS cannot do natively.  I was using a script component but this particular task ran into a concurrency issue.  So by dumping to a recordset I was able to use the recordset in a script task to do the logic in a manner to avoid that issue.
Another script task use is to build and send HTML emails.
I suppose a use for it might be when you have 1 data flow to get 1 record set then do a bunch of non dataflow tasks and then use that as a source in another data flow task, but that is not something I have ever done.

RecordSetDestination SSIS


Duplicate rows if certain columns has values and copy to next sheet with duplicated rows

Question: So I have this problem where if there is a value in a column, the row should be duplicated and copied to the next sheet. I will show a scenario to understand better.
This is sheet1

As you can see from the table above, there is a certain item name that doesn't have the three quantity columns. Some only have good quantity, some have both good and bad, and some have the three quantity. Now I want to copy this data to the other sheet with some modifications.
This should be the result in the next sheet:

As you can see, the data are duplicated based on the quantity columns if there is data or not. The status column is based on the quantity columns in sheet1. Status 0 is GOOD QTY, Status 1 is BAD QTY and Status 2 is VERY BAD QTY.
This is my current code:
    Set countsheet = ThisWorkbook.Sheets("Sheet1")
    Set uploadsheet = ThisWorkbook.Sheets("Sheet2")

    countsheet.Activate
    countsheet.Range("B11", Range("F" & Rows.Count).End(xlUp)).Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
    uploadsheet.Activate
    uploadsheet.Range("B2").PasteSpecial xlPasteValues

I know this code only copies data from sheet1 to sheet2. How to modify this code and achieve the result above?
Comment: Are you locked into using VBA?  Power Query can make this an easily repeatable task.
Comment: @JodyHighroller I'm not familiar with power query. If this is possible using excel, can you show me an answer?
Answer:
Select your data range > Data tab in the ribbon > From Table/Range

Select the Item Code and Item Name columns > right-click > Unpivot Other Columns

Select the Attribute column > right-click > Replace Values.  You can type in two dummy values: Value To Find = abc, Replace With = xyz

This code will appear in the formula bar:
= Table.ReplaceValue(#"Unpivoted Other Columns","abc","xyz",Replacer.ReplaceText,{"Attribute"})

Replace it with this:
= Table.ReplaceValue(#"Unpivoted Other Columns", each [Attribute], each if Text.Upper([Attribute]) = "GOOD" then 0 else if Text.Upper([Attribute]) = "BAD" then 1 else 2,Replacer.ReplaceValue,{"Attribute"})

I used the Text.Upper function because Power Query is case sensitive.

Now all you need to do is rename the columns and select Close & Load > Close & Load To > Table

This is a beneficial technique because as you add, edit, or remove data from your source table you can just refresh and the PQ table will update accordingly.


FC Layer followed by LSTM - Tensorflow

Question: I'm trying to work with LSTMs. My input data is 224*1 and my labels are 70*1.
Before connecting my inputs to LSTMs I'm trying to match the Input data to label values.
So i'm trying to use FC layer in the beginning, leave it to FC layer to learn the non-linear scale of Input-Label and then connect back the output of FC layer to LSTM.
I have tried using tf.reshape by flattening and reshape, it does not work has the size is different.
Can anyone help me with this ? Is this possibe at all?
My output of FC layer I am getting now is:
fc_layer:tf.Tensor 'Reshape:0' shape=(224, 70, 1) dtype=float32

Code
fc_layer = tf.contrib.layers.fully_connected(inputs =
                 batchX_placeholder, num_outputs = 70, activation_fn =
                                                          tf.nn.relu)
fc_layer = tf.reshape(fc_layer,[-1, 70 , 1])

#######RNN Layer
init_state = tf.placeholder(dtype = tf.float32, shape = [num_layers, 2,
batch_size, state_size],name = 'init_state')

state_per_layer_list = tf.unstack(init_state, axis=0)
rnn_tuple_state = tuple(
[tf.nn.rnn_cell.LSTMStateTuple(state_per_layer_list[idx][0],
state_per_layer_list[idx][1])
    for idx in range(num_layers)]
)

Answer: I tried this by creating 2 FC layer back-to-back.
Inputs are [1,224]
fc_layer1 = tf.contrib.layers.fully_connected(inputs, num_outputs = 224, activation_fn = tf.nn.relu)

fc_layer2 = tf.contrib.layers.fully_connected(inputs = fc_layer1, num_outputs = 70, activation_fn = tf.nn.relu)

So now I have fc_layer2 with shape (1,70). My LSTM labels are (70). I think I can now proceed for LSTM design

FC Layer followed by LSTM - Tensorflow


Form values kept as cookies after submit & page change

Question: I am currently writing a HTML page with some javascript controlling various events.
When the user clicks submit, the page automatically loads the response form the server (this is a test page used to show the XML sent to the server and the resulting response). I want the user to be able to switch back to the form and see the values that they have selected (3x dropdowns - one controlled by the selection of another, 3x textboxes - values controlled by the dropdowns, and a text area which is loaded from a text file the user has selected using input type="file" ).
This page is only useful if the user can switch back to the form and then back to the response easily. I have attempted to use cookies to save the values and then load them into the inputs when  the user returns to the page, but my code is refusing to work.
I have tried a few different examples on the internet, as well as using Garlic.js but no matter what I try, when i click "back" in the browser and the form loads, all my input is gone. I have tested the various scripts and realised there is some kind of mistake in my code, as when I include these functions inside the same script area as my working drop down functions, the whole form breaks.
Here is the script containing the cookie methods:
JAVASCRIPT
function persist() {
    removeAllCookies();
    var fValues[] = new Array();
    var expiry = new Date(today.getTime() + 3600 * 1000); // 1 hour expiry
    fValues[0] = document.getElementByName('calcType').value;
    fValues[1] = form.action.value;
    fValues[2] = document.getElementByName('transform').value;
    fValues[3] = document.getElementByName('calcResponse').value;
    fValues[4] = document.getElementByName('source').value;
    fValues[5] = document.getElementById('area').value;
    var i = 0;
    for (i = 0; i <= 6; i++) {
        element = fValues[i];
        writeCookie(i, element, expiry);
    }
}

function fillFromCookies() {
    var a = getCookie("0");
    var b = getCookie("1");
    var c = getCookie("2");
    var d = getCookie("3");
    var e = getCookie("4");
    var f = getCookie("5");
    if (b != null && f != null) {
        document.getElementByName('calcType').value = a;
        form.action.value = b;
        document.getElementByName('transform').value = c;
        document.getElementByName('calcResponse').value = d;
        document.getElementByName('source').value = e;
        document.getElementById('area').value = f;
    }
}

function writeCookie(id, value, expiry) {
    cookievalue = (value + ";");
    document.cookie = id + "=" + cookievalue + "; path=/; expires=" + expiry.toGMTString();
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function deleteCookie(name) {
    var expired = new Date(today.getTime() - 24 * 3600 * 1000);
    document.cookie = name + "=null; path=/; expires=" + expired.toGMTString();
}

function removeAllCookies() {
    deleteCookie("0");
    deleteCookie("1");
    deleteCookie("2");
    deleteCookie("3");
    deleteCookie("4");
    deleteCookie("5");
}

HTML (for test purposes)
    calcType

    <textarea name="calcType" cols="150" rows="2">-</textarea>

    transform

    <input type="text" name="transform" size="50" value="-"/>

    calcResponse

    <input type="text" name="calcResponse" size="50" value="-"/>

    source

    <input type="text" name="source" size="50" value="-"/>

    test

    <input type="text" name="test" size="50" value="test"/>

    environment
        <select id="Environment">
            <option>Pick one</option>
            <option>TEST</option>
        </select>

    product
        <select id="Product">
            <option>Pick one</option>
            <option>TEST</option>
        </select>

    brand
        <select id="Brand">
            <option>Choose Product First</option>
            <option>TEST</option>
        </select>
    <textarea id = "area" onload = "fillFromCookies();" name="calcData" cols="150" rows="50">

I call the persist() function like: <form ..onsubmit="persist()"...>
I call fillFromCookies() on the text area (containing the txt from the selected file)
textarea ..onload="fillFromCookies();" property. (it is the last element in the HTML code).
I am relatively new to javascript so any comments on code are welcome and appreciated.
Answer: I'm not sure what your requirements are but my recommendation would be to use ajax to post the form to a server, that way your form is preserved because there is no post/call back to deal with.  You call another page that will then return your xml, which I believe you can parse with JQuery though if you are restricted to javascript you could still do it but it will be a little more involved.
$.ajax({url : url, dataType: "xml", success : function(data) { },
    error : function(request, status, error) { }
});

If posting the page is really important for whatever reason, then you can populate the form using dynamic html before it is sent to the client, depending on what server-side technology you are using how to do this will vary. Unfortunately, I can't help you with that without knowing more.
Finally here is a tutorial on setting cookies in javascript.  Hope this helps:
http://sicanstudios.com/post/set-cookies-javascript/
Comment: OK thank you for your comment. I have not used ajax before and I am not able to gain access to save a page onto a web server. This webpage will be loaded as a HTML page saved onto a local machine, and not part of a website. This is why I was looking at using cookies as a type of local storage while the user is testing various xml requests and responses.
Comment: Sorry about that a.hrdie.  I've edited my answer to include a link for a tutorial on using cookies but it uses Jquery.  I found that helpful but I'm afraid I've never done that sort of thing in pure javascript as Jquery makes it much easier.  If you are comfortable with Jquery that would be a good place to start.
Comment: Thank you, Jquery makes this look much easier! Will post completed code soon.
Comment: No problem, look forward to seeing it.
Answer: I have been working at using cookies all day, and even looked into using AJAX to return the response to a separate text box. After a lot of research I found a really handy way to keep the form intact in order to compare the response and the input : open the response in a seperate tab.
By adding target="_blank" into the form tag, the XML returned by the sever is now shown in a new tab. Cookies would have been one way, but I had a lot of problems (due to beginner's understanding) with pure Javascript and different JQuery plug-ins.


Update from multiple databases in SQLite

Question: I have two tables in two different databases. I'd like to update column data in db1 with column data in db2 based on id. db1 contains less rows than db2, so I do not want to copy over the whole table. I only want to update the data column of the already existing rows in db1.
I'm using SQLite (and am restricted to using this). Is there a query I can use that does the above?
Answer: With db1 open, try this:
<code>ATTACH 'path/to/db2' AS db2;
UPDATE main.table
SET data = (SELECT data FROM db2.table WHERE main.table.id = db2.table.id)
WHERE EXISTS(SELECT 1 FROM db2.table WHERE main.table.id = db2.table.id);
</code>
Comment: Thanks for the reply. I just tried it out, all the rows in db1get updated with the data from the first matching row in db2. I.e. they all have the same content now..
Comment: I found out the problem: when opening db1 and attaching db2 I have to use 'main' for db1 name. Another solution is attaching both databases and using the "AS .." name. Thanks!


What is the advantage of having a dedicate docker container for mounting volume?

Question: docker run has a flag --volumes-from which allows you to mount a volume from another container.
I see that people create a dedicate container just for the sake of providing a volume for another container. Is this an anti-pattern and the best-practice should be creating a named volume with docker volume create --name?
Can someone shed some light on why creating a dedicate container just for the sake of volume can be beneficial? Could it be for the scenario when it's used in orchestration with Docker Machine/Docker Swarm/Kubernetes?
Answer: My reason list :
1) imagine you have a really complicated stack with a lot of containers, you can imagine it is faster to do the volume setup in 1 docker, and herit this setup with a --volumes-from directive for all other dockers
2) as I'm running docker in production, I have static data that I have to backup to tapes. on each stack, I just need to add 1 docker running a backup software client image with --volumes-from, and I am done backuping all the static data from all the stack. This also made things easy when I had to delegate the data backup scheduling/triggering to the stack end user.


How can I add extra text fields to the image field when adding/ editing nodes?

Question: What is the best way to add additional text fields to the image module, other than the title and alt value, when adding/ editing content? Is there a module which already does this?
Edit
I've read through Add custom fields to image field and unfortunately this fella got stuck and I guess this was at 7 times. The fieldable files module is no big help. It does a lot of magic but it doesnt effect images added via node entity form.
Answer: Image is a file entity and to make it fieldable you can use this module:
File Entity (fieldable files)
From the documentation:

File Entity
The File entity module extends the capabilities of the core File
  module.
File Entity defines 5 File Types - Application, Audio, Image, Text,
  Video. The Media module adds an additional File Type - Other
  (currently these File Types are hard coded and cannot be changed).
When files are uploaded they are automatically assigned the
  appropriate File Type based on the file suffix.
The File Types as currently defined are:
Images - .png, .gif, .jpg, .jpeg, .ico Videos - .mov, .mpg, .flv,
  .m4v, .mp4, ,ogg, .ovg, .wmv Sound files - .mp3 Text - .txt Document
  files - .doc, .xls, .pdf, .ppt, .pps, .odt, .ods, .odp Other - ??
Each File Type can have fields. This allows for additional information to
  be stored along with a media file such as Title, Description, Taxonomy
  References, Node References, Location, Date created, License
  information etc.
Comment: unfortunately this doesnt work. you can actually add files under /file/add, but you wont see your custom fields when adding images inside nodes (the linked thread says so, also)
Comment: You changed the question after I answered. For this you need another field widget in the node form. For file there is "Editable file" included in the module. A combination for image and editable file was as far as i know in d7 in the media module. I don't know if this is ready for d8 yet.
Comment: But even if you can't find the widget to edit the image fields inline you can edit them in `/file/[id]/edit`
Comment: I've just tested it, the widget "Editable File" provided by this module works. Also with images. To use it you have to configure the widget in the content type. Then you can go in the node form, add a new image to your node and fill in the custom fields by clicking on the button, that appears right beside the file. But you loose the preview of the image. So you have to choose between those two options, custom inline fields or image preview,
Comment: Nice answer @4k4, as usual :) Yes, editable files should also work for images. For completeness, the alternative option is Media Entity, which instead of making images fieldable, offers an intermediate entity between the node and the actual file. And then you add fields there. The advantage is that it is more flexible. One "media" element can be a single image or video, but also a youtube video, tweet or a whole image gallery. You pretty much need a bunch of ther modules too, like entity browser and inline entity form to properly use it.
Comment: can you give me some hints how could make an own implementation of the fieldable files? not having a thumbnail is really annoying
Comment: The Media Initiative seems to go for D8 in another direction, see Berdir's comment. So I doubt there will be a full fledged image widget for File Entity like there was in D7.
Comment: Well I can modify the image core module and get it running, I have to add db fields for the extra fields and stuff. I just got no clue how I can write a module which extends all the necessary files


Excel VBA pivot table filtering by barcode

Question: I've been trying to create sub, that helps filter list of goods by selecting few barcodes. I know I can do it manually, but it's very long and frustrating, since there are about ~2000 unique barcodes. I've recorded a Macro and found a few similar answers here, but i get an error "Run-time error '1004': Application defined or object-defined error' it stucks when PI.value gets assigned true or false: "PI.Visible = True; Pi.Visible = False".
Code:

Private Sub CommandButton1_Click()
Dim MyNames() As Variant
Dim objPivotField As PivotField
Dim i As Long
Dim PI As PivotItem
Set objPivotField = _
ActiveSheet.PivotTables("PivotTable1").PivotFields(Index:="[Prekė].[Barkodas].[Barkodas]")
MyNames = Array("4770349225872", "4770033220077", "7622400004773")
With ActiveSheet.PivotTables("PivotTable1").PivotFields(Index:="[Prekė].[Barkodas].[Barkodas]")

    For i = LBound(MyNames) To UBound(MyNames)

    For Each PI In .PivotItems
        If PI.Name = MyNames(i) Then
        PI.Visible = True
    Else
        PI.Visible = False
    End If
    Next PI
    Next i
End With End Sub

And here's Macro that I recorded for filtering:

ActiveSheet.PivotTables("PivotTable1").PivotFields( _
    "[Prekė].[Barkodas].[Barkodas]").VisibleItemsList = Array("", _
    "[Prekė].[Barkodas].&[4750398000132]", "", "[Prekė].[Barkodas].&[4046234141238]", _
    "[Prekė].[Barkodas].&[4770248342625]")

Comment: Could you post more about the setup of the pivot table? I tried a small example with logic similar to yours and it worked, but I used With ActiveSheet.PivotTables("PivotTable1").PivotFields("Barkodas")
Comment: Also, looping through the barcodes once and checking each PivotItem against MyNames would go faster than looping through the barcodes three times, each time checking for a single barcode
Answer: As written above in the comments, here is the method I used to filter a pivot table with VBA:

Option Explicit
Sub FilterPivotTable()

Dim PT1 As PivotTable
Dim PT1Barkodas As PivotField
Dim MyNames() As Variant
Dim PivotIdx As Long

'assign table, field and array values for easy reference
Set PT1 = ActiveSheet.PivotTables("PivotTable1")
Set PT1Barkodas = PT1.PivotFields("Barkodas")
MyNames = Array("4770349225872", "4770033220077", "7622400004773")

With PT1Barkodas

    'loop through all the barcodes
    For PivotIdx = 1 To PT1Barkodas.PivotItems.Count

        'logic to check if the current barcode is in the MyNames array
        If UBound(Filter(MyNames, .PivotItems(PivotIdx))) > -1 Then
            IsInArray = True
        Else
            IsInArray = False
        End If

        'if the barcode was not in the MyNames array, hide it
        If IsInArray = False Then
            .PivotItems(PivotIdx).Visible = False
        End If

    Next PivotIdx

End With

End Sub

Running this script filtered PivotTable1 according to MyNames:
Comment: Hi, thanks for your answer. This seems to be a good way to do this, but when assigning visible value, I get an error on this line:
`code       If IsInArray = False Then
            .PivotItems(PivotIdx).Visible = False
        End If `

"Run-time error '1004'
Application-defined or object-defined error"
Comment: Also if I use "Barkodas" instead of "[Prekė].[Barkodas].[Barkodas]" I get the same error on this line.
Comment: Hey @user2179129, bummer! That 1004 error is very interesting. I would love to help troubleshoot more, but do you think you could send a screenshot of your pivot table and data source to help me better understand the filtering and source of the problem?
Comment: https://www.dropbox.com/s/oqu6o5l978zurzn/example.jpg
Here's an example of table. However I have no access to data source.


CSS Toggle Switch com

Question: Estou precisando fazer a transição desse script para usar com <select>.
Veja bem o script funcionando é assim
    http://callmenick.com/tutorial-demos/css-toggle-switch/
Meus selects (mais de 88) sao APENAS nesse estilo:
<select>
<option value="0">Off</option>
<option value="1" selected="selected">On</option>
</select>

Apenas com opcao de ligar e desligar (0,1)
Gostaria de poder adaptar o CSS para isso, mas vejo que é CSS3 e nao sei trabalhar com ele.. O que posso fazer?
Exemplo de como seria http://jsfiddle.net/thebestclassdsfgf/jo2hkom2/1/
Answer: Esse código é feito para um input type="checkbox" e o CSS faz o trabalho todo. Ou seja se o input estiver :checked ou não, o botão mexe-se. No seu caso poderia funcionar assim também, com inputs.
Mas se quiser mesmo usar select pode fazer assim usando uma classe ligado para substituir a funcionalidade do :checked
HTML
<select id="cmn-toggle-1" class="cmn-toggle cmn-toggle-round" >
    <option value="0">Off</option>
    <option value="1" selected="selected">On</option>
</select>

jQuery
$('select').on('click', function () {
     $(this).val(this.value == '1' ? '0' : '1');
    this.classList.toggle('ligado');
});

CSS (somente a parte relevante)
.cmn-toggle-round.ligado + label:before {
    background-color: #8ce196;
}
.cmn-toggle-round.ligado + label:after {
    margin-left: 60px;
}

jsFiddle: http://jsfiddle.net/y8u1beek/
Comment: perfeito! Mas eu teria problemas, pois eu ja pre defino quem ta marcado ou nao usando o `selected="selected"` e nesse caso nao funcionou..
Comment: @user3163662 ok, isso é simples, só precis de juntar mais uma linha: http://jsfiddle.net/7m8L2b74/2/
Comment: Ok, agora estou tendo problemas, ele nao altera o valor.. e como eu vou enviar por post, preciso que mude. Veja (altere o toggle e espere) jsfiddle.net/thebestclassdsfgf/7m8L2b74/3 @Sergio
Comment: @user3163662 e porque não fazer isso com checkbox?
Comment: @Segio estou fazendo transições.. e sao muitas checkboxes
Comment: @user3163662 editei a resposta para mudar o valor do select quando receber um clic
Comment: muito obrigado, com sua ajuda consegui =)
Comment: @user3163662 boa!

CSS Toggle Switch com


Calculating $\int \sqrt{1 + x^{-2}}dx$

Question: I would like to find
$$\int \sqrt{1 + x^{-2}}dx$$
I have found that it is equivalent to
$$
\int \frac{\sqrt{1 + x^2}}{x}dx
$$
but I am not sure what to do about it. With trig substitution $x = \tan(x)$ I get
$$
\int \frac{1}{\sin(\theta)\cos^2(\theta)}d\theta
$$
but that seems to be a dead end.
Answer: $$
\int \frac{1}{\sin(\theta)\cos^2(\theta)}d\theta
$$
$$
=\int \frac{\sin(\theta)}{\cos^2(\theta)(1-\cos^2(\theta))}d\theta
$$
then use $u=\cos(\theta)$ and partial fractions on the result.
Answer: Let $x^2+1=u^2$, so that $2x\,dx=2u\,du$, which implies
$${dx\over x}={u\,du\over x^2}={u\over u^2-1}du$$
Then
$$\int{\sqrt{1+x^2}\over x}dx=\int{u^2\over u^2-1}du={1\over2}\int\left(2+{1\over u-1}-{1\over u+1} \right)du=u+{1\over2}\ln\left(u-1\over u+1 \right)+C\\=\sqrt{x^2+1}+{1\over2}\ln\left(\sqrt{x^2+1}-1\over\sqrt{x^2+1}+1 \right)+C$$
Answer: and
$$
\int \frac{1}{\sin(\theta)\cos^2(\theta)}d\theta=
\int \frac{\sin\theta}{\sin^2(\theta)\cos^2(\theta)}d\theta=
\int \frac{-d(\cos\theta)}{(1-\cos^2\theta)\cos^2(\theta)}d\theta=...
$$
Answer: $$\int \sqrt{1 + x^{-2}}dx=\int \frac{\sqrt{1 + x^2}}{x}dx$$
With substitution $u=x^{2}$, $du=2xdx$.
$$\int \frac{\sqrt{1 + x^2}}{x}dx=\int \frac{\sqrt{u+1}}{2u}du=\frac{1}{2} \int \frac{\sqrt{u+1}}{u}du $$
With substitution $v=\sqrt{u+1}$, $dv=\frac{1}{2v}du$.
\begin{align}
\frac{1}{2} \int \frac{u+1}{u}du
&=\frac{1}{2} \int \frac{2v^{2}}{v^{2}-1}dv\\[6px]
&=v-\operatorname{arctanh} (v)+C\\[6px]
&=\sqrt{x^{2}+1}-\operatorname{arctanh}(\sqrt{x^{2}+1})+C.
\end{align}
Comment: Upon your first suggested substitution, $$dx= \frac{du}{2x} = \frac{du}{2\sqrt u} $$ $$\int \frac{\sqrt{1 + x^2}}{x}dx=\int \frac{\sqrt{u+1}}{2\sqrt u}du$$
Answer: I get $\int \frac{sec \theta}{tan \theta}d \theta$ from your simplification
Which gives $\int \frac{1/cos \theta}{sin \theta / cos \theta}d \theta$
= $\int \frac{1}{sin \theta}d \theta$
= $\int csc \theta d \theta$
which integrates similarly to $sec\  \theta$
and then the fun of back-substituting.
Comment: Sorry, keep hitting return too soon. I think I had a typo there and intended to correct, sorry. My error.  Still getting used to this system.

You substituted  $x = tan(\theta)$ so $dx = sec^2 (\theta) d \theta$

$ \sqrt{1 + x^2} =  \sqrt{1 + tan^2 (\theta)} = \sqrt{sec^2(\theta} } = sec(\theta)$

You now have

$$ \int \frac{ sec \theta * sec^2 \theta} {tan \theta} d \theta $$

so yes I slipped up somewhere. Had another approach to this and lost it,

The sinh sub suggested in another answer is a good one.
Comment: I am not sure I see how you get the $\sec(\theta) / \tan(\theta)$
Comment: You had
$$\int \frac{\sqrt{ 1 + x^2}}{x} dx$$
Comment: Yes, but don't you also need to do $dx = ... d\theta$?
Answer: Set $x^{-1}=\sinh t$, so $\sqrt{1+x^{-2}}=\cosh t$. Then
$$
dx=-\frac{\cosh t}{\sinh^2t}\,dt
$$
and the integral becomes
$$
-\int\frac{\cosh^2t}{\sinh^2t}\,dt=
-\int\frac{1+\sinh^2t}{\sinh^2t}\,dt=\frac{\cosh t}{\sinh t}-t+c=
\sqrt{1+x^2}-\operatorname{arsinh}\frac{1}{x}+c
$$
You can find a more explicit expression for $\operatorname{arsinh}\frac{1}{x}$ by setting
$$
\frac{1}{x}=\frac{e^t-e^{-t}}{2}
$$
or
$$
xe^{2t}-2e^t-x=0
$$
so
$$
e^t=\frac{1+\sqrt{1+x^2}}{x}
$$
The final antiderivative is
$$
\sqrt{1+x^2}-\log\frac{1+\sqrt{1+x^2}}{x}+c
$$
Comment: This is very nice. I like the use of the hyperbolic functions ending with something with a log. Thanks!

Calculating $\int \sqrt{1 + x^{-2}}dx$


Android: Getting ListView item position onscreen after layout

Question: I am currently working on a fragment with functionality similar to Roman Nurik's sticky scrollview technique here:
http://code.google.com/p/romannurik-code/source/browse/misc/scrolltricks
However, I want to use it with a ListView and have it stick both at the top and the bottom of the screen.  I've have been somewhat successful by using two hidden views at the top and the bottom of the screen, and having the list unhide them when the correct item reaches the top or bottom using the following:
<code>//Similar to Roman's Stick ScrollView
 @Override
public void onScrollChanged() {

    if(scrollListen){
        if(mMovingClock != null && mMovingClock.getTop() <= list.getTop()){
            //Log.i("DraftSync", "View at " + String.valueOf(mMovingClock.getTop()));
            clockTop.setVisibility(View.VISIBLE);
        }else {
            clockTop.setVisibility(View.INVISIBLE);
        }

        if(mMovingClock != null && mMovingClock.getBottom() >= list.getBottom()){
            clockBottom.setVisibility(View.VISIBLE);
        }else {
            clockBottom.setVisibility(View.INVISIBLE);
        }
    }

}
</code>
The problem I have is that if my targeted list item (mMovingClock) is one of the initial items shown onscreen at fragment start, the list.GetTop() method returns zero.  I have searched extensively, and understand that this is because it's measuring it before it is rendered in position onscreen, but I am enabling scrollListen where I feel it should be:
<code>  @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

     rootView = inflater.inflate(R.layout.fragment_draft, container, false);
     list = (ObservableListView)rootView.findViewById(R.id.draft_queue);
     list.setCallbacks(this);

 ...

  list.getViewTreeObserver().addOnGlobalLayoutListener(
             new ViewTreeObserver.OnGlobalLayoutListener() {
                 @Override
                 public void onGlobalLayout() {
                     onScrollChanged();
                    scrollListen = true;

                 }
      });

    return rootView;

}
</code>
I think I am following the example correctly, but scrollListen is being set to true before the mMovingClock is properly measured.  Can anyone figure out why this view always returns 0 for getTop() and getY() until it scrolls off screen once?  After that all is well.
Any advice?
Thanks,
Josh
Answer: Ok, I feel silly for missing this, but here it is:
In the xml for my layout I had my ListView set as wrap_content instead of fill_parent.  I spent so much time looking at the fragment coding that I never considered checking the layout.
Thanks to Flavio, as it seems his answer should work, but in the end was unnecessary.
Answer: Schedule the call to getTop() for the next layout pass. At this time, your view will have been measured. Try this out:
<code>final Handler h = new Handler();
list.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        h.post(new Runnable() {
            public void run() {
                onScrollChanged();
                scrollListen = true;
            }
        });
    }
});
</code>
Comment: Unfortunately, this method did not work.  The call seemed delayed, but did still happen too soon.  Also,  I did have to add a run() method to the new Runnable to get this to work.
Comment: I added a Log event for each time onGloballayout runs, and each time it returned 0 for the view position I am trying to find.  I even tried moving the boolean toggle to switch the first time the screen is touched, but the view still returns 0.  Any idea why a View 3 positions down on a list would return 0 for getTop() and getY()?


How to make google-mlkit text recognition work in a flutter app

Question: I'm trying to make a flutter app that uses google-mlkit text recognition to extract the text of receipts. I got it working but there are still isues. Some single letters don't get recognized and sometimes even full words or numbers dont get picked up.
I implemented my app following this guide https://blog.codemagic.io/text-recognition-using-firebase-ml-kit-flutter/.
In this picture you can see what i mean that some numbers and text dont get picked up. [1]
[1]: https://i.stack.imgur.com/nR5SP.jpg
Does anyone know what the problem could be? Any suggestions? Thanks in advance for the help and I will list some ways i have tried to fix it.
-Changed the cameracontroller picture resolution from high to max and ultra.
-Changed my dependecy to the newest version.
-Changed to mlkit text recognition v2
-Tried using the google_ml_vision https://pub.dev/packages/google_ml_vision
(Its also not the case that these missing words/numbers dont get marked with a rectangle.)
Comment: The google_ml_vision flutter plugging is neither owned, nor endorsed by Google. You can post your question using its support page: https://github.com/brianmtully/flutter_google_ml_vision/issues
Answer: You can use google_ml_kit package. It works with Google's standalone ML Kit. So no need to register project on firebase. It is a recommended package for standalone ml kit as firebase_ml_vission package is discontinued.
Recently google_ml_kit package is split into a set of packages. For text recognition, google_mlkit_text_recognition package is created.
For text recognition, you can use below code,
<code>final textRecognizer = TextRecognizer();
final RecognizedText recognizedText = await textRecognizer.processImage(inputImage);

String text = recognizedText.text;
for (TextBlock block in recognizedText.blocks) {
  final Rect rect = block.rect;
  final List<Offset> cornerPoints = block.cornerPoints;
  final String text = block.text;
  final List<String> languages = block.recognizedLanguages;

  for (TextLine line in block.lines) {
    // Same getters as TextBlock
    for (TextElement element in line.elements) {
      // Same getters as TextBlock
    }
  }
}
</code>
To know, how to add text recognition using google_ml_kit, you can refer this link.


Computation of the marginal likelihood from MCMC samples

Question: This is a recurring question (see this post, this post and this post), but I have a different spin.
Suppose I have a bunch of samples from a generic MCMC sampler. For each sample $\theta$, I know the value of the log likelihood $\log f(\textbf{x} | \theta)$ and of the log prior $\log f(\theta)$. If it helps, I also know the value of the log likelihood per data point, $\log f(x_i | \theta)$ (this information helps with certain methods, such as WAIC and PSIS-LOO).
I want to obtain a (crude) estimate of the marginal likelihood, just with the samples that I have, and possibly a few other function evaluations (but without rerunning an ad hoc MCMC).
First of all, let's clear the table. We all know that the harmonic estimator is the worst estimator ever. Let's move on.
If you are doing Gibbs sampling with priors and posteriors in closed form, you can use Chib's method; but I am not sure how to generalize outside of those cases. There are also methods that require you to modify the sampling procedure (such as via tempered posteriors), but I am not interested in that here.
The approach I am thinking of consists of approximating the underlying distribution with a parametric (or nonparametric) shape $g(\theta)$, and then figuring out the normalization constant $Z$ as a 1-D optimization problem (i.e., the $Z$ that minimizes some error between $Z g(\theta)$ and $f(\textbf{x}|\theta) f(\theta)$, evaluated on the samples). In the simplest case, suppose that the posterior is roughly multivariate normal, I can fit $g(\theta)$ as a multivariate normal and get something similar to a Laplace approximation (I might want to use a few additional function evaluations to refine the position of the mode). However, I could use as $g(\theta)$ a more flexible family such as a variational mixture of multivariate $t$ distributions.
I appreciate that this method works only if $Z g(\theta)$ is a reasonable approximation to $f(\textbf{x}|\theta) f(\theta)$, but any reason or cautionary tale of why it would be very unwise to do it? Any reading that you would recommend?
The fully nonparametric approach uses some nonparametric family, such as a Gaussian process (GP), to approximate $\log f(\textbf{x}|\theta) + \log f(\theta)$ (or some other nonlinear transformation thereof, such as the square root), and Bayesian quadrature to implicitly integrate over the underlying target (see here and here). This seems to be an interesting alternative approach, but analogous in spirit (also, note that GPs would be unwieldy in my case).
Comment: I think Chib, S. and Jeliazkov, I. 2001 "Marginal likelihood from the Metropolis--Hastings output" generalizes to normal MCMC outputs - would be interested to hear experiences with this approach. As for the GP - basically, this boils down to emulation of the posterior, which you could also consider for other problems. I guess the problem is that you are never sure about the quality of the approximation. What I also wonder is if an MCMC sample is ideal for a GP model, or whether you should invest more in the tails.
Comment: (+1) Thanks for the reference, looks spot on -- I will check it out. I agree that all model-based approaches can be problematic (the good thing with Bayesian quadrature is that you get an estimate of uncertainty, although not sure how calibrated it is). For the moment my modest goal is to do something that is "better than a Laplace approximation".
Answer: The extension by Chib and Jeliazkov (2001) unfortunately gets quickly costly or highly variable, which is a reason why it is not much used outside Gibbs sampling cases.
While there are many ways and approaches to the normalisation constant $\mathfrak{Z}$ estimation problem (as illustrated by the quite diverse talks in the Estimating Constant workshop we ran last week at the University of Warwick, slides available there), some solutions do exploit directly the MCMC output.

As you mentioned, the harmonic mean estimator of Newton and Raftery (1994) is almost invariably poor for having an infinite variance. However, there are ways to avoid the infinite variance curse by using instead a finite support target in the harmonic mean identity
$$\int \dfrac{\alpha(\theta)}{\pi(\theta)f(x|\theta)}\text{d}\pi(\theta|x)=\frac{1}{\mathfrak{Z}}$$
by picking $\alpha$ as the indicator of an HPD region for the posterior. This ensures finite variance by removing the tails in the harmonic mean. (Details are to be found in a paper I wrote with Darren Wraith and in a chapter about normalising constants written with Jean-Michel Marin.) In short, the method recycles the MCMC output $\theta_1,\ldots,\theta_M$ by identifying the $\beta$ (20% say) largest values of the target $\pi(\theta)f(x|\theta)$ and creating $\alpha$ as a uniform over the union of the balls centred at those largest density (HPD) simulations $\theta^0_i$ and with radius $\rho$, meaning the estimate of the normalising constant $\mathfrak{Z}$ is given by
$$\hat{\mathfrak{Z}}^{-1}=\underbrace{\frac{1}{\beta M^2}\sum_{m=1}^M}_{\text{double sum over}\\\beta M\text{ ball centres }\theta_i^0\\\text{and $M$ simulations } \theta_m}
\underbrace{\mathbb{I}_{(0,\rho)}(\min_i||\theta_m-\theta^0_i||)\{\pi(\theta_m)f(x|\theta_m)\}^{-1}\big/\overbrace{\pi^{d/2}\rho^d\Gamma(d/2+1)^{-1}}^{\text{volume of ball with radius $\rho$}}}_{\dfrac{\beta M\alpha(\theta_m)}{\pi(\theta_m)f(x|\theta_m)}}$$
if $d$ is the dimension of $\theta$ (corrections apply for intersecting balls) and if $\rho$ is small enough for the balls to never intersect (meaning that at best only one indicator on the balls is different from zero). The explanation for the $\alpha M^2$ denominator is that this is a double sum of $\beta M^2$ terms:
$$
\frac{1}{\beta M}\sum_{i=1}^{\beta M} \underbrace{\frac{1}{M}\sum_{m=1}^M {\cal U}(\theta_i^0,\rho)(\theta_m)}_{\text{same as with $\min$}} \times \frac{1}{\pi(\theta_m)f(x|\theta_m)}
$$
with each term in $\theta_m$ integrating to ${\mathfrak{Z}}^{-1}$.

Another approach is to turn the normalising constant $\mathfrak{Z}$ into a parameter. This sounds like a statistical heresy but the paper by Guttmann and Hyvärinen (2012) convinced me of the opposite.
Without getting too much into details, the neat idea therein is to turn the observed log-likelihood
$$
\sum_{i=1}^n f(x_i|\theta) - n \log \int \exp f(x|\theta) \text{d}x
$$
into a joint log-likelihood
$$
\sum_{i=1}^n[f(x_i|\theta)+\nu]-n\int\exp[f(x|\theta)+\nu]\text{d}x
$$
which is the log-likelihood of a Poisson point process with intensity function
$$
\exp\{ f(x|\theta) + \nu +\log n\}
$$
This is an alternative model in that the original likelihood does not appear as a marginal of the above. Only the modes coincide, with the conditional mode in ν providing the normalising constant. In practice, the above Poisson process likelihood is unavailable and Guttmann and Hyvärinen (2012) offer an approximation by means of a logistic regression. To connect even better with your question, Geyer's estimate is a MLE, hence solution to a maximisation problem.

A connected approach is Charlie Geyer's logistic regression approach. The fundamental notion is to add to the MCMC sample from $\pi(\theta|x)$ another sample from a known target, e.g., your best guess at $\pi(\theta|x)$, $g(\theta)$, and to run logistic regression on the index of the distribution behind the data (1 for $\pi(\theta|x)$ and 0 for $g(\theta)$). With the regressors being the values of both densities, normalised or not. This happens to be directly linked with Gelman and Meng (1997) bridge sampling, which also recycles samples from different targets. And later versions, like Meng's MLE.

A different approach that forces one to run a specific MCMC sampler is Skilling's nested sampling. While I [and others] have some reservations on the efficiency of the method, it is quite popular in astrostatistics and cosmology, with software available like MultiNest, PolyChord and UltraNest.

A last [potential if not always possible] solution is to exploit the Savage-Dickey representation of the Bayes factor in the case of an embedded null hypothesis. If the null writes as $H_0: \theta=\theta_0$ about a parameter of interest and if $\xi$ is the remaining [nuisance] part of the parameter of the model, assuming a prior of the form $\pi_1(\theta)\pi_2(\xi)$, the Bayes factor of $H_0$ against the alternative writes as
$$\mathfrak{B}_{01}(x)=\dfrac{\pi^\theta(\theta_0|x)}{\pi_1(\theta_0)}$$
where $\pi^\theta(\theta_0|x)$ denotes the marginal posterior density of $\theta$ at the specific value $\theta_0$. In case the marginal density under the null $H_0: \theta=\theta_0$
$$m_0(x)=\int_\Xi f(x|\theta_0,\xi)\pi_2(\xi)\text{d}\xi$$
is available in closed form, one can derive the marginal density for the unconstrained model
$$m_a(x)=\int_{\Theta\times\Xi} f(x|\theta,\xi)\pi_1(\theta)\pi_2(\xi)\text{d}\theta\text{d}\xi$$
from the Bayes factor. (This Savage-Dickey representation relies on specific versions of three different densities and so is fraught with danger, not even mentioning the computational challenge of producing the marginal posterior.)

[Here is a set of slides I wrote about estimating normalising
constants for a NIPS workshop last December.]
Comment: (+1) Incredibly rich answer, thank you. This will be useful to me and, I suppose, many other people. It will take me some time to have a look at the various approaches, and then I might come back with specific questions.
Comment: Starting from point (1)... I read the relevant articles. The "corrected" harmonic mean estimator seems *exactly* what I was looking for. It's neat and easy to compute given a MCMC output. So... what's the catch? It doesn't look like the method is being widely used, judging from a quick search on Google Scholar. What are its limitations? (besides the need to identify the HPD regions, which I imagine might become an issue for very complicated posteriors in high dimension). I am definitely going to give it a try -- but I wonder if there is something I need to be wary of.
Comment: I added a few more details: the issue in implementing the HPD uniform is to figure out a proper compact approximation for the HPD region. The convex hull of points with high posterior values is (NP?) hard to determine while balls centred at those points may intersect, which creates a secondary normalising constant problem.
Comment: @Xi'an : very helpful, thanks! Can I ask: of all the mentioned approaches, what would currently be your recommendation if one looks for a general approach that tends to work out of the box (i.e. no tuning / checking required from the user)? I would be especially interested in the case of models with a low (< 50) number of parameters, non-normal posteriors, and strong correlations between parameters.
Comment: @FlorianHartig: the fact that a generic software like BUGS does not return a generic estimate of $\mathfrak{Z}$ is sort of revealing the extent of the problem. The many solutions that one can find in the specialised literature have not produced a consensus estimate. Hence, my recommendation would be to opt for Geyer's logistic regression solution, which is somewhat insensitive to dimension.
Comment: @FlorianHartig: Addendum: there is an [R package called BayesFactor](http://bayesfactorpcl.r-forge.r-project.org/#references), developed by Richard Morey, that I have never tried and which foundations I know nothing about...
Comment: @Xi'an: thanks a lot, I will have a look at both options.


use different "From" header for different actions when sending emails

Question: So for example, when a user's creating an account, I want to have the sent email use "From: email@example.com" header.
But also, when I will approve his content I want to use the header "From: email@example.com"
Right now, all emails sent are using the same "From" email header provided in the "Site information" settings.
Any ideas on how to achieve this? Thanks
Answer: use hook_mail_alter function in your custom module and change the from address based on your requirements.


using ng-hide animations to create a simple slide-show kind of effect

Question: In my application I am attempting to create a slide-show like effect.
i.e first show a certain text.. then hide is (animatedly) ..then show another piece of text... then hide it.. and so on..
Kind of like slide show.
Following the example from AngularJS lessons:
http://plnkr.co/edit/DCvvNxnitHpcAowKKSvI?p=info

I have set my css as below:'
.part1 {
  background-color: blue;
  opacity: 1;
  height: 200px;
}

.part1.ng-hide-add.ng-hide-add-active,
.part1.ng-hide-remove.ng-hide-remove-active {
  -webkit-transition: opacity ease-in 2s;
  transition: opacity ease-in 2s;
}

.part1.ng-hide {
  opacity: 0;
}

.part2 {
  background-color: red;
  opacity: 1;
    height: 200px;
}

.part2.ng-hide-add.ng-hide-add-active,
.part2.ng-hide-remove.ng-hide-remove-active {
  -webkit-transition: opacity linear 0.5s;
  transition: opacity linear 0.5s;
}

.part2.ng-hide {
  opacity: 0;
}

However, there is no animation happening between part1 and part2.
A plnkr is here:
http://plnkr.co/edit/hrxtvxIIAysEw1iF2DLn?p=info

Is there some other class that I need to add ?
Comment: You aren't including ng-animate
Answer: You are missing ng-animate
http://plnkr.co/edit/AwEToSEnSYiZePF5KhO9?p=preview
you have to add the cdn and inject into app like so
['ui.bootstrap', 'ngAnimate']

Not 100% sure what effect you want with your css, but i'm guessing you will have to tweak a little bit, but this will get the angular animate part working for you.


C# DataGridView alinhar header no centro

Question: Estou sofrendo para conseguir alinhar o cabeçalho do DataGridView. Quero que o texto fique centralizado no centro.
Eis o código:
        dg.EnableHeadersVisualStyles = false; // Desabilita formatação padrão
        dg.ColumnHeadersDefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold);
        dg.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;
        dg.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
        dg.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

O resultado fica como na figura seguinte:

Ele fica alinhado no centro, mas puxado para a esquerda. Há como por o texto 100% centralizado? Já procurei no fórum mas encontrei ninguém com esse problema.
O código é parte de uma função que recebe um DataGridView, formata e retorna com a formatação. Segue o código completo:
    public DataGridView Grade(DataGridView dg){
        dg.EditMode = DataGridViewEditMode.EditProgrammatically;
        dg.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        dg.AllowUserToAddRows = false;
        dg.AllowUserToDeleteRows = false;
        dg.DefaultCellStyle.Font = new Font("Calibri", 9);
        dg.EnableHeadersVisualStyles = false; // Desabilita formatação padrão
        dg.ColumnHeadersDefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold);
        dg.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;
        dg.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
        dg.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        dg.RowsDefaultCellStyle.BackColor = Color.LightCyan;
        dg.AlternatingRowsDefaultCellStyle.BackColor = Color.LightBlue;
        dg.MultiSelect = false;
        return dg;
    }

Esta função fica na classe Design e é chamada nas outras pelo código:
public void DataGridViewDesign(){
    Design modelo = new Design();
    dgDados = modelo.Grade(dgDados);
}

Todos os Grids da aplicação ficam com a mesma aparência.
Comment: É Windows forms?
Comment: Sim, é Windows Forms. Usei o Visual Studio 2013.
Comment: @LindomarLemos Coloque o trecho da rotina responsável por chamar o método `Grade()` também.
Comment: Coloquei o código que chama a função. Ele é o mesmo em toda o aplicativo.
Comment: Estou testando aqui.
Comment: @LindomarLemos Adiciona a linha no método `Grade()` veja se funciona: `dg.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;`
Comment: Esse código é pra célula, nela funcionou deixando o texto das células alinhado à esquerda e a altura centralizada. A distância em cima e embaixo é a mesma.
Comment: @LindomarLemos Fiz uma modificação aqui e resolveu, deixou o Header no centro, vou editar a minha resposta.
Comment: Desculpe, coloquei o código na função errada. Ele centralizou as células de maneira perfeita o lado esquerdo e direito tem a mesma distância. Só queria que o mesmo acontecesse com o header.
Answer: Você poderia especificar as colunas, veja um pequeno exemplo:
dg.Columns["nomeDoMeuCampo"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

Edição:
Consegui deixar o conteudo do Header no centro desabilitando a propriedade de ordenação:
public DataGridView Grade(DataGridView dg)
{
    dg.EditMode = DataGridViewEditMode.EditProgrammatically;
    dg.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
    dg.AllowUserToAddRows = false;
    dg.AllowUserToDeleteRows = false;
    dg.DefaultCellStyle.Font = new Font("Calibri", 9);
    dg.EnableHeadersVisualStyles = false; // Desabilita formatação padrão
    dg.ColumnHeadersDefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold);
    dg.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;
    dg.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
    dg.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter;

    //Vc pode usar um for se quiser
    dg.Columns[0].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
    dg.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
    dg.Columns[1].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
    dg.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
    dg.Columns[2].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
    dg.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
    dg.Columns[3].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
    dg.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable;
    dg.Columns[4].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
    dg.Columns[4].SortMode = DataGridViewColumnSortMode.NotSortable;

    dg.RowsDefaultCellStyle.BackColor = Color.LightCyan;
    dg.AlternatingRowsDefaultCellStyle.BackColor = Color.LightBlue;
    dg.MultiSelect = false;
    return dg;
}

Fonte:
https://social.msdn.microsoft.com/Forums/en-US/72b7fbac-660a-4693-9b7f-33ae6657853b/datagridview-headertext-alignment-padding-on-the-right-or-center?forum=csharplanguage
Comment: Fiz a função para alinhar o Header. Deve ser chamado:
`dgDados = modelo.AlinharHeader(dgDados, dgDados.ColumnCount);`

Função:
`public DataGridView AlinharHeader(DataGridView dg, int colunas){
     try{
         for (int i = 0; i < colunas; i++){
             dg.Columns[i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
             dg.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
          }
     }
     catch { }
     return dg;
 }
`
Comment: Também já tentei aplicar em cada coluna mas o resultado foi o mesmo. Já nas células funciona perfeito. Acho muito estranho ou falta eu declarar alguma coisa no código.
Comment: @LindomarLemos Tenta deixa a opção `EnableHeadersVisualStyles` habilitada (true).
Comment: Se deixar habilitada a formatação não funciona. Fica default com a cor da fonte preta, fundo cinza e alinhado à esquerda. Fiz outros testes com alinhamento à direita e também fica um espaço até a borda jogando o texto mais à esquerda.
Comment: @LindomarLemos Posta toda rotina responsável pela formatação na pergunta.
Comment: Coloquei o código completo da função na descrição, mas fora da função acontece a mesma coisa.
Comment: @LindomarLemos veja se funcionou agora.
Comment: Muito legal, funcionou sim. Só não dá pra colocar na função. Não tenho um tamanho exato de colunas em cada DataGrid em que a função é chamada, Vou ver se faço outra função passando a quantidade de colunas e retornar essa formatação. Muito obrigado!


Java Script conflict while Popup and Slideshow

Question: In my webpage I am doing two things:

Image slide show
Image popup

For that I had included 6 JavaScript files, but it conflicts. It works fine individually. How can I avoid the JavaScript conflict?
I had included the js file like this:
----------------for popup-------------

            >

--------------for slideshow-------------

Comment: What is the conflict error that you are getting ? Give us more details.
Answer: I'm pretty sure Lightbox is dependent upon JQuery, so it should be placed AFTER you load in JQuery, like so:

It is also best practice to put all your JavaScript files towards the END of your HTML file in case some of the JavaScript files are dependent upon the elements in the DOM being loaded first.
However, more clarity around the exact error message would be useful for helping you debug.
Comment: Fantastic! It helps to have sharp eyes ;)


Can the product of a Beta and some other distribution give an Exponential?

Question: Let $X$ follow a Beta distribution in $[0,1]$ with some parameters, and $Y$ be a non-negative random variable, independent of $X$.
Is it possible for $Y$ to have a distribution such that $Z = XY$ follows an Exponential distribution?
A bit of elaboration
By the formula for the density of the product distribution we can write
$$f_z(z) = \int_0^1\frac {1}{x}f_x(x)f_y(z/x)dx = \int_0^1\frac {dF_x(x)}{dx}\left(\frac {1}{x}f_y(z/x)\right)dx$$
$$=F_x(x)\left(\frac {1}{x}f_y(z/x)\right)|^1_0 - \int_0^1F_x(x)\left(-\frac {1}{x^2}f_y(z/x)-\frac {z}{x^3}f'_y(z/x)\right)dx$$
$$=f_y(z) + \int_0^1\frac {1}{x^2}F_x(x)\left(f_y(z/x)+\frac {z}{x}f'_y(z/x)\right)dx \tag{1}$$
To obtain the last step, I think that we have already assumed that $f_y(\cdot)$ goes to zero "fast enough".
If this is to be a density for an r.v. in $[0.\infty]$, it must be the case that
$$\int_0^{\infty}f_y(z)dz + \int_0^{\infty}\int_0^1\frac {1}{x^2}F_x(x)\left(f_y(z/x)+\frac {z}{x}f'_y(z/x)\right)dx dz = 1 \tag{2}$$
But if $f_y(\cdot)$ is a densirty of a non-negative randomm variable, it follows that the first intergal should equal unity on its own (here $z$ is just the dummy variable of intergation). So a -necessary- condition is that
$$\int_0^{\infty}\int_0^1\frac {1}{x^2}F_x(x)\left(f_y(z/x)+\frac {z}{x}f'_y(z/x)\right)dx dz  =0$$
where $F_x(x)$ is the cdf of the Beta distribution.
So the question is: is there a density $f_y(\cdot)$ such that it satisfies $(2)$ and makes $(1)$ equal to $\lambda e^{-\lambda z}$ for $\lambda>0$?
I am concerned mainly with existence, I don't expect to obtain $f_y(\cdot)$.
Answer: Based on multiple answers to Distribution of $XY$ if $X \sim$ Beta$(1,K-1)$ and $Y \sim$ chi-squared with $2K$ degrees , let $X \sim \mathrm{Beta} \left(1,K-1 \right) $ and $Y$ be chi-squared with $2K$ degrees of freedom.
Then the product is exponential with parameter $\frac{1}{2}$ .
Comment: (+1), and of course, $Z = \frac{2XY}{\lambda} \sim Exp(\lambda)$.
Answer: A thought:
Since we are prescribing the distributions of $Z, X$, then $Z = XY \implies Y = Z/X$, so why not try to calculate $Y$ as a ratio distribution and see what we get?
We have
$$f_y(y) = \int_0^1 x f_z(yx)f_x(x)dx$$
We assume that $X$ is a $Beta(a,b)$ and $Z$ is an $Exp(\lambda)$ (rate parameter). So
$$f_y(y) = \frac {\lambda}{B(a,b)} \int_0^1 x \exp \{(-\lambda y)x\} x^{a-1}(1-x)^{b-1}dx$$
$$=\frac {\lambda}{B(a,b)} \int_0^1 x^a (1-x)^{b-1}\exp \{(-\lambda y)x\} dx$$
Looking up Gradshteyn & Ryzhik (2007, 7th ed.) p 347, eq. 3.383(1) and mapping coefficients, we get
$$f_y(y) = \lambda \frac {B(b,1+a)}{B(a,b)} \cdot  {}_1F_{1}(1+a;1+a+b;-\lambda y)$$
where the function is Kummer's confluent hypergeometric function.
Is this a probability density over $[0,\infty]$?
Comment: $X$ and $Z$ and not independent, so it's difficult to see how you can justify the step at "We have...".
Comment: @whuber Oops, and I was wondering why it appears so easy...
Comment: @whuber But help me understand this: Let's assume that $Z$, $X$ are two independent r.v.'s. Then we go on and calculate the density of $Y= Z/X$ as above. Is it not still true that $XY = Z$ and so that the distribution of $XY$ will be the same as the distribution of $Z$? I have a hard time thinking otherwise.
Comment: Then X and Y would generally be dependent (because of how Y was constructed from X), and your problem statement has them be independent.


how to modify the size of a column

Question: I created the table Test_Project2 in Oracle SQL Developer. After that I realized that the column proj_name is of a small size, so I decided to modify the column using the follwoing statement
ALTER TABLE TEST_PROJECT2 MODIFY proj_name VARCHAR2(300);

but for some reason Oracle SQL Developer underscores the semi-colon with red and I do not what is mistake and how to correct it
Test_Project2:
CREATE TABLE Test_Project2 (
proj_id number(30),
proj_name VARCHAR2 (30),
proj_desc VARCHAR2(300)
);

Comment: http://stackoverflow.com/questions/10179217/alter-the-size-of-column-in-table-containing-data
Comment: i solved it..it should be: ALTER TABLE Test_Project2 MODIFY (proj_name varchar(150));
/
Answer: Regardless of what error Oracle SQL Developer may indicate in the syntax highlighting, actually running your alter statement exactly the way you originally had it works perfectly:
ALTER TABLE TEST_PROJECT2 MODIFY proj_name VARCHAR2(300);

You only need to add parenthesis if you need to alter more than one column at once, such as:
ALTER TABLE TEST_PROJECT2 MODIFY (proj_name VARCHAR2(400), proj_desc VARCHAR2(400));

Comment: I prefer to to add "CHAR" with varchar2 after the number, to avoid ambiguity with "BYTE": `ALTER TABLE TEST_PROJECT2 MODIFY proj_name VARCHAR2(300 CHAR);`. See more here: https://stackoverflow.com/questions/7477564/varchar2n-bytechar-default-char-or-byte
Answer: If you run it, it will work, but in order for SQL Developer to recognize and not warn about a possible error you can change it as:
ALTER TABLE TEST_PROJECT2 MODIFY (proj_name VARCHAR2(300));

Answer: This was done using Toad for Oracle 220.127.116.11
ALTER TABLE SCHEMA.TABLENAME
    MODIFY (COLUMNNAME NEWDATATYPE(LENGTH)) ;

For example,
ALTER TABLE PAYROLL.EMPLOYEES
    MODIFY (JOBTITLE VARCHAR2(12)) ;

how to modify the size of a column