What are advantages and disadvantages of bernoulli assignment/randomization?

Question: This is good explanation for what is Bernoulli assignment is.
For treatment assignment, what is the difference between Bernoulli assignment vs. completely randomized assignment?
I am wondering, what are benefits and drawbacks of using Bernoulli assignment? What are the scenarios that this method is desired?
Thank you!
Answer: The advantage of this simple randomization procedure is that it is easy to
implement. You just use a coin or a computer and allocate treatment option for each patient basing on Head or Tail. However, the major disadvantage is that, although in the long run the number of participants in each group will be in the proportion anticipated, there could be unbalanced between two arms. In addition, although with very very small probability, this randomization scheme might end up with unwanted outcome, that is all 1 (or all 0) appear. In this case, you cannot compare two treatments.
Comment: Random assignment is as easy to implement: draw names from a hat, or use a computer. You do need to know how many patients you'll have beforehand though; which is not the case with Bernoulli assignment - just assign each to an arm when he/she walks through the door of the clinic, & carry on for the duration of the trial.


jQuery "parseerror" with static JSONP callback function

Question: Ok, simple JSONP setup with jQuery, built with the requirement that I have "static" URLs beyond the search term:
function handleJSONPResponse (data, status, request) {
    // update UI
}

$(function () {
$('#some-input').on('keyup', function () {
    $.ajax('http://www.example.com/service/', {
        dataType : 'jsonp',
        jsonpCallback : 'handleJSONPResponse',
        data : {
            search : $('#some-input').val()
        },
        complete : function (xhr, status) {
            if (status === 'parsererror') {
                console.log(xhr.responseText)
            }
        }
    });
});

When the user presses keys, they requests are fired. For the purpose of this question, it doesn't matter if "hamme" returns after "hammer" we just want to make the call (I do handle this in the real code). My problem is this... sometimes, especially under frequent key presses, I don't get a UI update, I get an error that gets logged to my console that looks something like this:
handleJSONPResponse({"JSON" : "Some Data"})

So, as you can see, the response text that jQuery has is fine, but its still causing a parsererror. I've also verified that the JSON content is OK. Let me stress that sometimes the JSONP for "hammer" works, and sometimes the JSONP for "hammer" fails. Its not a back-end error; I always get what looks like a valid JSONP response in my xhr.responseText.
I've tried this with the JSONP callback handler passed into the "success" parameter for the Ajax request, but this does not change the operation. The only thing that I can do that prevents this error is to remove the specified JSONP callback name and let jQuery make random ones, but I have a requirement from our caching layer that states that I must keep the URL static, thus a static callback name.
What can I do to make sure that I don't randomly get parsererror fails from jQuery?
You can see an example here:
http://jsfiddle.net/yVqpS/
The JSFiddle "Echo" JSONP produces errors far less frequently than my local service, but if you hammer at it, you'll see some "handleJSONPResponse not defined" errors come through your console...
Clarification:
Cross-domain is required, so anything that isn't cross-domain doesn't work. Sorry I did not make that clearer in the first example other than using JSONP as my standard rather than a normal Ajax request.
Answer: It's probably easier to just use $.getScript in this case:
http://jsfiddle.net/yVqpS/1/ (note how it's running the script in the body, not dom load. head will work too. function must be defined in the global namespace.)
function handleJSONPResponse(data, status, request) {
    console.log('response', data);
}

$(function(){
    $('#some-input').on('keyup', function () {
        $.getScript('http://jsfiddle.net/echo/jsonp/?' + $.param({
            search: $('#some-input').val()
        }) + "&callback=handleJSONPResponse");
    });
});

Comment: @JonHartmann `$.getScript` works just fine cross-domain for the same reason `` works.
Comment: Unfortunately, that is not an option. $.getScripts() is just a wrapper for $.ajax() which is not cross domain. If you use the crossDomain: true param to force it, then it just converts to making a randomly named JSONP request any way.
Comment: If you use `dataType :"jsonp"`, you can't use a static function like you are wanting to because jQuery is going to create one for you.
Comment: Hrm, sorry, I missed that it was doing a JSONP style request the first time, thats why I tried doing forcing crossDomain:true. And yes, you can use datatype: "jsonp" with a fixed function name by specifying the jsonpCallback:"funcName" param as I did in my example.

Now I just need to test to see if $.getScripts() works in my original setup. Thanks! If I get it to work I'll accept your answer.
Comment: Well yeah you can use a static name, but it's not going to use your original function unless you pass it to the success callback.
Comment: I've also looked into $.getScript's execution, and as far as I can tell, it only uses the script-in-the-head method if you're forcing a crossDomain:true any way. I'm still sorting out the execution for crossDomain:false, to see if they fake it as a JSONP somehow, but I'm not sure why they would have separate handling if that were the case.
Comment: Never mind. I just tested it cross domain, and it seems to be working fine. Still not sure how the execution tracks out, but yes, in this case $.getScript() seems to be working.


What are typical NFS read/write rates

Question: I have just installed a server that is sending HTTP video streaming files to a Web server over NFS and I want to make sure that I have the transfer speed optimized.  But I don't know what sort of read/write rates are typical so I don't know if I have already achieved close to the maximum.  I understand that wsize and rsize parameters are important but I don't know what they are defaulting to and if its worth changing them.
As per the sourceforge article on NFS, I tested write speed using:
time dd if=/dev/zero of=/mnt/data/video/testfile bs=16k count=16384

And I get a Write rate of 48MB/s.
I tested this a number of times (unmounting / mounting to clear the cache)  and this speed was fairly consistent.
I tested read speed:
time dd if=/mnt/data/video/testfile of=/dev/null bs=16k

And get a Read rate of 117MB/s
The ethernet switch and all cables are good for 1Gb/s and the NICs on both machines are set to use jumbo frames, (MTU=9000) and in /etc/exportfs I set the async option - speed is more important to me than perfect data integrity.  Both machines are fairly standard HP Proliant's with 7.2K SATA drives (3G on one, 6G on the other).   Both machines are using Linux 2.6.18.  The machine sending the files is is running CentOS 5.5 and the machine receiving them is running RHEL 5.4 (Tikanga).
I'm hoping that someone who has tested a number of different systems can say whether the above figures are typical for NFS data transfer or if there is plenty of room to increase them.
Comment: What is the read/write speed on the directly on the NFS server and how does that compare to your speed over NFS?  BTW Linux 2.6.18 is pretty old, you sure it isn't time to upgrade?
Comment: @Zoredache: 2.6.18 is the base kernel in RHEL/CentOS/etc 5.x. 6.x uses a new kernel (2.6.32 base). The RHEL 5.x 2.6.18 is very different to a kernel.org 2.6.18 kernel though.
Comment: Also check the rsync and (s)cp between the servers to give you an idea what the bandwidth is.
Comment: "Typical rate"?  What a strange concept
Answer: Adam, in my opinion you ARE in the right ballpark.
Blocksize is hugely important as the sourceforge article implies.
It's unlikely that you can hit your network wire speed 110-120MB/s (1 Gb, that's bits not bytes).
For the audience, here's the article which is great:  http://nfs.sourceforge.net/nfs-howto/ar01s05.html
There is of course some overhead of transferring the block, getting the response.  We tested on 10 Gb Ethernet, it wasn't faster.  But in theory we could run more NFS in parallel with that fatter pipe.
Answer: Take a comparison with a 1-bay NAS appliance from Synology using CIFS, they don't publish NFS figures:

http://www.synology.com/products/performance.php?lang=enu
That reads as your file server is a little faster than a 2010 1-disk NAS but worse than a 2011 model.
The maximum for 1Gb Ethernet should be in the region 110-120MB/s.  Make sure you are using TCP transport for NFSv3 and not UDP, and not NFSv2.  NFSv4 would be more preferable.

What are typical NFS read/write rates


Stop Words removal from TextView

Question: I have a TextView which contains a processed text, so that it will be in lower case and doesn't have punctuations.
Now I want to remove the stop words (these stop words are in my language which I already define). After that, I want to send the result to another TextView.
This my code
public void onClick(View v) {
    // TODO Auto-generated method stub
    if (v.getId() == R.id.button6) {
        Intent i2 = new Intent(this, PreposisiRemoval.class);

        String test = ((TextView) findViewById(R.id.textView7)).getText()
            .toString();
        String[] preposisi = { "akibat", "atas", "bagai", "bagi", "berkat",
            "dalam", "dari", "demi", "dengan", "di", "hingga",
            "karena", "ke", "kecuali", "lewat", "oleh", "pada",
            "sampai", "sejak", "seperti", "tanpa", "tentang", "untuk" };

        StringBuilder result = new StringBuilder();

        Scanner fip1 = new Scanner(test);
        while (fip1.hasNext()) {
            int flag = 1;
            String s1 = fip1.next();
            for (int i = 0; i < preposisi.length; i++) {
                if (s1.equals(preposisi[i])) {
                    flag = 0;
                }
                if (flag != 0) {
                    System.out.println(s1);
                    result.append(s1);
                }
            i2.putExtra("result2", result.toString());
            startActivity(i2);
            }
        }
    }
}

After I pressed button6, I did not get any results.
Where is the part of my coding that is wrong?
This code is in another Activity which will receive the processed text.
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_preposisi_removal);

    Intent intent = getIntent();
    String result = intent.getStringExtra("result2");

    TextView tv = (TextView) findViewById(R.id.textView8);
    tv.setMovementMethod(new ScrollingMovementMethod());
    tv.setText(result);
    tv.setTextSize(12);
}

Comment: please use substring and remove that word from that string
Answer: To prepare the text for result2 you can try the following-
String STOP_WORD = "."; // define your stop word here.

String result2= result.replace(STOP_WORD ,"");

Then pass the text and set it on your second TextView.

Stop Words removal from TextView


My server's security was breached... I need help - Ubuntu/Linux

Question: I'm using Ubuntu 10.04. An unknown person has logged in several times through SSH using postgres user account.
I'm having a hard time finding logs with any related acitivty, probably because such logs are being cleaned??

I need help logging the person's activity, so I can understand what this person did or is doing?
Help would be awesome, thanks.

Edit:
Are there any traps I could set for the next login this person makes? I don't mind leaving the server as is, just to find out what this person's activities are.
Any ideas? =)
Comment: at this point you should be assuming the box is rooted, and any investigation beyond this point is strictly evidence gathering / research, yes ?
Comment: And the next question from RadiantHex will be "how do i lock down my server to prevent attack?"
Comment: @Chris: Bingo! Oh well, it's always good to get some expert's advice.
Comment: Can you post the log fragment or whatever you are seeing that is making you suspect there is a this breach?  Sometimes cronjobs can do things that may look unusual if you don't know about them.
Answer: Step one: take the server offline, shut it down, and make a clone of the hard drive. When doing your forensic work, use only this clone drive, leaving the original untouched.
You should be able to throw the clone drive into another system, mount it, and start poking around to see what the user did. The first thing I'd check is the user's ~/.bash_history, if there is one. Most smart hackers will delete this file when they're done with their work, but there's a chance it may still be around. If that doesn't work, then all you really have to go by are log messages in /var/log. You may try running rkhunter over the system, but IMO, it's not worth it, as you already know that this system is compromised. Depending on how savvy this user was, you may never know what they actually did.
If I were you, I'd do a full re-install of the system and restore from a known-good backup. That's the only way you'll be able to be certain the system isn't compromised. Additionally, when you bring the new system up, do yourself a favor, and turn off PasswordAuthentication in your /etc/ssh/sshd_config file and use key auth instead. By doing this, you'll be much safer from this sort of malicious activity.
Comment: Sorry, but I'm not going to put a whole lot more effort into this answer. See my above comment.
Comment: Oh, and also - go back to your previous questions and mark answers as "accepted". That would a polite, courteous, and respectful way to thank the community for the information and advice they've given you.
Comment: thanks for your awesome reply, postgres currently has no folder. Any idea where the .bash_history file would be?
Comment: I did so, after Chris S wrote his comment. I don't use ServerFault often, I am not sure how come I forgot to tick the answers.
Answer: Part One (what to do): As per what ErikA wrote. You are sure that the system is compromised, so the right thing to do is to take it off-line.
Part Two (setting traps): There isn't much you can sensibly do on the host, as doing anything on the host may alert the person(s) that compromised the server. Since you're using SSH, it's also not trivial to packet-sniff upstream to recover the session from there. I'd, personally, ignore that and go with what ErikA wrote (take the server down; clone the disk; if a forensic investigation is needed, use the cloned data; install a new server; secure the new server; recover data from known-good backup).


ProgressDialog não sai do 0%

Question: estou fazendo um upload de uma imagem para o banco de dados do firebase e quero mostrar isso no progress porem ele sempre fica 0/100.
<code> progress=new ProgressDialog(getContext());
    progress.setMessage("Downloading Music");
    progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progress.setIndeterminate(true);

   progress.show();
    uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
            double p = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
          int currentprogress = (int) p;
            progress.setProgress(currentprogress);

            if(currentprogress==100){
                progress.dismiss();
            }
        }
    });
</code>
Comment: A variável que está recebendo a atualização do progresso é a variável "p" e não "currentprogress", então, em vez de fazer isso progress.setProgress(currentprogress); faça progress.setProgress((int) p);
Comment: eu esqueci de colocar essa parte,int currentprogress = (int) p;
Answer: O progress.setIndeterminate(true); faz com que ele não meça o progresso. Muda para false que deve resolver.

ProgressDialog não sai do 0%


Reverse Proxy Server Cloud Architecture (AWS + nginx)

Question: Currently I cache responses using nginx + fastcgi. I'm in the process of moving my app to AWS. I'm architecting a horizontally scaled approach, but trying to determine where best to put nginx + fastcgi cache.
I found a few solutions from my own research, both with significant drawbacks.

Use AWS Elastic Load Balancer to balance a cluster of web apps. Each web app runs it's own nginx and web server stack. Drawback: the cache on each server needs to be warmed. Worst case 1/n the hit rate.
Put nginx + fastcgi in front of the AWS ELB so the cache is centralized for maximum hits. Drawback: single point of failure - if nginx dies traffic doesn't pass thru to the ELB. Added nginx instance.

I'd appreciate any suggestions of common architectures that overcome the drawbacks outlined above.
Comment: You could always combine the two a bit, and have an ELB for a couple nginx+fcgi instances that pass requests along to the web server stack's ELB.
Comment: @ceejayoz, true. That eliminates the single point of failure drawback, but combines the other **two drawbacks**.
Comment: Not necessarily. You can likely have fewer servers in the first tier, meaning fewer caches to be warmed up, and you've eliminated the SPOF that's the drawback of the first.
Answer: I've set up this stack many times on AWS.  Option #1 has always worked well for me and is the one I normally choose because it's the simplest.  I'm curious to know how much traffic you're dealing with where the less-than-ideal initial cache hits are an issue?  I'm serving a few million pageviews a month on a pair of m1.small instances and they're barely scratched.
Other thoughts:

Nginx can use memcached as a caching store.  Plug it into an ElasticCache cluster.  This will give you a very fast, centralized datastore for multiple instances to connect to for cache contents.  (I've never done this, but it looks doable.  Please post results if you do attempt it.)
The SPoF problem mentioned in Option #2 can be mitigated by setting up an autoscaling group that contains a single instance.  If it dies, it should come back online in a matter of a couple of minutes.  You will need to fiddle with a boot script that automatically grabs the Elastic IP though.
Keep in mind that putting anything in front of a ELB will require that you use VPC.  This is generally good practice anyhow, but it can have a steep learning curve.
CloudWatch Alarm Actions were just announced today.  You could do some cool stuff with this to help minimize the SPoF issue.
Comment: If mins of downtime isn't workable, you can run two identical instances, each in a separate AZ, and use a floating EIP.  See [this design pattern](http://en.clouddesignpattern.org/index.php/CDP:Floating_IP_Pattern).
Comment: Thanks. I'll look into memcached as a shared caching layer for nGinx to mitigate the low hit ratio. The SPoF is a large concern given the role of this box (single entry). Minutes of downtime while another instance boots is unacceptable.
Answer: Looks like you are thinking about the same architecture what I am planning to implement.
I have thought of both the scenarios and the same approach, and then settling up to this solution.
I will be using the 2nd option, setting up Caching solution in front of Load Balancer. I am going to handle the Single point of Failure problem with adding one more node having standby and using something like HAProxy to keep checking the health of the machine. If first Caching machine went down, then HAProxy will automatically move the IP and move the traffic to the other Caching Standby Machine and hence the Single point of failure will be handled.
Also, in my scenario, I will be using something like Varnish, instead of Nginx+php, which I will suggest you too, incase your application is not dependent on Nginx. Varnish will have it's own built in Load Balancer, hence you will skip the AWS Load Balancer too.
Hope this will help you building a robust and scalable infrastructure.
Comment: Thanks for sharing. Nginx has a built in load balancer as well. But using these instead of ELB does not offer auto-scaling, among other things.
Comment: Oh yes, that's right. My architecture is kind of fixed, so never thought about auto-scaling. Thanx for sharing that thought.


The reason (and intuition) behind why stochastic gradient descent can get stuck on a local minimum

Question: Suppose you want to find $k$ that minimises your cost function $J(k)$. We may want to apply batch gradient descent or stochastic gradient descent. Let's deliberately initialise $k$ with the same number for both BGD and SGD to see the difference in their behavior.
If you apply BGD, this optimisation may look like this:

On the other hand if you apply SGD, this optimisation may look like this:

In both pictures the blue solid curve represents the cost function $J(k)$. But in the second picture there are also dotted curves. In my experiment I used batch size which was $10\text%$ of the whole dataset. So each dotted curve represents the cost function for the current batch. From these dotted curves you can see that the gradient of the batches' cost functions happened to be large multiple times in a row. That's why the point was "pushed" to the deeper minimum.
$\left(*\right)$ As I can see it, if the gradient of most batches' cost functions at a particular point is small enough, then the red point isn't able to get out from the local minimum, precisely because this local minimum makes those gradients small enough. In simple words, that minimum makes the mean gradient of all different batches so small that these batches don't have strength enough to push the point out of this deeper minimum.
Question 1: Was I right in $\left(*\right)$? If the point can't get out from some local minimum, then does it imply that all (or the majority?) these batches have reached their own local minima? Meaning that there is a common local minimum at $k = 0$ in our example. You can see it observing different dotted curves. My line of reasoning is the following one: If most of different batches haven't reached their local minima, then they will eventually push the red point out of this minimum in the picture above (I know it's wrong to say "batches reached their local minima", but I didn't find a better way to express this). So I believe that the point can't get out of the local minimum if this local minimum is the local minimum for the most (how many?) batches.
Question 2: It's not clear to me where does this red point tend to? It obviously can't always tend to a global minimum (which is $k = 2$). My guess is that the point tends to some minimum near the point's initial position that is local minimum for the most of batches (dotted curves). But I'm not sure if I'm right. And what if there is no common minimum for all different batches (dotted curves)?
Question 3: If I'm right in Question 1 and Question 2, then is it the main advantage of SGD? I mean if we use BGD, then it just looks for the nearest local minimum. But if we use SGD, then it looks for the local minimum that is going to be the local minimum for most of the batches? It implies then that this latter local minimum reduced most batches' gradients enough not to escape this local minimum.
Question 4: So I believe that BGD answers the question: "Where should the red point go to reduce the overall error?". And SGD answers the question: "Where should the red point go to reduce the current batch error?". Then if most of the batches says: "Go left", then the red point gets out from the local minimum and moves to the left and, therefore reduces the overall error even more (because most of the batches said to go left). Is that right?
If possible, elaborate on this a little bit so that I can build the intuition. Thank you in advance!

As a side note, $J(k) = \frac 1n\sum\left(\sin\left(kX\right) - Y\right)^2$, where $X$ is a single feature vector and $Y$ is a vector of true answers and $k$ is a coefficient we want to find so that $J(k)$ was minimal.
Comment: Nice animations. If I understand your question correctly, you are asking that if in batch gradient descent, once a local minimum is reached, then there is no way to get out, but in stochastic gradient descent, because the cost function depends on the batch, then there is a chance that the gradient at the current point is big enough for one of the batches that the next step jumps out of the minimum?
Comment: @mhdadk, Thank you! Yes, that's a part of the question. The true question is "If BGD looks for the nearest minimum, then what kind of minimum does SGD look for?". But let me edit my post a little bit, so that it becomes clearer.
Answer:
Question 1: Was I right in $\left(*\right)$? If the point can't get out from some local minima, then does it imply that all (or the majority?) these batches have reached their own local minimas? Meaning that there is a common local minima at $k = 0$ in our example. You can see it observing different dotted curves. My line of reasoning it the following one: If most of different batches haven't reached their local minimas, then they will eventually push the red point out of this minima in the picture above (I know it's wrong to say "batches reached their local minimas", but I didn't find a better way to express this). So I believe that the point can't get out of the local minima if this local minima is the local minima for the most (how many?) batches.

Not quite. A necessary, but not sufficient, condition of a local minimum is that $\nabla J(k) = 0$. Therefore, it is possible that $\nabla J(k) = 0$ for all batches, but it is possible that this is just a saddle point for some batches and not a local minimum. A sufficient condition for a local minimum is that $\nabla J(k) = 0$ and the Hessian is positive-definite. If the Hessian is also positive definite for all batches at a single point, then this local minimum is common for all batches.

Question 2: It's not clear to me where does this red point tend to? It obviously can't always tend to a global minima (which is $k = 2$). My guess is that the point tends to some minima near the point's initial position that is local minima for the most of batches (dotted curves). But I'm not sure if I'm right. And what if there is no common minima for all different batches (dotted curves)?

The purpose of stochastic gradient descent, besides making computing the cost function $J(k)$, is the randomness. As you have observed, the cost function becomes random. Normal gradient descent without the randomness depends on a steady target (where $\nabla J(k) = 0$). In stochastic gradient descent, the target is always moving, so how can you expect it to converge to a single point?
While it may seem that a moving target is pointless, you may have observed that there is a chance that one of the batches has a large gradient at the local (not global) minimum of another batch that SGD is currently stuck on, which could push it to jump out of the local minimum for another chance at arriving at a global minimum.
Furthermore, if your batches have common statistics, then it is reasonable to predict that a local minimum for one batch will be close to a local minimum for another batch. This page on stochastic approximation could be helpful.
Responses to comments

I know that it's possible for SGD to start in a deep local minimum and end up in a shallower (higher) local minimum. Question 1: is it just because there wasn't a minimum deep enough to reduce batches' gradients enough not to escape this minimum?

It could also depend on the curvature of the deeper local minimum. If its curvature is very steep, then it is possible that gradients around the deeper local minimum are big enough to cause a jump outside of it, regardless of how deep the local minimum actually is.

Question 2: What should we do to be sure that SGD ends up in a minimum that is not worse than its initial minimum? Just reduce learning rate or batch size to make it less stochastic and therefore to prevent it from escaping all the local minima? I mean if we make the red point less stochastic, then it's going to find a local minimum that is able to hold the red point?

Note: increasing, not decreasing, the batch size makes SGD less stochastic. In classic optimization problems, normal gradient descent makes use of a line search to avoid jumping out of minimums. However, in the context of neural networks, where millions of parameters are optimized, this is not emphasized as much. Have a look at section 9.2 of Boyd's Convex Optimization book for details. Sections 9.3 - 9.5 are helpful too.
Nevertheless, even line search will struggle, since the cost function keeps changing with every batch. Really, the biggest solution is to try to line up the minima of the cost functions for each batch.

Question 3: We believe that if the red point is stuck in a local minimum, then by using SGD, we can push it to jump out of this minimum for a chance at arriving at a better minimum, right? But how do we know that it won't escape from that better minimum? We just hope that there is a local minimum that will reduce enough the error, and therefore the gradient of the majority of batches so that the red point is stuck in such a minimum? I mean: In what kind of minima do we expect the red point to get stuck? And why do we think that these minima are better than one you can get with BGD?

There really is no guarantee that the red point will stay in place over different batches, unless the cost function looks very similar for each batch. It could end up at a better or worse place.
Comment: Thank your for the answer! I've understood about saddle point and that the red point doesn't tend anywhere. But a couple of things is still unclear to me. I know that it's possible for SGD to start in a deep local minimum and end up in a shallower (higher) local minimum. ***Question 1***: is it just because there wasn't a minimum deep enough to reduce batches' gradients enough not to escape this minimum?
Comment: ***Question 2***: What should we do to be sure that SGD ends up in a minimum that is not worse than its initial minimum? Just reduce learning rate or batch size to make it less stochastic and therefore to prevent it from escaping all the local minima? I mean if we make the red point less stochastic, then it's going to find a local minimum that is able to hold the red point?
Comment: ***Question 3***: We believe that if the red point is stuck in a local minimum, then by using SGD, we can push it to jump out of this minimum for a chance at arriving at a ***better*** minimum, right? But how do we know that it won't escape from that better minimum? We just hope that there is a local minimum that will reduce enough the error, and therefore the gradient of the majority of batches so that the red point is stuck in such a minimum? I mean: In what kind of minima do we expect the red point to get stuck? And why do we think that these minima are better than one you can get with BGD?
Comment: @mathgeek I've responded to your comments at the bottom of my answer.
Comment: Thank you again! I have my last confusion. You said that the red point could end up at a better or worse place. But if we don't know for certain that new minimum is going to be better, then why to use SGD?
Comment: @mathgeek the main reason is to make computing $J(k)$ tractable. In your $J(k)$, try increasing $n$ to 1 million or 10 million. You will quickly realize that you do not have enough memory to do this. So, you will have to settle for breaking down your dataset of size $n$ into smaller batches, and then computing $J(k)$ and it's gradient for each batch.
Comment: I asked with a bit different context. Is there something that tell you: "Hey, if you use SGD instead of BGD, then you're likely to found a better minimum"?
Comment: @mathgeek I think if we had infinite memory, then almost everyone would use BGD. Why would anyone want a moving target at each step?
Comment: I don't know. It's just that everyone says that SGD helps to avoid local minima problem. But I can't see how. I just see that it can push the point out of local minimum, but I can't see any good in it.


jquery code for drupal 6

Question: I try to implement this simple js tooltip script on drupal 6 site.
http://jsfiddle.net/wrN2u/50/
$(document).ready(function(){

$('#container').on('mouseenter', '#radiobtn', showBox);
$('#container').on('mouseleave', '#radiobtn', hideBox);

function showBox(e){
var x = e.pageX + 20;
var y = e.pageY + 20;
$('#hoverbox').fadeIn();
$('#hoverbox').offset({ left: x, top: y });
}
});
function hideBox(){
$('#hoverbox').fadeOut();
}

However, the framework is 1.8.2
The script is not working under 1.3.2 which uses drupal 6
Can somebody help me with js code for 1.3.2?
Thank you very much
Comment: Please don't post answers inside question and avoid link-only answers. Link can still be found in edit history, if anyone wants to turn it into an answer.
Answer: if you don't want to upgrade the jQuery version. Please try this.
http://jsfiddle.net/ravindrasingh22/3HVpW/
$(document).ready(function() {

    var changeTooltipPosition = function(event) {
      var tooltipX = event.pageX - 8;
      var tooltipY = event.pageY + 8;
      $('div.tooltip').css({top: tooltipY, left: tooltipX});
    };

    var showTooltip = function(event) {
      $('div.tooltip').remove();
      $('
I\' am tooltips! tooltips! tooltips! :)
')
            .appendTo('body');
      changeTooltipPosition(event);
    };

    var hideTooltip = function() {
       $('div.tooltip').remove();
    };

    $("label#tooltip2'").bind({
       mousemove : changeTooltipPosition,
       mouseenter : showTooltip,
       mouseleave: hideTooltip
    });
});

HTML Code
Mouse Hover here

CSS Code
#hint{
     cursor:pointer;
    }
    .tooltip{
        margin:8px;
        padding:8px;
        border:1px solid blue;
        background-color:yellow;
        position: absolute;
        z-index: 2;
    }

Comment: hello, I tried this code but doesn't work for drupal 6. I read more about jquery version in drupal 6 and found out, that drupal 6 uses only 1.3.2 version of jquery. I edited also the original question. Would it be possible to rewrite the code for thos version? Thank you for your help.
Comment: previously you asked for 1.6.4 version of jQuery.  for that the above given code is working fine...you need to upgrade the your jquery version if possible
Answer: I would suggest you to add the latest jQuery library to your site. You can do that by:

Copying the jQuery library to your theme's JS folder.
Then modifying the .info file of the theme and adding the following line to it:
scripts[] = JS/jquery-1.8.2.js. Do this if you want to use the same library throughout your project. OR
If you want to use it for some particular scenario (in custom module, for example) you can use drupal_add_js() function to do that.
drupal_add_js(drupal_get_path('theme', 'your_custom_theme') . '/JS/jquery-1.8.2.js');
Answer: With jQuery 1.3.2 you can't use on() (or even delegate()) so you're left with the live() method:
$('#radiobtn').live('mouseenter', showBox).live('mouseleave', hideBox);

At first glance I can't see anything else that would need to change.
Comment: hello, I changed what you suggested but it is not working for some reason. here is my test site www(dot)test(dot)biome(dot)sk js file called tooltip is loaded and #hoverbox is present as well. Can not figure out why there is no tooltip showing.
Comment: how is it possible to fix it? I used simple js files like this before and it never happened to me. The code is simple, I can see that jquery 1.3.2 is loaded what else should I check?
Comment: I'm afraid this isn't the right place to ask about javascript problems unless they directly involve Drupal (which this doesn't, you could add the same script to any site and still be experiencing the same problem). Try searching on Stack Overflow for similar issues, and if you can't find any it might be worth asking a question over there

jquery code for drupal 6


Find the equation of an exponential function knowing that its gradient=y coordinate

Question: Find the equation of an exponential function knowing that its gradient=y coordinate.
$f(x)=k^x$
   What values would have to take $k$?
The $y$ coordinate has to be equal to the gradient, e.g. in $y=1$, the gradient has to be $1$.
Comment: Do you mean $y'(x)=y(x)$ ?
Comment: @YvesDaoust Yes, I added some information to try to make it clearer.
Comment: You mean like an $e^x$ function? Because if you take the derivative of it and substitute in an x you get the y-coordinate of the original function.
Answer: If you are given that
$$f(x)=k^x$$
then $$f'(x)=k^x\log k=f(x)$$ is achieved when $$\log k=1.$$


Find minimum and maximum value of $\sqrt{5\cos ^2x+1}+\sqrt{5\sin ^2x+1}$

Question:
Blockquote

Find min,max of function $$T=\sqrt{5\cos ^2x+1}+\sqrt{5\sin ^2x+1}$$

Max

By squaring both side and AMGM:
$$T^2=7+2\sqrt{5\cos^2x+1}\cdot \sqrt{5\sin^2x+1}$$
$$\le 7+5\left(\cos^2x+\sin^2x\right)+2=14$$
Or $$T\le \sqrt {14}$$

About minimal value:By $\sqrt x +\sqrt y \ge \sqrt{x+y}$

So $T\ge \sqrt{5+1+1}=\sqrt 7$
I think the minimal value has a little wrong. Pls help me.
Comment: Does this answer your question? [The maximum and minimum values of the expression](https://math.stackexchange.com/questions/1364170/the-maximum-and-minimum-values-of-the-expression)
Comment: The minimum is right. It's the maximum that may be wrong. You should have $1+\sqrt 6.$
Comment: @Allawonder: Unless I am mistaken, the maximum is right and the minimum is $1+\sqrt 6$. It is the case $a=\sqrt 6$, $b=1$ from the above-referenced (and possible duplicate target) Q&A.
Comment: In fact, you are right. My above comment about the maximum is wrong. The maximum is $\sqrt 14.$ I made a silly mistake.
Comment: @MartinR Yes, I was wrong about the maximum. However, the minimum is $\sqrt 7,$ which is attained when $\sin x=-1/5.$
Comment: @Allawonder: If $\sin x = -1/5$ then $\sin^2 x = 1/25$ and $\cos^2 x = 24/25$. I do not see how you get $T=\sqrt 7$ in that case. – Also in your answer it seems that you substituted $x$ for $\sin^2 x$, and that cannot be negative.
Comment: @MartinR Oh, that's true. I was all the while thinking of a substitution $\sin x\mapsto x.$ Thanks.
Answer: For minimum,
$$T=\sqrt{(\sqrt{5\cos ^2x+1}+\sqrt{5\sin ^2x+1})^2}\\
=\sqrt{7+2\sqrt{25\cos^2x\sin^2x+6}}\\
\ge \sqrt{7+2\sqrt6}=1+\sqrt6
$$
Answer: The quantity $T(x)\geq0$ is a ${\pi\over2}$-periodic function of $x$. It is extremal, i.e., maximal or minimal, iff $$T^2=7+2\sqrt{(5\cos^2 x+1)(5\sin^2 x+1)}$$ is extremal, and this is the case iff the radicand on the RHS
is extremal. Letting $\sin^2 x=:t$ this means that
$$\phi(t):=\bigl(5(1-t)+1\bigr)(5t+1)=6+25(t-t^2)\qquad(0\leq t\leq1)$$
should be extremal. This $\phi(t)$ takes its minimum $6$ at $t=0$ and $t=1$, and takes its maximum $6+{25\over4}={49\over4}$ at $t={1\over2}$.
From $T^2=7+2\sqrt{6}=\bigl(1+\sqrt{6}\bigr)^2$ it follows that the minimum of $T$ is $1+\sqrt{6}$. Similarly, from $$T^2=7+2\cdot\sqrt{49\over4}=14$$ it follows that the maximum of $T$ is $\sqrt{14}$.
Answer: Hint. That's equivalent to extremising $$\sqrt{6-5x}+\sqrt {1+5x}$$ on the interval $[0,1].$ Can you now continue?
Comment: but if $x=1/2$ we got $T=\sqrt {14}>1+\sqrt 6$
Comment: @user774564 That was a mistake. The maximum is $\sqrt 14$ and the minimum $\sqrt 7.$
Comment: @user774564 Note that the previous domain I gave was not optimal. Check out the edit. So it stands that the minimum is indeed $1+\sqrt 6,$ and the maximum still $\sqrt{14}.$


How to access a dictionary within a class?

Question: I'm accessing a class from another Python file by importing it at the top of the file.  The class looks something like this:
class Something(object):
    a_dictionary = {1: 2, 3: 4, 5: 6}

    def __init__(self):
        stuff....

My question is how would I be able to access a_dictionary from the other file.  I can't seem to find how to access a dictionary not within a function in another file.
I'm a beginner in Python and I have looked everywhere to find this answer and I can't.  I essentially need to be able to iterate through the above dictionary from the other file.
Comment: `Something.a_dictionary` ?
Comment: for more insight into the topic : https://stackoverflow.com/questions/68645/static-class-variables-in-python
Answer: Something like this should work:
from your_module import Something
print (Something.a_dictionary) # prints {1: 2, ...}

Answer: in this case, a_dictionary is a class variable, and therefore part of the object's __dict__. You would access this dictionary in another file like this:
from your_file import Something

new_object = Something()
print(new_object.a_dictionary)

Accessing a class variable is done the same way as accessing an instance variable. The only difference between a class variable and instance variable is that class variables are the same value across all instances of an object, whereas an instance variable is specific to a single instance.
Answer: import otherfile

print(otherfile.Something.a_dictionary[1])

Output

2

Comment: I guess the upvotes were awarded at a time when this answer contained incorrect code.
Comment: @MarcusLind I reverted your edit, because it changed the code in this answer significantly.  If you want to do things in a different fashion, post an answer of your own.
Comment: I thought he wanted to access to a dictionary in a class of another file... so I imported the file and printed the dictionary... wasn't that the goal of the questions?


Event ID: 2002 Source: IIS-W3SVC-PerfCounters on Windows Server 2012

Question: My server is showing on Event Viewer this error every hour.
Log Name:      Application
Source:        Microsoft-Windows-IIS-W3SVC-PerfCounters
Date:          03/10/14 9:07:42
Event ID:      2002
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      MyServer.MyDomain.local
Description:
Setting up Web Service counters failed, please make sure your Web Service counters are registered correctly.
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Microsoft-Windows-IIS-W3SVC-PerfCounters" Guid="{90303B54-419D-4081-A683-6DBCB532F261}" EventSourceName="W3CTRS" />
    <EventID Qualifiers="49152">2002</EventID>
    <Version>0</Version>
    <Level>2</Level>
    <Task>0</Task>
    <Opcode>0</Opcode>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2014-10-03T12:07:42.000000000Z" />
    <EventRecordID>2193581</EventRecordID>
    <Correlation />
    <Execution ProcessID="0" ThreadID="0" />
    <Channel>Application</Channel>
    <Computer>MyServer.MyDomain.local</Computer>
    <Security />
  </System>
  <EventData>
    <Binary>02000780</Binary>
  </EventData>
</Event>

Searching through the web, I found many articles saying "this error happens because of corrupted entries on registry". I found many webpages with tutorials or tips to solve this issue on Windows Server 2008 or older but no one worked on my Windows Server 2012.
This are some of the pages I followed instructions:

http://technet.microsoft.com/en-us/library/cc734941(v=ws.10).aspx
http://technet.microsoft.com/en-us/library/cc735037(v=ws.10)
http://support.microsoft.com/kb/2554336
http://jesperarnecke.wordpress.com/2013/12/18/corrupt-or-broken-performance-counters-windows-2012/

Do you have another tip of how can I solve this error?
Thanks in advance!
Answer: I followed the instructions of this webpage:

http://www.vikingengineer.com/microsoft/iis-servers-get-iis-w3svc-perfcounters2002-and-iisinfocounters1001-errors-in-application-log/

I did this steps before and I'm not sure why "cutting and pasting" the steps from this website worked. The commands were:
cd c:\Windows\Inf\W3SVC
lodctr .\0409\w3ctrs.ini

After that, the Warning Event ID 2003 comes up. To solve this warning I followed the instructions from:

http://support2.microsoft.com/kb/932813/en-us

Typing this command:
lodctr /T:W3SVC


Como exibir a SQL History no SQL Developer?

Question: Necessito visualizar todas alterais em uma procedure.
A ferramenta SQL Developer tem uma barra de ferramenta que
armazena um historico de alterações.
Como posso habilitar/visualizar ?
Imagem da fucionalidade
Comment: Infelizmente não funcionou!
Comment: Dá uma olhada nessa imagem: https://i.stack.imgur.com/oZTQP.png
Comment: Meu objetivo é visualizar o histórico de alterações em uma procedure. Afim de identificar o que foi alterado
Comment: só consigo visualizar as alteções em aquivos .sql as procedures não consigo visualizar o histórico
Answer: Nas telas abaixo basta clicar na aba history para visualizar as alterações
feitas o arquivo.


How to send and use the V7R3 created program object in V7R2 version of iseries/AS400?

Question: I have tried using save file with target system version *PRV/V7R2M0 but save file not saving the objects which are created with V7R3. How can i still use the V7R3 object in V7R2.
Answer: SAVOBJ TGTRLS(V7R2M0) is what you need.
However, the object has to be compatible with that prior release.
Using the DSPxxx commands, such as DSPOBJD, DSPPGM you can see what version the object was created on and/or for...
Module created on  . . . . . . . . . . . . . . :   V6R1M0
Module created for . . . . . . . . . . . . . . :   V6R1M0

Creation date/time . . . . . . . . . :   11/27/12
Source file date/time  . . . . . . . :   09/27/11
System level . . . . . . . . . . . . :   V6R1M0

I seem to recall for some objects, it's shown as "earliest release supported" or something like that.
Trying to save incompatible objects to a prior release should result in an error message.
Newly created Program/service program objects have to be compiled with TGTRLS(*PRV) in order for the objects to be saved with TGTRLS(*PRV).
So for example
CRTBNDRPG PGM(MYPGM) TGTRLS(*PRV)


How can I overwrite existing file and keep same filename when uploading new

Question: I have content type 'Document' and added the 'Upload document' field with type 'File'
I want to replace file and update the node. I'm using below code
<code>function custom_file_upload_form_alter(&$form, $form_state, $form_id) {
  if($form_id == "test_node_form") {
    $form['#submit'][] = 'custom_fileupload_submit';
  }
}

function custom_fileupload_submit(&$form, &$form_state) {
 $file = file_save_upload('field_document', array(
    'file_validate_extensions' => array('pdf'), // Validate extensions.
    'public://', FILE_EXISTS_REPLACE
  ));
  if ($file) {
    // Move the file, into the Drupal file system
    if ($file = file_move($file, 'public://', FILE_EXISTS_REPLACE)) {
      // Save the file for use in the submit handler.
      $form_state['storage']['file'] = $file;
    }
    else {
      form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
    }
  }
  else {
    form_set_error('file', t('No file was uploaded.'));
  }
}
</code>
Here file_save_upload() not working. I have debug the $file variable but it's print nothing.
Comment: Look at your call to `file_save_upload` more carefully. It's likely you didn't mean to include the destination and constant as part of the validation array
Comment: 'field_document' is file field name is this correct?
Answer: You can just use the Upload File Replace module to solve this use case instead of custom code:

This is a small utility module that automatically stops Drupal from renaming new files upload via filefield CCK. When 2 files with the same name exist, the older files will be renamed.
Comment: Yes I have tried this module it's not working with another functionality related to file upload.  Is there any other way to do by custom module?


How to show Search API search box? No block available, nothing from

Question: I'm updating a site to use Search API (with Search API DB) instead of the built-in search module. I've set up my Search API server and search, indexed everything, and now am just trying to replace the old search box with the new one in the theme.
But I can't find any way to do this.
Before disabling the built in search module, there was only one search block. After disabling, there are none, including after clearing caches. According to Integrate core search block with search_api and Solr and various other sources, I should get a search block automatically, but I don't.
Before, I got the search box into my template .tpl file with <?php print render($search_box); ?>. After, this throws an error.
I can't find anything on what to use instead, and the relevant documentation page about search forms talks only about search results pages, not about how to put a search box on other pages. I'm confused at how hard it is to find how to do something so basic. I can't find anything about how to find the code to either populate this variable in template.php or access any inbuilt template variable.
How do I show a basic search block on the front page that integrates with search api? is similar but the asker reports its answer doesn't work, and I'm not fussy about whether it's specifically a block or specifically on the front page or connected to a view, I just want the search input element.
How do I add a Search API search box to a theme? How do I make it generate the block or load the search box from code?
Answer: Maybe not the best option, but to get a usable Search Block from the Views module (that includes the Search API Views submodule), you need to activate the "Expose Form >> Exposed form in block" option in your Views advanced configuration. This is what it looks like:

Good luck!
Answer: In Views Under the Filter Criteria click the 'Add' button.
Choose 'Search: Fulltext search'.
Check the checkbox 'Expose this filter to visitors, to allow them to change it'.
Place the block.
When people submit a search via this Block it will only take them to the View page that is was created on.  If that Page is Disabled in your View it will not work.  It will give you a page not found.
If you are using a Content Pane in a Panel instead of a Page you need to go into the 'Allow Settings' and check the checkbox 'Path override'.  That will allow you to change the path to the path you are using in your Panel page.
Answer: Stefanos and heart-cooks are correct, I just wanted to mention that you don't need to try to make a block using the typical views tab as in "add a new block".. ie, don't use this:

Clicking on the "expose form in block" is enough to create the block.


Node reference solution for a content type which referenced to two fields. (company, product & review)

Question: My website has three content types: company, product & review.
1). The product has a field referenced to a company node using Node URL Reference module.
2). The review has two fields, one referenced to company node, another referenced to product node.
The question is how to implement the item 2) following the behaviours described below:

While creating review node from company node, the product field should be updated to the products which belongs to that company.
While creating a review from product node, the company & product fields should be auto-filled.

Could you help me? I research this issue for several days but haven't resolved completely. Thanks a lot.
Comment: did you take look at Node URL Reference module read me? Check the section under 'Advanced: Build your own links'
Comment: How are you creating the review node from the company node?
Answer: Try entityreference_prepopulate
This will allow you to create a link with query string to pre-fill selections on an entity reference form field.


Laravel / Eloquent - Consulta em mais de uma tabela

Question: Tenho as seguintes Tabelas/Models e não estou conseguindo fazer uma consulta:
Model 1
id | Name
---+---------------
1  | Model1.1
2  | Model1.2
3  | Model1.3

Model 2
id | Name     | model1_id
---+----------+----------
1  | Model2.1 | 1
2  | Model2.2 | 2
3  | Model2.3 | 3

Model 3
id | Name     | model2_id
---+----------+----------
1  | Model3.1 | 1
2  | Model3.2 | 2
3  | Model3.3 | 3

class Model1 extends Model
{
   public $table = 'model1';

   const CREATED_AT = 'created_at';
   const UPDATED_AT = 'updated_at';
   protected $dates = ['deleted_at'];
   public $fillable = ['name','model2_id'];
   protected $casts = ['name' => 'string'];
   public static $rules = [];

   public function model2()
   {
      return $this->belongsTo(\App\Models\Model2::class);
   }
}

class Model2 extends Model
{
   public $table = 'model2';

   const CREATED_AT = 'created_at';
   const UPDATED_AT = 'updated_at';
   protected $dates = ['deleted_at'];
   public $fillable = ['name'];
   protected $casts = ['name' => 'string'];
   public static $rules = [];

   public function model1()
   {
      return $this->hasMany(\App\Models\Model1::class);
   }

   public function model2()
   {
       return $this->belongsTo(\App\Models\Model2::class);
   }
}

class Model3 extends Model
{
   public $table = 'model3';

   const CREATED_AT = 'created_at';
   const UPDATED_AT = 'updated_at';
   protected $dates = ['deleted_at'];
   public $fillable = ['name',];
   protected $casts = ['name' => 'string'];
   public static $rules = [];

   public function model2()
   {
      return $this->hasMany(\App\Models\Model2::class);
   }
}

Com o exemplo abaixo não consegui pois o que preciso é saber os Model1 que relacionados ao Model3.
$model1 = Model3::where('model2_id', 2);

Comment: Veja se isso pode te ajudar: [Consultas entre tabelas com Eloquent - Laravel 5](https://pt.stackoverflow.com/questions/55283/consultas-entre-tabelas-com-eloquent-laravel-5)
Comment: Acho que isto resolve: https://laravel.com/docs/5.5/eloquent-relationships#has-many-through
Comment: Muito obrigado... ajudou bastante a resolver o problema
Answer: Relacionamento N:M Laravel
Os models estão configurado errado no item fillable faltou colocar os campos corretamente e as suas relações estão todas erradas, vide documentação para maiores informações e o links abaixo com exemplos de como configurar os relacionamentos 1:1, 1:N e N:M:

Salvar relacionamento 1:1 no Laravel 5.3
Como usar o relacionamento hasmany no laravel 5.2?
Salvar varios atributos para um mesmo objeto no Laravel

Exemplo modificado:
class Model1 extends Model
{
   public $table = 'model1';

   const CREATED_AT = 'created_at';
   const UPDATED_AT = 'updated_at';
   protected $dates = ['deleted_at'];
   public $fillable = ['name'];
   protected $casts = ['name' => 'string'];
   public static $rules = [];

   public function model2()
   {
      return $this->hasMany(\App\Models\Model2::class,'model1_id', 'id');
   }
}

class Model2 extends Model
{
   public $table = 'model2';

   const CREATED_AT = 'created_at';
   const UPDATED_AT = 'updated_at';
   protected $dates = ['deleted_at'];
   public $fillable = ['name','model1_id'];
   protected $casts = ['name' => 'string'];
   public static $rules = [];

   public function model1()
   {
      return $this->belongsTo(\App\Models\Model1::class,'model1_id', 'id');
   }

   public function model3()
   {
       return $this->hasMany(\App\Models\Model3::class,'model2_id', 'id');
   }
}

class Model3 extends Model
{
   public $table = 'model3';

   const CREATED_AT = 'created_at';
   const UPDATED_AT = 'updated_at';
   protected $dates = ['deleted_at'];
   public $fillable = ['name','model2_id'];
   protected $casts = ['name' => 'string'];
   public static $rules = [];

   public function model2()
   {
      return $this->belongsTo(\App\Models\Model2::class,'model2_id','id');
   }
}

A pergunta eu fiquei um pouco na dúvida, mas, eu acho que é um simples join entre as tabelas:

Com o exemplo abaixo não consegui, pois o que preciso é saber os Model1 que relacionados ao Model3.

$model1 = Model1::join('model2','model2.model1_id','=','model1.id')
                ->join('model3','model3.model2_id','=','model2.id')
                ->where('model3.model2_id', 2)
                ->get();

Referencias

Laravel: defining-relationships
Soma da multiplicação da quantidade por valor do produto em vendas diarias
Eloquent: Relationships
Comment: Ajudou muito... consegui resolver o "problema" com todas as dicas.


Filtrar ao selecionar uma checkbox

Question: Preciso fazer um filtro onde é mostrado certos dados quando selecionado alguma(s) checkbox.
Por exemplo:
Foi marcado o checkbox "Aguardando embarque" e "Recebido", então devera mostrar uma lista em uma tabela que contenham os Status dos checkbox selecionados.
Checkbox:
Aguardando embarque | Embarcado | Recebido | Em análise | Aguardando aprovação
--------------------|-----------|----------|------------|---------------------
          X         |           |     X    |            |

Saída:
Número Ose |  Nome  | Status da Ose | Perfil Usuário
-----------|--------|---------------|----------------
     65    |  Admin |  Aguardando   |  Administrador
           |        |   Embarque    |
-----------|--------|---------------|----------------
     69    |  Admin |   Recebido    |  Administrador

Caso eu não tenha sido claro, por favor comentem para que eu possa lhes fornecer mais informações sobre o que eu preciso.
Answer: Solução:
Na Controller eu faço um filtro para cada Checkbox, no caso do exemplo abaixo farei somente três:
Controller
  $this->Filter->addFilters(
          array(
              'filter1' => array(
                   'Filtro1.descricao' => array(
                       'operator' => 'ILIKE',
                       'value' => array(
                           'before' => '%',
                           'after' => '%'
                        )
                    )
               )
               'filter2' => array(
                   'Filtro2.descricao' => array(
                       'operator' => 'ILIKE',
                       'value' => array(
                           'before' => '%',
                           'after' => '%'
                        )
                    )
               )
               'filter3' => array(
                   'Filtro3.descricao' => array(
                       'operator' => 'ILIKE',
                       'value' => array(
                           'before' => '%',
                           'after' => '%'
                        )
                    )
               )
          )
   );

Depois inicializo as variáveis que serão utilizadas no foreach abaixo:
$conditions = array();
$vFiltro = array();
$filtro1 = '';
$filtro2 = '';
$filtro3 = '';

foreach ($this->Filter->getConditions() as $chave => $valor) {
    if ($valor != '%0%') {
        if ($chave == 'Filtro1.descricao ILIKE') {
            $filtro1 = $valor;
        }
        if ($chave == 'Filtro2.descricao ILIKE') {
            $filtro2 = $valor;
        }
        if ($chave == 'Filtro3.descricao ILIKE') {
            $filtro3 = $valor;
        }
    }
}

Depois se os filtros não estão vazios eu adiciono cada filtro na variável de condições $conditions para fazer a paginação.
if (!empty($filtro1)) {
    $conditions[] = "Filtro1.descricao ILIKE '" . $filtro1 . "'";
} elseif (!empty($filtro2)) {
    $conditions[] = "Filtro2.descricao ILIKE '" . $filtro2 . "'";
} elseif (!empty($filtro3)) {
    $conditions[] = "Filtro3.descricao ILIKE '" . $filtro3 . "'";
} else {
    $conditions[] = "";
}

Após fazemos a paginação para mostrar os itens que queremos.
$this->Paginator->settings = array(
    'fields' => array('Ose.id', 'user_nome',
                      'Status.descricao', 'Group.descricao'),
    'joins' => array(
        array('table' => 'groups',
            'alias' => 'Group',
            'type' => 'LEFT',
            'conditions' => ['User.group_id = Group.id'],
        ),
        array('table' => 'statuses',
            'alias' => 'Status',
            'type' => 'LEFT',
            'conditions' => ['Status.id = Ose.status_id_destino'],
        ),
        array('table' => 'statuses',
            'alias' => 'Filtro1',
            'type' => 'LEFT',
            'conditions' => ['Filtro1.id = Ose.status_id_destino'],
        ),
        array('table' => 'statuses',
            'alias' => 'Filtro2',
            'type' => 'LEFT',
            'conditions' => ['Filtro2.id = Ose.status_id_destino'],
        ),
        array('table' => 'statuses',
            'alias' => 'Filtro3',
            'type' => 'LEFT',
            'conditions' => ['Filtro3.id = Ose.status_id_destino'],
        ),
    'condition' => array($conditions),
    'order' => array('Ose.id' => 'asc')
);

Acima tem o alias Ose e o alias User, não faço o relacionamento deles por aqui, pois já foi feito na Model.
Após eu seto os valores de paginação.
// Aqui é definido quais status serão exibidos
$i = [1, 2, 3];
$this->set(
    'ose', $this->paginate(
        'Ose', array(
            'Ose.ativo' => 't%',
            'Ose.status_id_destino' => $i
        )
    )
);

Então na View fazemos o seguinte:
View
 <?php
      echo $this->Search->create();
      echo $this->Search->input(
                      'filter1', array(
                            'id' => 'filter1',
                            'type' => 'hidden'
                       ));
      echo $this->Search->input(
                      'filter2', array(
                            'id' => 'filter2',
                            'type' => 'hidden'
                       ));
      echo $this->Search->input(
                      'filter3', array(
                            'id' => 'filter3',
                            'type' => 'hidden'
                       ));
 ?>

E finalizamos com o Snippet abaixo onde ao clicar na Checkbox desejada o valor é adicionado no campo de texto exemplificado no Snippet, mas na verdade será incluído no campo input acima, conforme é feito no CAKEPHP.

function filtro1(value) {
  var filter = document.getElementById('filter1');
  if (document.getElementById('1').checked) {
    filter.value = value;
  }
}

function filtro2(value) {
  var filter = document.getElementById('filter2');
  if (document.getElementById('2').checked) {
    filter.value = value;
  }
}

function filtro3(value) {
  var filter = document.getElementById('filter3');
  if (document.getElementById('3').checked) {
    filter.value = value;
  }
}

<input type="text" name="filter1" id="filter1">
<input type="text" name="filter2" id="filter2">
<input type="text" name="filter3" id="filter3">

    Aguardando embarque
    Embarcado
    Recebido!

      <input type="checkbox" name="filter1" onclick="filtro1(value)" id="1" value="Aguardando embarque">

      <input type="checkbox" name="filter2" onclick="filtro2(value)" id="2" value="Embarcado">

      <input type="checkbox" name="filter3" onclick="filtro3(value)" id="3" value="Recebido">

<input type="submit" value="Filtrar" />

Filtrar ao selecionar uma checkbox


Functions with the property $\frac{d}{dx}(f(x)\cdot f(x))=f(2x)$

Question: I've noticed the derivative of $\sin^2 x$, $$\frac{d}{dx}\sin^2(x)=\sin 2x$$ and the same applies to $\sinh^2 x$, that is
$$\frac{d}{dx}\sinh^2(x)=\sinh(2x)$$
I was wondering about the other functions of that property. (I posted a similar question about a week ago but I had an incorrect premise.)
So these functions must satisfy $$(f^2(x))'=f(2x)\rightarrow 2f'(x)f(x)=f(2x)$$ The only way I could think of solving these was the power series method which is something I've never been good with. $$f(x)=\sum_{n=0}^{\infty} C_nx^n,$$ $$f'(x)=\sum_{n=0}^{\infty}(n+1)C_{n+1}x^n$$ plugging this
$$2\sum_{n=0}^{\infty}(n+1)C_nC_{n+1}x^{2n}=\sum_{n=0}^{\infty}C_n(2x)^n.$$ and now I don't know what to do with that $x^{2n}$ term. Could someone help me find the general form of $f(x)$?
Comment: Actually, you should just check your trig identities and the Chebyshev polynomials.
Comment: I think your multiplication in the last equation is not $f \cdot f'$, this is a cauchy product!
Answer: There seem to be 3 families of solutions:
$$
\left(
\begin{array}{cccc}
Coeff & Solution\,1 & Solution\,2 & Solution\,3\\
 a_0 & 0 & 0 & \frac{1}{8 a_2} \\
 a_1 & 1 & 0 & \frac{1}{2} \\
 a_2 & 0 & 0 & a_2 \\
 a_3 & a_3 & 0 & \frac{4 a_2^2}{3} \\
 a_4 & 0 & 0 & \frac{4 a_2^3}{3} \\
 a_5 & \frac{3 a_3^2}{10} & 0 & \frac{16 a_2^4}{15} \\
 a_6 & 0 & 0 & \frac{32 a_2^5}{45} \\
 a_7 & \frac{3 a_3^3}{70} & 0 & \frac{128 a_2^6}{315} \\
 a_8 & 0 & 0 & \frac{64 a_2^7}{315} \\
 a_9 & \frac{a_3^4}{280} & 0 & \frac{256 a_2^8}{2835} \\
 a_{10} & 0 & 0 & \frac{512 a_2^9}{14175} \\
 a_{11} & \frac{3 a_3^5}{15400} & 0 & \frac{2048
   a_2^{10}}{155925} \\
 a_{12} & 0 & 0 & \frac{2048 a_2^{11}}{467775} \\
 a_{13} & \frac{3 a_3^6}{400400} & 0 & \frac{8192
   a_2^{12}}{6081075} \\
 a_{14} & 0 & 0 & \frac{16384 a_2^{13}}{42567525} \\
\end{array}
\right)
$$
Solution 2 is clearly the constant $0$ function, Solution 1 seems to be:
$$
f(x)=\sum_{n=0}^\infty\frac{2^{\frac{n}{2}-2} 3^{\frac{n}{2}-1} \left((-1)^n+1\right)
   a_3^{\frac{n}{2}-1}}{\Gamma (n)}x^n
$$
Solution 3 seems to be of the type:
$$
f(x)=\sum_{n=0}^\infty\frac{2^{2 n-5} a_2^{n-2}}{\Gamma (n)}x^n
$$
This is far from a proof, but I don't think there are other families.
Comment: if $f(x)$ is a solution to $2f(x)f'(x) = f(2x), $ then so is $\frac 1a f(ax)$ for any $a.$ so it makes sense to have an arbitrary constant in the solution, in yours that is $a_3.$
Comment: I suspect the limits in your summations are wrong, since $\Gamma(0)$ isn't defined


WPF click on label change checkbox isChecked property

Question: I'm new to WPF and try (in my opinion) an easy task but I didn't get it. Even Google won't help me, or I asked the wrong question.
I have a checkbox and a label; I wish that a click on the label change the isChecked property of the checkbox.
I want to do this completely in XAML with no code behind, because I wish to keep the code behind file clean of unnecessary code. Please don't discuss on this point. I know it's a single line of code doing this in code behind!
Working with event setter on the label doesn't solve the problem because you can only set the handler (which is in code behind of course). Using a storyboard doesn't help because there is no way to check the actual value of the property.
Does anyone have a good hint? Maybe I overlooked something. Please provide some code snippet for the solution.
Comment: This is a dupe - the accepted answer even just cites another question.
Answer: You can also do this:
<CheckBox>

</CheckBox>

One limitation though is that the text will have to be on the right side of the checkbox.
Comment: @Muhannad I know this is late, but you can fix that by adding `VerticalContentAlignment="Center"` on the `CheckBox`. Note that this is distinct from `VerticalAlignment` which affects the `CheckBox` itself.
Comment: Wow, thanks, I always thought there must be a more simple solution and here it is!
Comment: I love this. However, the alignment becomes a little bit off between the label and the checkbox.
Answer: Paste this code into kaxaml
You'll see that clicking on the label toggles the checkbox.
[See this SO answer by Kent]
<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <StackPanel>
    <CheckBox IsChecked="{Binding IsChecked, ElementName=checkbox}" Content="Hello">
        <CheckBox.Template>
            <ControlTemplate TargetType="CheckBox">
                <ContentPresenter/>
            </ControlTemplate>
        </CheckBox.Template>
    </CheckBox>
    <CheckBox x:Name="checkbox" Content="A normal checkbox"/>
</StackPanel>
</Page>

Comment: I found that in a WinRT XAML app on Windows Phone, I didn't need to use the template - the default template worked fine (the key was the `Content` property).
Comment: I realy overlooked it... thanks!


PHP script for sending mail won't work when executed via browser but work fine when executed from command line

Question: I've written a little PHP script:
<code><?php
$phpPath = shell_exec("which php");

print "$phpPath\n";

$uid =  posix_getuid();
$userinfo = posix_getpwuid($uid);
print_r($userinfo );
print "\n";

    $to = "my_user_name@my_company_mail.com";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "email@example.com";
    $headers = "From:" . $from;

    $res = mail($to,$subject,$message,$headers);

    print_r(error_get_last());
    if($res){
    echo "Mail Sent.\n";
    }else{
    echo "Mail was'nt Sent\n";

    }
?>
</code>
The thing that drives me crazy is that when I execute this script from command line it work fine:
<code>/usr/bin/php

Array
(
    [name] => daemon
    [passwd] => x
    [uid] => 1
    [gid] => 1
    [gecos] => daemon
    [dir] => /usr/sbin
    [shell] => /bin/sh
)

Mail Sent.
</code>
but when I execute it from a remote browser this what I get:
<code>/usr/bin/php

Array
(
    [name] => daemon
    [passwd] => x
    [uid] => 1
    [gid] => 1
    [gecos] => daemon
    [dir] => /usr/sbin
    [shell] => /bin/sh
)

Mail was'nt Sent
</code>
any idea?
Answer: Command Line PHP and PHP doesn't use the same php.ini, please check if you have difference between them.
More information on php.ini here
Related question on SO here
Comment: I've copied the the cli php.ini to lampp directory, nothing changed, all the mail configuration were the same anyway...


MySQL from decimal(13.6) to currency

Question: I'm trying to get from an decimal(13.6) value to currency in EURO's
I'm getting this as result right now:
╔══════════════╦═════════╗
║   total      ║ Date    ║
╠══════════════╬═════════╣
║8887616.500000║ 2017    ║
╚══════════════╩═════════╝

What I want is something like this one:
╔══════════════╦═════════╗
║   total      ║ Date    ║
╠══════════════╬═════════╣
║€8,887.616.50 ║ 2017    ║
╚══════════════╩═════════╝

Or this one:
╔══════════════╦═════════╗
║   total      ║ Date    ║
╠══════════════╬═════════╣
║   €M8,9      ║ 2017    ║
╚══════════════╩═════════╝

I did try to convert from decimal but had no luck with that
SELECT  SUM(totalExcl) AS total, DATE_FORMAT(date_add, '%Y') AS 'Date'
FROM ex.ps_oxo_quotation
WHERE saleType IN ('IEW' , 'As', 'Pr')
AND date_add >= '2017-01-01 00:00:00'
GROUP BY 'Date'
ORDER BY 'Date' DESC

Comment: Which locale uses BOTH ',' AND '.' as thousands separators?
Comment: You can test with `SELECT FORMAT(8887616.500000, 2, 'locale');` and you own locale read about MySQL's function FORMAT here https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_format... Don't know of the FORMAT function will support your wierd locale that uses BOTH ',' AND '.' as separators.
Comment: FORMAT(8890905.860000, 2, 'de_DE'), this one changed to '8.890.905,86'
Answer: This will give you a sum formatted in Euro:
SELECT CONCAT('€', FORMAT(SUM(totalExcl), 2, 'de_DE')) AS total

Will show: €8.890.905,86
The other requested alternative:
SELECT CONCAT('€M', FORMAT((SUM(totalExcl)/1000000), 1, 'de_DE')) AS total

Will show: €M8,9
Note that this example will show the sum according to standards (LOCALE de_DE), and not with the exact format you have requested, that have mixed dots "." and commas "," in a non standard way. This could easily be fixed with some string manipulation if you really must format the sum that way.

MySQL from decimal(13.6) to currency


Utilizar elvis operator em conjunto com ngIf

Question: Olá, tenho o seguinte elemento:
Produto.descricao_b2w.descricao
As vezes, esse descricao não existe nesse produto, então quando o eu tento aplicar o ngModel e *ngIf nele eu recebo:

Cannot read property 'descricao' of null

Esse é meu template:
<textarea *ngIf="produto.descricao_b2w.descricao !== null" rows="4" [(ngModel)]="produto.descricao_b2w.descricao" readonly type="text" name="descricaob2w" id="descricaob2w{{i}}" class="form-control">

Tentei o elvis de algumas formas diferentes, mas nenhuma conseguiu atingir meu objetivo, o ngModel não consegue encontrar a descrição porque ela realmente não existe no objeto, só existe as vezes.
Answer: O objeto anterior pode estar nulo, tente desta maneira.
<textarea *ngIf="produto.descricao_b2w !== null" rows="4" [(ngModel)]="produto.descricao_b2w.descricao" readonly type="text" name="descricaob2w" id="descricaob2w{{i}}" class="form-control">


How do I find the equation of the tangent line to the curve?

Question: We have a curve described by the system of equations:
$$\begin{cases}
    x^2z+2xy=-8\\
   y^2z^2+xy=-4
  \end{cases}$$
We are asked to find a parameterization of the tangent line to the curve at the point $(-2,2,0)$
I've solved similar problems before but I've never seen the curve defined with a system of equations. I need help figuring out how to approach the problem!
My attempt:
$$\text{Let }
  \begin{cases}
   f(x,y,z) = x^2z+2xy+8 = 0 \\
   g(x,y,z) = y^2z^2+xy=-4
  \end{cases}$$
The common normal vector to $\nabla f \;\text{ and }\; \nabla g$ is tangent to the original curve, i.e their cross product.
$$\begin{cases}
   \nabla{f} = (2xz+2y,2x,x^2) \\
   \nabla{g} = (y,2yz^2+x,2zy^2)
  \end{cases}$$
$$\nabla{f}(-2,2,0) = (4,-4,4) \\
  \nabla{g}(-2,2,0) = (2,-2,0)
  $$
$$\nabla{f}\times\nabla{g} = (8,8,0) || (1,1,0)$$
Ultimately, the equation of the tangent is
$$\begin{cases}
   x = -2 +t \\
   y = 2 + t \\
   z = 0
  \end{cases}$$
Answer: Hint: Let $(u,v,w)$ be a directing vector of the tangent.
Expand
$$\begin{cases}
    (x+\lambda u)^2(z+\lambda w)+2(x+\lambda u)(y+\lambda v)&=&-8\\
   (y+\lambda v)^2(z+\lambda w)^2+(x+\lambda u)(y+\lambda v)&=&-4
  \end{cases}$$
You will obtain 2 polynomials equations in variable $\lambda$.
Annihilate the first order terms in $\lambda$ (of course replacing $(x,y,z)$ by $(-2,2,0)$).
This will give a system of 2 equations in unknowns $u,v,w$ :
$$\begin{cases}
    4u-4v+4w&=&0\\
    2u-2v+0w&=&0
\end{cases}$$
which is enough for determining a direction.
Do you see why ? Intuitively, this annihilation is  the way to express that for an infinitesimal "step" in the direction of vector $(u,v,w)$, one remains on each surface, therefore on their intersection curve.
Remark: We assume that the way the surfaces are meeting at the considered point is not "pathological"...
Comment: I mean that for example, the first equation will give rise to $A+B \lambda+C\lambda^2+D \lambda^3=...$, where $A,B,C,D$ are expressions of $x,y,z,u,v,w$ (in fact of $u,v,w$ only). Then the idea is to force $B=0$.
Comment: A more rigorous method is to work with tangent planes as described [here](https://math.stackexchange.com/q/2605535) on a similar example.
Comment: i.e., obtain the gradient of the first equation (which is the normal to the tangent plane) ; do the same for the second equation ; take the cross product of these two gradients.
Comment: what do you mean by annihilating the first-order terms?
Comment: I appreciate the response but I'm not convinced, could you explain further?
Comment: We are here at the intuitive roots of the infinitesimal calculus (as "grasped" by Leibniz for example). I don't know the degree of rigor asked by your instructor...
Comment: Thank you this was helpful, I'll upload my attempt!


Tomcat memory and virtual hosts

Question: I have a VPS on which I serve Tomcat 6.0.
500mb memory was enough, when I had only two applications.
Last week I deployed another web application and formed a new virtual host editing Tomcat server.xml.
But the server responses slow down, linux started to eat the swap.
When I increased the memory 750 mb it become stable again.
But memory is not so cheap so I won't be happy to pay 250 mb RAM for each additional application.
Is "250 mb additional memory need" for each web app normal?
Is there any solution to decrease this cost?
For example, does "to put common libraries of these applications to shared folder of Tomcat" have positive impact on Tomcat memory and performance?
Note: Deployed applications are web applications that use Spring, hibernate, sitemesh and related libraries, war file size totals up to 30 mb.
Thanks.
Answer: It's unlikely that this memory is being consumed by the Spring / Hibernate / etc. classes themselves. So the size of their .jar files isn't going to matter much. Putting these libraries in Tomcat's shared library directory would help save a bit of memory in that one copy of these classes would be loaded only, but that won't save much.
Isn't it simply more likely that your applications are just using this much memory for data and so forth? You need to use a profiler to figure out what is consuming the heap memory first. Until you know the problem, it's not much use in pursuing particular solutions.
Comment: Yes maybe there is problem in my applications. Indeed my applications are Grails web application, I use basic Grails controllers, services etc. I will search about memory need of a typical Grails application. Maybe there is excessive use of hibernate caching
Comment: As of Grails 1.37 >= 512mb per app is suggested for optimal performance. 256mb is probably cutting it a bit too thin.  Grails is a powerful solution, but it comes at a cost, literally. As you say, memory is not cheap...
Answer: I think you need to measure the memory consumption of the application.
You can use JProfiler or Java6 build in profiling tools such as VisualVM and JHat (best way to start).
Check this link for more info:
http://java.sun.com/developer/technicalArticles/J2SE/monitoring/

Tomcat memory and virtual hosts


Consulta ao Firebase realtime database não retorna os valores alterados no banco

Question: Tenho uma consulta no Firebase que deve retornar os dados do usuário para verificar se este ainda tem acesso e o seu nível de acesso ao sistema, no entanto ao modificar os valores a consulta continua trazendo os valores anteriores.
private void buscarUser(String matricula){
    ValueEventListener buscaUserListener = new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if(!dataSnapshot.exists()){
                Toast.makeText(BuscaUserPage.this,
                        "Usuário não encontrado.", Toast.LENGTH_LONG).show();
            }else {
                try {
                    Usuario userRecebido = null;
                    for (DataSnapshot dados : dataSnapshot.getChildren()) {
                        userRecebido = dados.getValue(Usuario.class);
                        idUser = dados.getKey();
                    }
                    atualizarTela(userRecebido);
                }catch (Exception e){
                    Toast.makeText(BuscaUserPage.this,
                            e.getMessage(), Toast.LENGTH_LONG).show();
                }

            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {
            Toast.makeText(BuscaUserPage.this,
                    "Ocorreu um erro: " + Objects.requireNonNull(databaseError),
                    Toast.LENGTH_LONG).show();
        }
    };

    Query consulta = referenciaFirebase.child("Usuarios").orderByChild("matricula").equalTo(matricula);
    consulta.addListenerForSingleValueEvent(buscaUserListener);
}

Classe Usuario:
public class Usuario implements Serializable {

private String id;
private String email;
private String senha;
private String matricula;

private int nivelAcesso;
private boolean ativo;
}

Os valores de nivelAcesso e ativo que são alterados.
Comment: Você activou a Offline Persistence do Firebase?
Comment: A persistência offline está ativa.
Comment: É por isso que você está tendo esse problema. Pode ser que esteja levando muito tempo para carregar os novos valores, ou esteja havendo algum problema com a sua conexão. Esse problema é meio comum quando usamos a persistência offline.
Answer: O problema realmente estava ligado a Offline Persistence do Firebase. Estava utilizando este código para ativar a persistência:
public class CustomApplication extends Application {
@Override
public void onCreate() {
    super.onCreate();
    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}}

Então substitui essa classe por um singleton que utilizo em apenas algumas activities em que é interessante manter a persistência off line.
public static DatabaseReference getReferenciaFirebaseOffLine(){
    if(referenciaFirebase == null){
        bancoFirebase = FirebaseDatabase.getInstance();
        bancoFirebase.setPersistenceEnabled(true);
        referenciaFirebase = bancoFirebase.getReference();
    }
    return referenciaFirebase;
}


Why do CNNs conclude with FC layers?

Question: From my understanding, CNNs consist of two parts. The first part (conv/pool layers) which does the feature extraction and the second part (fc layers) which does the classification from the features.
Since fully-connected neural nets aren't the best classifiers (i.e. they get outperformed by SVMs and RFs most of the time), why do CNNs conclude with FC layers, rather than let's say an SVM or a RF?
Answer: It's not so simple. First of all, a SVM is, in a way, a type of neural network (you can learn a SVM solution through backpropagation). See What *is* an Artificial Neural Network?. Second, you can't know beforehand which model will work better, but the thing is with a fully neuromorphic architecture you can learn the weights end-to-end, while attaching a SVM or RF to the last hidden layer activation of a CNN is simply an ad hoc procedure. It may perform better, and it may not, we can't know without testing.
The important part is that a fully convolutional architecture is capable of representation learning, which is useful for a myriad of reasons. For once, it may reduce or eliminate feature engineering altogether in your problem.
About the FC layers, they are mathematically equivalent to 1x1 Convolutional layers. See Yann Lecun's post, which I transcript below:

In Convolutional Nets, there is no such thing as "fully-connected
  layers". There are only convolution layers with 1x1 convolution
  kernels and a full connection table.
It's a too-rarely-understood fact that ConvNets don't need to have a
  fixed-size input. You can train them on inputs that happen to produce
  a single output vector (with no spatial extent), and then apply them
  to larger images. Instead of a single output vector, you then get a
  spatial map of output vectors. Each vector sees input windows at
  different locations on the input.
In that scenario, the "fully connected layers" really act as 1x1
  convolutions.
Answer: If you knew the No-Free Lunch Theorem (Wolpert & Macready), you would not get so hung up on one classifier and ask why it's not the best.  The NFL Theorem states essentially that "in the universe of all cost functions, there is no one best classifier."  Second, classifier performance always "depends on the data."
The Ugly Duckling Theorem (Watanabe) states essentially that "in the universe of all sets of features, there is no one best set of features."
Cover's Theorem states that if $p>n$, i.e., the dimensionality of the data is larger than the sample size, then a binary classification problem is always linearly separable.
In light of the above, as well as Occam's Razor, there is never anything that's better than anything else, independent of the data and cost function.
I have always argued that CNNs by themselves are not ensembles of classifiers for which diversity (kappa vs error) can be assessed.

Why do CNNs conclude with FC layers?


Problema com get data no angular js

Question: Boa noite,
Estou a tentar buscar dados do php através do Angular.js mas não está a funcionar. Quando vou clicar na categoria não abre a próxima página onde serão mostrados os dados.
PHP
<?php
    header('Content-Type: application/json');

    require_once("../funcoes/funcoes.php");

    $result = $conexao->prepare("SELECT * FROM colecoes WHERE menu = :menu AND activo = :activo ORDER BY pos ASC");
    $result->bindValue(':menu', 'Comer', PDO::PARAM_STR);
    $result->bindValue(':activo', 1, PDO::PARAM_INT);
    $result->execute();
    $rows = $result->fetchAll(PDO::FETCH_ASSOC);

    foreach ($rows as $row) {

        $result_anex = $conexao->prepare("SELECT * FROM colecoes_anexos WHERE id_mae = :row_id AND seccao = :seccao");
        $result_anex->bindParam(':row_id', $row['id'], PDO::PARAM_INT);
        $result_anex->bindValue(':seccao', 'thumbnail', PDO::PARAM_STR);
        $result_anex->execute();
        $row_anex = $result_anex->fetch(PDO::FETCH_ASSOC);

        echo json_encode($row);

    }
?>

Controlller
angular.module('starter.controllers', [])

.controller('comer_categorias', function($scope, $http) {
    $http.get("https://www.sabeonde.pt/api/api_categorias_comer.php").success(function (data) {
        $scope.comer = data;
    });
});

HTML
<ion-content ng-controller="comer_categorias">

{{comer_cat.id}}

</ion-content>

Comment: Provavelmente sua requisição está sendo negada porque é para outro domínio. Ver http://pt.stackoverflow.com/questions/12363/como-efetuar-requisi%C3%A7%C3%B5es-ajax-com-jquery-em-dom%C3%ADnios-diferentes e http://pt.stackoverflow.com/questions/3183/requisição-ajax-cross-domain-com-javascript-puro-sem-apis
Answer: Qual é o erro?
tente fazer assim
$scope.comer = {};

$scope.GetData = function () {
$http.get("https://www.sabeonde.pt/api/api_categorias_comer.php").success(function (data) {

    $scope.comer = data;

}).error(function(data){
console.log(data);
})

}

Problema com get data no angular js


AWS EFS - file delete and recreate not detected programmatically for 25 to 30 seconds

Question: I am observing a very large delay in EFS detecting that a file has been re-created i.e. deleted and then created again.
In this simple test example, I have a single file that gets deleted and recreated around 5 seconds later. I have two EC2 instances mounted to the same EFS:
EC2-1: responsible for reading the file
EC2-2: responsible for deleting and creating the file.
The problem I am seeing is that when EC2-2 deletes the file, EC2-1 correctly updates to say it is no longer present. EC2-2 then recreates the file around 5 seconds later. EC2-1 does not detect the file has returned for another 25 to 30 seconds.
Now, if I run some sort of query on the file system on EC2-1 just after recreation (like and LS command), it DOES then immediately update to say the file is created.
To be clear, I visually see the file get created on EC2-1 FS immediately after creation, just by running an LS. Its reading it programmatically that fails. In my test case I have a Node.js script that literally just calls readFileSync() every second. I have also tested with the same in Python to conclude this is an EFS issue.
If I run the same script on EC2-2, is see expected results i.e. the file is missing for a second and then is available immediately once recreated. So, reading this on the instance that does the delete and create, works as expected.
Its as if EFS is not detecting the file delete/recreation at all.
OS is Ubuntu Server 18.04 on both EC2 VM's. Tested on new EFS of type "General Purpose" and "High I/O".
Comment: Sounds like nfs caching effects. Try to mount with *noac* or lower directly cache lifetime.
Comment: Solved! Thanks @kofemann - I had no idea the attribute cache existed. Really helpful pointer, thanks you!
Answer: Thanks to @kofemann who pointed me to the noac option I was able to learn about the file system attribute cache and locate the post below that sums up the options nicely.
https://forums.aws.amazon.com/thread.jspa?threadID=245354


Sound spectrum to notes software

Question: I'm looking for software that can graphically assist in translating a sound frequency to notes.
Closest example of what I had in mind is FL Studio's Wave Candy plugin:

Hovering cursor above a certain position displays the closest note to that frequency.
Ideally, it would be something like Synthesia, but I guess there really isn't a piece of software out there that can perfectly separate desired notes from noises and lyrics.

What software like that is there that helps figure out which notes are being played at a certain moment from a sound file?

I realize this might not be the best SE site for this kind of questions, but I figured here would be a better chance to get an answer from a professional, rather than just asking on general sites, like SuperUser
Comment: If code for pitch detection would be helpful try some of the answers to these stackoverflow questions: [Graphing the pitch of a sound](http://stackoverflow.com/q/4708613/575530), [Sound frequency detection](http://stackoverflow.com/q/5231294/575530), [Real time pitch detection](http://stackoverflow.com/q/1354084/575530), and [Pitch detection using FFT for trumpet](http://stackoverflow.com/q/2244973/575530).
Comment: Regarding your comment about "the best SE site for this kind  of questions", you might want to consider http://avp.stackexchange.com/
Comment: @Gauthier avp's faq list of relevant topics doesn't include something this question is about. This site still seems a better alternative to avp.
Comment: When you say "software" do you want an application or some software code?
Comment: @dumbledad why, do you have some useful and easy to use code from which an application could be made?
Comment: Not quite. I do recall a trick for getting the frequency of a sound by offsetting until the graphs match ('twas a colleagues hobby code - so I'd have to check that). If that proved reliable one could present frequency and closest note, like tuning apps do.
Comment: Should this question be CW?
Comment: @Luke I don't know, do you?
Answer: Capo for Mac OS X
There is also a more limited version for iOS.
Comment: I use Capo for all kinds of music, not just guitar music. I  don't think its capabilities are particular to guitar. The developer just chooses to market it as a guitar tool because there are so many guitarists out there who want to transcribe guitar solos. And you don't need an expensive computer to use it, although you do need a Macintosh.
Comment: The guitar playing specifics are accidental. The developer is an avid guitar player, and wrote to/uses for/markets the tool to guitar players. Don't let that fool you - it's capabilities are not specific to guitars
Comment: This seems to be targeted at guitar fans, as well as expensive hardware owners ;) I'm looking for a tool that would help decompose all sorts of instruments into notes, rather than just guitar chords.
Answer: Music Spectrograph
There's an iOS (iPhone/iPad) app, and an OSX/macOS app, Music Spectrograph, designed for just this purpose (Disclaimer.  It's my app in the iTunes App Store.)  The Y axis is scaled to a midi keyboard.  Works both with live audio and with sound files.  "Assist" is the right word, as a spectrograph can display a lot and lots of overtones, leaving a human with musical training to visually pick out any relevant musical pitches from among all the overtones.
If it's really just for 1 pitch frequency, with no accompaniment, harmony or background sound, another iOS app of mine (Sing-inTuna) attempts to place the note pitch directly on a musical staff.  (Repeat disclaimer.).
Separating notes pitches (especially within common chords) from overtones, noise, vocals and percussion, reliably, currently appears to be a very difficult software digital signal processing problem.  Research papers on the topic can be found at www.music-ir.org/mirex/
Comment: This looks useful. Hope it keeps the screen orientation when rotated so that the keyboard is on bottom of the screen. A screenshot with greater resolution than on the store page included in your answer would also be great.
Answer: Melodyne
The Celemony Melodyne family of products can achieve this, among other functions. The products are expensive but they are the state of the art.
From the website:

What Melodyne is
Melodyne is a program for your Mac or PC that offers truly
  extraordinary possibilities for the editing of audio. For Melodyne
  recognizes the notes that are sung or played in your recording and
  shows them to you. It's almost like the recording turns into sheet
  music again.
Answer: Sonic Visualizer
http://sonicvisualiser.org/ is free and can do regular spectrograms with a piano scale along the left side, automatic note transcriptions (and play them back), chromagrams, etc.
Answer: HarmonEye
It can show you the pitches that are played in real-time (without regard to the octaves and no matter which instruments play it). There's no time axis but you can pause it and read out the tones or chords. It is not restricted to files loaded from disk. In fact it can listen on a system input (either the microphone or routed system output) so that you can use any music player or play yourself. It can filter out the harmonics and show only base notes.
I've successfully used it to find out chords and melody from several song with quite difficult chords and modulations.
Besides transcribing it help finding the key and locating modulations. The pitches can be accumulated and averaged over a time interval so that you can guess the key by the tones present in the song fragment.
Answer: There are a lot of software designers trying to do this.  I know it's a hot commodity.  However, programming a computer to think like a musician; isolate fundamental frequencies, determine key and pitch, and notate, is quite an ordeal that isn't done well in any self-transcribing software I've seen.
Your best bet is to hire a transcriber.  :)

It will more than likely be cheaper than buying the best software out there on unfathomable hardware.
It will be notated in the right key choice
Depending on the complexity of the tune, and the experience of the transcriber, can be handed back over within hours, or worst a day or two.
Automatically parsed out to correct notation, not requiring more software (Like Finale, which is $600) to be purchased for correct transcription, notation, and engraving

Upon further review, if you're just looking for assistance and not entire automation, most transcription software out there (Capo, Transcribe!, etc.) allows you to view a graphic of suggested frequencies.  A strong background in music overtones and good judgement will let you easily strip the notes from the noise and background and get to what you need.

Sound spectrum to notes software


Conditional distribution (on N) of arrival times in a nonhomogenous poisson process

Question: Conditional on $N(t)$, given some $\lambda(t)$ characterizing some Nonhomogenous poisson point process, the distribution of an arrival time $t_i$ is $\lambda(t_i)/\int_{A}\lambda\left(t\right)dt$  where A is the space over which the point process is defined.
Can anyone explain the derivation here?
Thank you
Comment: what's that $\beta$? And what do you mean by distribution?
Comment: I removed beta, it's unnecessary.  Re distribution:   In a regular (homogenous poisson process), conditional on the number of arrivals $N(t)$ , the distribution of the arrival times themselves are uniformly distruted over $[0,t]$.   In a nonhomogenous poisson process, they are distributed as above.  Why?
Comment: Do you want a heuristic / intuitive or mathematical explanation?
Comment: Both would be ideal.  I have vague intuition already
Comment: I don't think your statement is entirely correct.  The $i$th arrival time $t_i$ does not have pdf $\lambda(t)/\int_A\lambda(u)du$ but is instead distributed as the $i$th order statistic of $n$ iid random variables, each having this density.
Answer: Here's the situation for the first arrival time. Let $T_1$ be the first arrival time. Sorry for making this capitalized...I like random variables to be capital letters. Pick any $t_1 < t$, where $t$ is the end time.
Also let $\Lambda(t') = \int_0^{t'}\lambda(s) ds$, $p = \Lambda(t_1) / \Lambda(t)$, and $r = s-1$.
\begin{align*}
P(T_1 \le t_1 | N(t) = n) &= \sum_{s=1}^n\frac{P(N(t_1) = s, N(t) =n)}{P(N(t) = n)}\\
 &= \sum_{s=1}^n\frac{P(N(t_1) = s)P( N(t)-N(t_1) =n - s)}{P(N(t) = n)}\\
&= \sum_{s=1}^n \frac{e^{-\Lambda(t_1)}\Lambda(t_1)^s e^{-[\Lambda(t)-\Lambda(t_1)] } [\Lambda(t)-\Lambda(t_1)]^{n-s} n! }{s!(n-s)! e^{-\Lambda(t)}\Lambda(t)^n  } \\
&= \sum_{s=1}^n {n \choose s} \frac{\Lambda(t_1)^s  [\Lambda(t)-\Lambda(t_1)]^{n-s}  }{ \Lambda(t)^n  }\\
&= \sum_{s=1}^n {n \choose s} p^s (1-p)^{n-s} \\
&= \frac{np}{(r+1)} \sum_{r=0}^{n-1} {n-1 \choose r} p^r (1-p)^{n-1-r} \\
&= \frac{np}{(r+1)}
\end{align*}
You're looking for $f_{T_1|N(t)=n}(t_1)$, and that's $\frac{d}{dt_1}\frac{np}{(r+1))}.$  When I take the derivative I get
$$\frac{n}{r+1}\frac{\lambda(t_1)}{\Lambda(t)}$$
which is sort of like your answer. In the special case that $n=1$, then $s$ would have to be $1$, and thus $r$ would be $0$. In that case we would get the answer you mentioned in the question.
As far as intuition goes, there's higher density in places where the rate function $\lambda$ is higher. And the denominator is just a normalizing constant.