ActiveMQ Configuration with KahaDB

Question: We are using ActiveMQ 5.6.0 with KahaDB. It has produced quite some log files, which is to be expected with our setup (DLQ and stuff), looking like this:
<code>$ ll -h /opt/activemq/data/kahadb/
total 969M
drwxr-xr-x 2 root     root     4.0K Nov  3 12:47 ./
drwxr-xr-x 3 activemq activemq 4.0K Sep 24 12:12 ../
-rw-r--r-- 1 root     root      39M Oct 16 07:57 db-202.log
-rw-r--r-- 1 root     root      38M Oct 16 07:57 db-203.log
-rw-r--r-- 1 root     root      33M Oct 17 08:12 db-238.log
...
</code>
No more messages were processed, when we ran into the 1GB temp usage limit. Or that's what we are assuming, is that correct?
The configuration looks like this:
<code><systemUsage>
    <systemUsage>
        <memoryUsage>
            <memoryUsage limit="512mb"/>
        </memoryUsage>
        <storeUsage>
            <storeUsage limit="3 gb"/>
        </storeUsage>
        <tempUsage>
            <tempUsage limit="1 gb"/>
        </tempUsage>
    </systemUsage>
</systemUsage>
</code>
After cleaning up the log files and being way below the limits, still no messages were consumed by AMQ. Only when we manually purged a route, messages were starting to be delivered again.
So we need to ensure, that the KahaDB log size always stays below the temp usage, right? And that delivery was not picked up after fixing that is a bug or are there any other steps to be taken?
Answer: Yes, you should look for the storeUsage limit.
If you have undelivered messages in queues logs can't be removed.
The solutions are:

raise the storeUsage limit;
watch for your queues and purge messages from them;
setup message expiration (http://activemq.apache.org/manage-durable-subscribers.html).

ActiveMQ Configuration with KahaDB


Managing parameter dependencies in Python 3 classes using constructors

Question: I'm setting up some hydraulic calculation scripts and plan on using them a lot in the future.  In short, I would like to have class methods that update the object in full when updating a single parameter.  Is my first pass method even viable, and what is the most pythonic way to rebuild an object based on a new parameter?
class Conduit(object):
    """
    Defines a Conduit through a set of knowns. All internals are kept
    in metric.
    """

    def __init__(self, b=0, n=0, S=0, y=0, Q=0, V=0):
        self.b = float(b)
        self.n = float(n)
        self.S = float(S)
        self.y = float(y)
        self.Q = float(Q)
        self.V = float(V)
        self.A = self._A()
        self.V = self._V()
        self.Q = self._Q()

    def set_width(self, b):
        self.__init__(b=b, y=self.y, n=self.n, S=self.S, Q=self.Q, V=self.V)

    def set_depth(self, y):
        self.__init__(b=self.b, y=y, n=self.n, S=self.S, Q=self.Q, V=self.V)

    def set_flow_rate(self, Q):
        self.__init__(b=self.b, y=self.y, n=self.n, S=self.S, Q=Q, V=self.V)

    def set_slope(self, S):
        self.__init__(b=self.b, y=self.y, n=self.n, S=S, Q=self.Q, V=self.V)

    def set_n(self, n):
        self.__init__(b=self.b, y=self.y, n=n, S=self.S, Q=self.Q, V=self.V)

    def _A(self):
        if self.b and self.y:
            return self.b * self.y
        elif self.Q and self.V:
            return self.Q / self.V

    def _V(self):
        if self.V:
            return self.V
        elif self.Q and self.y and self.b:
            return self.Q / (self.y * self.b)

    def _Q(self):
        if self.Q:
            return self.Q
        elif self.V and self.y and self.B:
            return self.V * self.y * self.b

    def Froude(self):
        if self.V and self.y:
            return self.V / sqrt(9.814 * self.y)
        elif self.Q and self.y and self.b:
            return (self.Q / (self.y * self.B)) / sqrt(9.814 * self.y)

I'm simply calling the initialization function inside of the set_x functions to resolve dependencies.  I see no reason why this wouldn't work, but I'm not sure about the internals of using a magic method in this way.  Should I create a rebuild method for this purpose?  Or should I create a new instance of the object and pass that new object to self?  The latter two options seem viable, but inefficient compared to calling an already existing function that does what I want.
Comment: It is not pythonic to write explicit setters and you shouldn't call the `__init__()` method. You should look at [this](http://www.python-course.eu/python3_properties.php) example which explains how to use the `@property` decorator, which , I thinnk, is what you are looking for
Comment: Exactly what I was looking for and couldn't get via Google-fu.  Thanks!
Answer:
Resolved in comments:
It is not pythonic to write explicit setters and you shouldn't call the __init__() method.
You should look at this example which explains how to use the @property decorator,
  which , I thinnk, is what you are looking for – gionni
Exactly what I was looking for and couldn't get via Google-fu. Thanks!


Integrate Pyspark Structured Streaming with confluent-kafka

Question: i want to create custom data transformation on pyspark structured streaming.
I want to serialize my message into protobuf using confluent-kafka library. I need this library in order to integrate with SchemaRegistry. I saw they already has complete Class and Function to Serialize and Deserialize protobuf format.
Then, i was unable to use it even if i created spark udf like below :
def row_to_protobuf(iterator, schema_registry_url, topic):
    schema_registry_client, serializer = generate_confluent_context(schema_registry_url)
    for row in iterator:
        message = MyMessage()
        message.timestamp = int(row.timestamp)
        for key, value in row.repeated.items():
            message.repeated[str(key)] = str(value)
        value = integrate_to_confluent_proto(message, topic, serializer)
        yield value

process_to_proto_udf = f.pandas_udf(lambda x: row_to_protobuf(
        x, schema_registry_url, destination_topic), StringType())
    df = df.withColumn("value", process_to_proto_udf(f.col("value")))

but i got this error
TypeError: Return type of the user-defined function should be Pandas.Series, but is <class 'generator'>

Back then, if i saw confluent-kafka repository, they have custom producer class (https://github.com/confluentinc/confluent-kafka-python/blob/master/src/confluent_kafka/serializing_producer.py). So can we use this producer instead of pyspark default producer? I know that spark have kafka producer and we can use something like below
df.write \
  .format("kafka") \
  .option("kafka.bootstrap.servers", destination_server) \
  .option("topic", destination_topic) \
  .option("checkpointLocation", checkpoint_dir) \
  .mode("append") \
  .save()

If you have any idea or recommendation, please let me know. Thanks in advance!
Comment: Can you share your integrate function? Also, you probably should pass the topic column into UDF as well rather than use a separate variable
Answer: As explained in the Spark documentation, the value column must be binary or string schema type, however Protobuf is binary, so don't use StringType for your UDF. If you meet that requirement, the producer will work , yes. Alternatively, you could also just use the Confluent library directly and skip the overhead of the Spark JVM and cluster management.
As far as your error goes, you'll not want to use yield for a pandas UDF; it wants you to return a Series. Perhaps you wanted to use a regular pyspark UDF?
Comment: Yes, i changed the code yesterday to resolve Type and move into regular pyspark udf. The function works right now. But i have another issue on connecting the result to kafka connect. may be i will post another question on it. The issue is more on the `magic byte` that need to be generated from `SerializingProducer` class on `confluent-kafka` library.
Comment: You shouldn't be using SerializingProducer  anyway when you can import the ProtobufSerializer directly


Derivation of hypothesis testing -- intuition?

Question: Let's say I have data points $0.1$, $0.2$, $0.3$ coming from a normal distribution with mean $\mu$ and standard deviation $1$.
If I want to test the hypotheses $H_0: \mu = 0.15$ vs. $H_1: \mu > 0.15$, then the test statistic is
$$T = \frac{\hat{\mu} - \mu}{1/\sqrt{n}}
$$
where $\hat{\mu}$ is the sample mean. Under the null hypothesis,
$$T = \frac{\hat{\mu} - 1.5}{1/\sqrt{3}} \sim \mathcal{N}(0,1).
$$
With my data, I know my observed test statistic is $T = \sqrt{3}\times 0.05$.
Now my confusion here is the rationale for why we do the following:
The p-value is $p = \mathbb{P}(Z > \sqrt{3}\times 0.05)$ where $Z$ is standard normal.
Why do we look at the probability that the theoretical statistic exceeds the observed test statistic? Why not when it doesn't exceed?
A similar question with the p-value is when we do the two-sided test ($H_1: \mu \neq 0.15$). The p-value will evaluate to
$$p = 2\mathbb{P}(Z > \sqrt{3}\times 0.05)$$
but if the two-sided alternative is more likely than the one-sided alternative (It's either $>$ or $<$ opposed to $\neq$), shouldn't we intuitively be more likely to reject in the two-sided test? But our p-value seems to give the opposite result with the factor of 2, as we reject if p is small and this factor of 2 makes it harder to reject. Why is there a discrepancy in my intuition?
Answer:
as we reject if p is small

This is probably the root of your confusion. The p-value doesn't determine whether we accept or reject the null hypothesis; the p-value is a descriptor of the test itself. The p-value tells us "how good" the test is (in a certain sense of "how good"), even before the we perform the test; the result of the test will determine whether we accept or reject, but the p-value gives us information about how much we should "trust" that acceptance or rejection.
The p-value is the probability of a false negative, i.e., the probability that we will reject a true null hypothesis because the test should an abnormal result. In a two-sided test, there are twice as many ways that a true null hypothesis could show an abnormal result; as you correctly stated, this makes rejection much more likely, and since the p-value is the probability of rejection, this makes the p-value higher. Since the p-value is higher, we will less likely to "trust" the rejection -- it could more easily have been a statistical anomaly under the null hypothesis.
As for your first question, your calculations are conceptually backward. Conceptually, we first determine the p-value, and then we run the test and observe the statistic. It's true that we can do it the other way around, first observing the statistic and then determining what the lowest p-value is such that the statistic still tells us to reject, but this is conceptually much more awkward (and that's probably why you're having trouble with the intuition). In any case, the reason p-value calculation requires us to look at the probability the test statistic will exceed a certain threshold is that we are calculating the probability of rejection given a true null hypothesis, and rejection occurs upon exceeding that threshold. In the conceptually awkward post-observation calculation of lowest possible p-value, we just set the threshold to be exactly the observed value (since that is the highest possible threshold we could set at which the observation would still tell us to reject) and go through with that calculation.
Comment: Thanks for your answer.
Throughout university, I have always been taught the process: Pick a significance level $\alpha$ (0.05 in this case) -> Choose a test statistic, then calculate it's p-value -> compare the p-value with the level. If $p$ is lower than the level then we reject null, else accept the null. Is this what you mean by doing it backwards?
Comment: Your first paragraph says that $p$ doesn't determine whether we accept or reject, but I've always used it to compare with the significance level (so I have been using it to accept or reject). I thought that the significance level tells us "how good" the test is (we pick small levels).
Comment: @OneGapLater I guess I've been using "p-value" as synonymous with "significance level." If you ever hear "p-value of a test" that's how it's being used.
Comment: @OneGapLater If you're talking about p-value of a test statistic, it means "the lowest possible significance level at which we would still reject," as I mentioned in the answer. Since that's the definition, then you can compare it with your chosen significance level to accept or reject. But that's really just a conceptually less clear (in my opinion) way of checking whether your observed statistic is inside or outside the "accept" range determined by the significance level.
Comment: @OneGapLater You can think of the p-value of the observed statistic as a measurement of how anomalous the result is (under the null hypothesis). If it's too anomalous (p-value lower than $\alpha$), you'll reject the null hypothesis. You measure how anomalous it is by checking how many possible outcomes **exceed** -- i.e., are even more anomalous than -- it. And in a two-sided test, you're more likely to get anomalous results (since you can get them on either side), which makes them actually less anomalous (higher p-value).
Comment: @OneGapLater Perhaps my last comment gives a clearer perspective than my answer.


Using the Residue Theorem evaluate $\int_{C}{e^\frac{1}{z}dz}$

Question:
Evaluate $$\int_{C}{e^\frac{1}{z}dz}$$ where $C:|z|=1$ using the Residue Theorem

I found out that I don't need to use the Theorem at all.
Since $e^\frac{1}{z}$ is analytic over the entire complex region, thus also inside the unit circle which is simply connected, by the Morera Theorem I state that
$$\int_{C}{e^\frac{1}{z}dz}=0$$
Comment: I think there is a pole at $z=0$
Answer: The function $e^{\frac{1}{z}}$ is not analytic. It has an essential singularity at $0$, which makes it normally difficult to deal with. However, we know that we have a power series representation for the exponential as
$$e^z=\sum_{n=0}^\infty\frac{z^n}{n!}$$
We can then write
$$e^{\frac{1}{z}}=\sum_{n=0}^\infty\frac{1}{z^n}\frac{1}{n!}$$
The residue of this function is therefore the value we get when $n=1$, so
$$Res(e^{\frac{1}{z}})=1$$
Thus,
$$\oint_{|z|=1}e^{\frac{1}{z}}dx=2\pi i$$


windows background in Yosemite

Question: My Application work as expected in 10.6, 10.7, 10.8 and 10.9, but in 10.10 I found that the windows background color is not set as in the old OSes....leaving gray windows.
This is the code:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    self.window1.backgroundColor = [NSColor whiteColor];
    self.window2.backgroundColor = [NSColor whiteColor];
}

each help is appreciated
Comment: This was a bug that was fixed in developer preview 6, I had the same problem: http://stackoverflow.com/questions/25006794/textured-nswindow-with-setbackgroundcolor-has-a-tinged-grey-background
Comment: Problem disappeared in the latest DP (and latest xcode 6)
Comment: Maybe it helps you: http://stackoverflow.com/a/27042648/2360439
Comment: Thanks but this was simply solved by Apple in the latest DPs of Yosemite...now works great
Answer: Did you try setting it in - (void)windowDidLoad of your NSWindowController? It works for me this way under 10.10 DP 6.
Comment: Sorry, but doing as you say, I just recreated the problem I have in Yosemite, even on old OSes..
Comment: Did you try it in a vanilla Xcode project? If not, can you rule out that self.window1 and self.windo2 are nil? Did you check the window's settings in IB? Did you check the view hierarchy, i.e. did you make sure the window's `contentView` isn't a custom `NSView` that is drawing the background?
Comment: I use rotating windows in this app, so that each contents view is processed to be passed from one window view to another. So rule out simple problems.
I connected an IBAction to a button to make a test, but backgroud windows is not changed even in this way, with a clean log.
So I created a new project, but still this happens....and now this is really stupid.
I decided to upgrade to latest XCode 6 from the Developper portal, but I'll do this after I did a clean OSX 10.10 installation . I'll know soon the response
Comment: Bingo, with latest DP + latest xCode 6, now work as expected...but I could not find any explanation/bug related.

windows background in Yosemite


fullcalendar is not a function while using in Laravel

Question: I am trying to use fullcalendar in my laravel app.
Scripts in webpage source code

Code in script.js
$(function() {
    $('#calendar').fullCalendar({
      editable: true,
      eventLimit: true,
    });
});

I have #calendar div in my page and my console is showing error
Uncaught TypeError: $(...).fullCalendar is not a function
    at HTMLDocument.<anonymous> (script.js:2)
    at l (jquery.min.js:2)
    at c (jquery.min.js:2)
(anonymous) @ script.js:2
l @ jquery.min.js:2
c @ jquery.min.js:2
setTimeout (async)
w.readyException @ jquery.min.js:2
(anonymous) @ jquery.min.js:2
l @ jquery.min.js:2
c @ jquery.min.js:2
setTimeout (async)
(anonymous) @ jquery.min.js:2
u @ jquery.min.js:2
fireWith @ jquery.min.js:2
fire @ jquery.min.js:2
u @ jquery.min.js:2
fireWith @ jquery.min.js:2
c @ jquery.min.js:2
setTimeout (async)
(anonymous) @ jquery.min.js:2
u @ jquery.min.js:2
fireWith @ jquery.min.js:2
fire @ jquery.min.js:2
u @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
_ @ jquery.min.js:2

My blade file

Menu

                            Calendar

Dashboard

As @Leo suggested, I tried using https URLs for resources I am using and also used ngrok to create https in localhost, but still I got same error.
Comment: @PrafullaKumarSahu did you simply try to move the scripts in the 'head' tag?
Comment: yeee, finally :D
Comment: @Leo check I have just updated my answer.
Comment: I will try to see if I find other solutions, while I delete the answer before giving wrong information.
Comment: @Leo I don't think you need to delete your answer, may be that will be solution to some people.
Comment: does the network-tab actually show that all the js are successfully loaded ?
Comment: @birdspider I found the actual issue.
Comment: @Leo you are correct laravel  app.js is creating the problem.
Comment: @Leo yes, you are correct. what I did was copying the basic html and tried on the laravel page and got the idea. :D
Comment: @PrafullaKumarSahu Union is strength ;)
Comment: @Leo Always. :)
Answer: I found the issue is Laravels app.js, that is creating the error, I will add a proper solution to it.
If you will use npm and webpack and manage dependencies you will not get this error. With out using a dependency manager.
Another solution will be using defer,
You can use defer attribute on all other scripts and the error is gone.

-->

Comment: It's unlikely that Laravel native code has mistakes.
Comment: @GiamPy, I don't think so, it is about maintaining dependencies.


$P(C\mid B)=P(C\mid\bigcup_{i=1}^{n}(B\cap A_i))= \sum_{i=1}^{n}P(C\mid B\cap A_i) $

Question: where $A_i\cap A_j=\varnothing $ for $ i \ne j$
Is formula true?
P.S newbie in this area
Comment: You seem to have (mis) copied just a part of the intended question: The summation index should be $i$, not $n$. There must be an additional assumption about the $A_i$'s. Even then, unless $n=1$, it can happen that the right side of the proposed equation is $>1$, which would make the equation obviously false. I suggest you consider some small examples, say on probability spaces of two or three points.
Answer: If $\bigcup_{i=1}^{n} A_{i}$ sum up to the entire sample space, yes, it is true. You can check the law of total probability.
Comment: Yeah, $\bigcup_{i=1}^{n} A_{i}$ sum up to entire sample space, I have checked the link and i think that i now get it. Thank you.


Custom normalizer throws error once enabled

Question: I wrote a custom normalizer last year to alter link output (using https://www.mediacurrent.com/blog/using-normalizers-alter-rest-json-structure-drupal-8/ as reference) for use with JSON:API output, which worked like a charm. However, at the moment I get a big error (see below) when I've enabled the module.
The error:
TypeError: Adaptor Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase returned invalid output data: [] in Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase->undoTransform() (line 66 of /vendor/e0ipso/shaper/src/DataAdaptor/DataAdaptorTransformerTrait.php).
Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase->undoTransform(Array, Object) (Line: 65)
Drupal\jsonapi_extras\Normalizer\ResourceIdentifierNormalizer->normalize(Object, 'api_json', Array) (Line: 143)
Symfony\Component\Serializer\Serializer->normalize(Object, 'api_json', Array) (Line: 62)
Drupal\jsonapi\Serializer\Serializer->normalize(Object, 'api_json', Array) (Line: 26)
Drupal\jsonapi\Normalizer\DataNormalizer->Drupal\jsonapi\Normalizer\{closure}(Object)
array_map(Object, Array) (Line: 27)
Drupal\jsonapi\Normalizer\DataNormalizer->normalize(Object, 'api_json', Array) (Line: 143)
Symfony\Component\Serializer\Serializer->normalize(Object, 'api_json', Array) (Line: 62)
Drupal\jsonapi\Serializer\Serializer->normalize(Object, 'api_json', Array) (Line: 26)
Drupal\jsonapi\Normalizer\RelationshipNormalizer->normalize(Object, 'api_json', Array) (Line: 143)
Symfony\Component\Serializer\Serializer->normalize(Object, 'api_json', Array) (Line: 62)
Drupal\jsonapi\Serializer\Serializer->normalize(Object, 'api_json', Array) (Line: 187)
Drupal\jsonapi\Normalizer\ResourceObjectNormalizer->serializeField(Object, Array, 'api_json') (Line: 121)
Drupal\jsonapi\Normalizer\ResourceObjectNormalizer->getNormalization(Array, Object, 'api_json', Array) (Line: 73)
Drupal\jsonapi\Normalizer\ResourceObjectNormalizer->normalize(Object, 'api_json', Array) (Line: 38)
Drupal\jsonapi_extras\Normalizer\JsonApiNormalizerDecoratorBase->normalize(Object, 'api_json', Array) (Line: 24)
Drupal\jsonapi_extras\Normalizer\ResourceObjectNormalizer->normalize(Object, 'api_json', Array) (Line: 143)
Symfony\Component\Serializer\Serializer->normalize(Object, 'api_json', Array) (Line: 62)
Drupal\jsonapi\Serializer\Serializer->normalize(Object, 'api_json', Array) (Line: 26)
Drupal\jsonapi\Normalizer\DataNormalizer->Drupal\jsonapi\Normalizer\{closure}(Object)
array_map(Object, Array) (Line: 27)
Drupal\jsonapi\Normalizer\DataNormalizer->normalize(Object, 'api_json', Array) (Line: 143)
Symfony\Component\Serializer\Serializer->normalize(Object, 'api_json', Array) (Line: 62)
Drupal\jsonapi\Serializer\Serializer->normalize(Object, 'api_json', Array) (Line: 193)
Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer->normalize(Object, 'api_json', Array) (Line: 143)
Symfony\Component\Serializer\Serializer->normalize(Object, 'api_json', Array) (Line: 62)
Drupal\jsonapi\Serializer\Serializer->normalize(Object, 'api_json', Array) (Line: 120)
Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber->renderResponseBody(Object, Object, Object, 'api_json') (Line: 85)
Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber->onResponse(Object, 'kernel.response', Object)
call_user_func(Array, Object, 'kernel.response', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object) (Line: 191)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 173)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 191)
Drupal\page_cache\StackMiddleware\PageCache->fetch(Object, 1, 1) (Line: 128)
Drupal\page_cache\StackMiddleware\PageCache->lookup(Object, 1, 1) (Line: 82)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

My services.yml
services:
  custom_normalizer.typed_data:
    class: Drupal\custom_normalizer\Normalizer\LinkNormalizer
    tags:
      - { name: normalizer, priority: 10 }

The LinkNormalizer file:
<?php

namespace Drupal\custom_normalizer\Normalizer;

use Drupal\Core\Url;
use Drupal\link\Plugin\Field\FieldType\LinkItem;
use Drupal\serialization\Normalizer\NormalizerBase;

/**
 * Converts typed data objects to arrays.
 */
class LinkNormalizer extends NormalizerBase
{
    /**
     * The interface or class that this Normalizer supports.
     *
     * @var string
     */
    protected $supportedInterfaceOrClass = 'Drupal\Core\TypedData\TypedDataInterface';

    /**
     * {@inheritdoc}
     */
    public function normalize($object, $format = null, array $context = array())
    {
        $value = $object->getValue();
        $parent = $object->getParent();
        if ($parent instanceof LinkItem) {
            $internalLink = $parent->get('uri')->getValue();
            $link = Url::fromUri($internalLink, array('absolute' => false))->toString();
            $object->getParent()->get('options')->setValue(['url' => $link]);
        }
        return $value;
    }
}

If anyone has an idea what I'm doing wrong (or what has changed), that would be great. I haven't found anything useful yet.
Stephan
Comment: What is being returned? What is it expecting? The error is "Adaptor Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase returned invalid output data: []"
Comment: It actually doesn't matter what I return, albeit a string, an array, an object, null, it always throws the same error.
Comment: Your class isn't mentioned in the trace which could suggest it's not that code causing the problem. What else does the module do? If you disable the module does the error literally disappear and then reappear as soon as the module is enabled again? Is the error on every page or just happening when you consume a related rest resource?
Comment: The module only contains the code given above. The error is only shown when I consume a jsonapi resource, and disappears when I disable the module.
Answer: Your normalizer is basically a null function:
$value = $object->getValue();

You return typed data values without applying any changes.
You are only doing this to get hold of a different object, the parent field. This is not what the method is supposed to do according to the interface. The result is unpredictable. Instead try to target the normalization process of the field or entity directly.
Comment: Unfortunately, just enabling the module (even with an empty `normalize` function throws the error
Comment: I don't know what you mean by empty, but my advice was to normalize a field or entity directly where you normalize according to the interface.


Generalization of different play-field sizes

Question: I'm currently working on a Deep Reinforcement Learning model for the game "connect 4". Before I started I read some rules and facts about "connect 4". Thats when I noticed after years of playing it, that there is actually no fixed play-field size. Common sizes are e.g. 8x8, 8x7, 7x8. A human might adapt to that quickly. Not so a NN.
My first question is about a fully connected NN. Is my assumption correct, that a model trained on one size will perform poorly on a different size?
Another idea would be the use of CNN. Could this maybe work? I could zero pad different games to e.g. 10x10. Then the model might be able to play different sizes.
Are there maybe other similar examples of generalization of different input arrays? Only found some experimental papers about CNN with a special "pyramid pooling".
Answer: It's hard to transfer a fully connected NN to inputs of differing sizes.
Convolutional neural networks are fairly flexible when it comes to input size. As long as you use some sort of global average pooling on the last conv layer, there is nothing which prevents you from feeding inputs of variable sizes.
If you try to generalize to different board sizes while training only on one, I'd expect it to do poorly, but better than random. If you're able to train on all board sizes, it may do well.


Find the minimum vertex cover for a Bipartite Graph, if we are given the maximum Bipartite Matching

Question: From Konig's Theorem, the size of Maximum Matching (|M|) and minimum vertex cover is the same. Now we can include both ends of the matching in the vertex cover to find a vertex cover, but its size will be 2|M|. So I considered choosing a matching edge and then checking the degree of both ends. And then include the vertex with the higher degree. Suppose the degree of both ends is the same. We can include either. I tried this with a few examples I could think of it worked. But I am not sure of the algorithm. Is this correct? Also, if not, can anyone provide any counter example.?
Comment: @ParclyTaxel The approach you suggested seems to be different from mine. I just wanted to confirm if my approach works too.
Answer: Here is a counterexample:

Here, the maximum matching we have chosen is $M = \{bx, cy, dz\}$. If we pick the highest-degree endpoint of each edge in $M$, we will pick $b$ from $bx$, $y$ from $cy$, and $z$ from $dz$.
This is not a vertex cover. To get a vertex cover, we must pick $x$ from $bx$, because that is the only choice which can cover the edge $ax$.


Como inserir um registro já existente no Entity Framework?

Question: Em certo ponto do sistema alguns registros são selecionados e devem ser replicados alterando apenas um valor.
Neste ponto estou selecionando os registros que preciso inserir:
listaRegistros = listaRegistros .GroupBy(r => r.Id)
                        .Select(grp => grp.First()).ToList();

Logo depois utilizo esses registros selecionados acima para inserir novos registros na tabela:
foreach (var orgao in listaOrgaosASeremAdicionados)
{
    foreach (var registro in listaRegistros)
        registro.Orgao = orgao;
    new RegistrosMeService().InsertListaRegistrosMe(listaRegistros);
}

Aqui está o InsertListaRegistrosMe da classe RegistrosMeService:
protected EFSpecificRepository<TB_RegistrosMe, Entities> _repository;
protected EFSpecificRepository<TB_RegistrosMe, Entities> Repository
{
    get
    {
        if (_repository == null)
            _repository = new EFSpecificRepository<TB_RegistrosMe, Entities>();
        return _repository;
    }
}

public int InsertListaRegistrosMe(List<TB_RegistrosMe> listaMe)
{
    Repository.InsertList(listaMe);
    Repository.SaveChanges();
}

O primeiro loop, onde é feito a inserção, é para informar para quantos órgãos a lista de registros será adicionada, mais de um pode ter sido selecionado.
A unica alteração realizada no registro é a que pode ser verificada no loop, que é a alteração do registro.Orgao.
O problema é que no Insert ocorre o erro:

"Já existe um objeto com a mesma chave no ObjectStateManager. O objeto
  existente está no estado Unchanged. Um objeto só poderá ser adicionado
  novamente ao ObjectStateManager se estiver no estado adicionado."

Já tentei alterar o Id, mas ao tentar fazer isso também ocorre um erro:

A propriedade 'Id' faz parte das informações de chave do objeto e não
  pode ser modificada.

Pelo que entendo esse problema ocorre por que estou observando um registro que já existe no EF e por segurança ele não permite que eu adicione esse registro pois o considera duplicado, correto?
Mas como eu poderia resolver isso sem precisar criar um novo objeto no EF 3.5 (v1)? É possível alterar o ObjectStateManager de forma que ele permita que faça a inserção?
Comment: @jbueno, verifiquei pelo meu `System.Data.Entity` e é essa versão mesmo. Outro fato estranho se realmente não existir é a `tag` estar aqui no SOpt, mas realmente quando pesquiso por essa versão não encontro nada concreto sobre ela. Mas achei [aqui](https://en.wikipedia.org/wiki/Entity_Framework)
Comment: O que tem em `RegistrosMeService.InsertListaRegistrosMe`?
Comment: @CiganoMorrisonMendez é onde estão todos os métodos de select, insert, saveChanges. Quer que edito com o método `InsertListaRegistrosMe`?
Comment: Sim, por favor. É aí que está o problema.
Comment: @CiganoMorrisonMendez adicionei a pegunta.
Comment: Outra coisa: não existe EF3.5. O primeiro EF estável é o 4.1, que deve ser o que você está usando.
Comment: @CiganoMorrisonMendez então a verificação de versão pelo `System.Data.Entity` não está correta? Como identifico a versão corretamente?
Comment: Biblioteca `EntityFramework`, no seu References, ou versão do arquivo `packages.config`.
Answer: O Entity Framework trabalha com coleções observáveis, ou seja, os registros que são retornados da sua consulta estão sendo "observados" pelo contexto para que, quando (e se) houver mudanças estas possam ser refletidas no banco de dados.
Usar o método AsNoTracking() deve resolver. Este método "avisa" ao contexto que não é preciso observar as mudanças nas entidades.
listaRegistros = listaRegistros.GroupBy(r => r.Id)
                    .Select(grp => grp.First()).AsNoTracking().ToList();

Comment: Não funciona. Parece que `AsNoTracking()` nem existia nessa versão. :(
Comment: Nada de `Configuration` no contexto também, omg! Da pra entender por que não acha nada de EF 3.5, ninguém devia usar!
Comment: Pois é, não parei pra pensar nisso. Veja se fazer `context.Configuration.AutoDetectChangesEnabled = false;` te ajuda. Isso deve ter o mesmo efeito.
Answer: Você tem duas alternativas.
Alternativa saudável: clone os objetos que deseja copiar e salve os clones. A vantagem é que quem for ler o seu código para dar manutenção vai entender que era claramente a sua intenção ter novos objetos. Eu digo isso porque ao ler o código que você postou sem considerar o contexto da pergunta, eu juraria de pés juntos, pela minha alma e pela minha mãe, que você confundiu os termos insert e update e que a sua intenção na verdade era editar registros já existentes no banco de dados ao invés de inserir novos.
Ao inserir um objeto completamente novo no repositório, ele fica marcado como um novo objeto nas coleções internas do EF. Quando o contexto for salvo os novos objetos serão inseridos no banco de dados.
Maneira McGyver: essa maneira é muito feia. Sério. Se você fizer isso de propósito eu vou descobrir quem você é só para garantir que nunca vou apertar a sua mão. Vou adicionar essa forma aqui por motivos educacionais, porque muita gente faz isso sem querer quando começa a trabalhar com Entity Framework em conjunto com ASP.NET.
Simplesmente carregue os objetos em um contexto. Feche o contexto. Agora abra outro contexto, adicione os objetos e salve. O novo contexto entenderá que os objetos são novos (pois não os observou durante a sua obtenção) e irá marcar todos para criação no banco de dados.
A maioria das pessoas quando inicia com ASP.NET não percebe que você tem um contexto diferente a cada requisição das páginas. As pessoas carregam os objetos em uma requisição GET e os alteram no processamento de uma requisição POST. Isso já levou a páginas e páginas de perguntas e respostas no Stack Overflow sobre duplicação de objetos ao se utilizar Entity Framework. Para a maioria das pessoas isso é um defeito, mas parece que no seu caso pode ser uma feature (a depender do ciclo de vida dos seus objetos).
Comment: Renan, já estou fazendo o Clone do objeto, mas queria saber se era possível fazer algo como o `AsNoTracking()` sugerido pelo @jbueno. Mas pelo jeito não é possível. Espero que possa apertar minha mão um dia se surgir a oportunidade!! hahah :D
Answer: Se o registro precisa ser replicado, ou seja, reinserido, você não pode reinserir com o mesmo valor de chave primária. Precisa criar objetos novos a partir dos objetos que já existem. Ou seja:
var novaListaDeRegistros = new List<Registro>();

foreach (var orgao in listaOrgaosASeremAdicionados)
{
    foreach (var registro in listaRegistros)
    {
        novaListaDeRegistros.Add(new Registro
        {
            // Coloque aqui todas as propriedades de Registro,
            // com exceção do RegistroId, que será novo.
            registro.Orgao = orgao;
        });
    }
}

new RegistrosMeService().InsertListaRegistrosMe(novaListaDeRegistros);

PS: Livre-se desse repositório.
Comment: Cigano, já estava funcionando exatamente dessa maneira que sugeriu, mas achei que poderia evitar isso. Como sugeriu, a única forma de evitar vai ser me livrando desse repositório.


Envio de dados via ajax gerando novo "_id" no MongoDB

Question: Estou enviando via ajax informações para o backend em Node para realizar um update em um documento no MongoDB, porém sempre que envio o form via frontend, ele gera um novo "_id" ao invés de buscar um ja existente como estou tentando fazer. Segue o código:
**OBS.: **Testei no Insomnia (semelhante ao Postman), e por la tem funcionado até então
Trecho do frontend onde envio os dados do formulario

document.querySelector('#update').addEventListener(
    'click',
    (
        ev,
        url = '/admin/user/update',
        data = {
            _id: userId,
            email: document.querySelector('#email').value,
            name: document.querySelector('#name').value,
            userType: document.querySelector('#userType').value
        },
        success
    ) => {

    success = (data) => {console.log(data)};
    console.log('===> response id', userId)
    let params = typeof data == 'string' ? data : Object.keys(data).map(
            function(k){ return `${k}:${data[k]}` }
        ).join(',');

    let xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");

    console.log('url =====> ', url);
    xhr.open('put', url, true);
    xhr.onreadystatechange = function() {
        if (xhr.readyState>3 && xhr.status==200) { success(xhr.responseText); }
    };
    xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    let obj = new Object();

    params.split(',').forEach(element => {

        element = element.split(':')

        var name = element[0]
        var value = element[1]

        obj[name] = value

    });
    //console.log(obj)
    obj = JSON.stringify(obj);
    console.log('===>obj', obj)
    console.log('===>obj', obj.toString())

    xhr.send(obj);
    return xhr;
});

Trecho no backend tratando essa chamada

router.put('/user/update', async (req, res) => {

    let { _id, email, name, userType} = req.body;

    console.log('user/id =============>',  ObjectID(_id));

    console.log('req.body ======> ', req.body);

    try {
        const user = await User.findOne(ObjectID(_id));
        console.log('User id ======> ', user._id);

        if( user ){

            console.log('User ======> ', user)

            console.log('email, name, userType =====> ', email, name, userType)

            console.log('ObjectID(user._id) ======> ', ObjectID(user._id))

            let updateUser = await User.updateOne({_id}, {$set:{ email, name, userType }});
            if(updateUser)  {
                console.log('===> updated', updateUser);
                console.log('User 2 ======> ', user)
                let message = "Usuario Editado com sucesso";
                console.log(message)

                return res
                    .status(400)
                    .render(path.resolve('../frontend/views/layouts/admin/cadastroUsuario'), {message});

            }

            // if(update){

            //     let message = "Usuario Editado com sucesso";

            //     return res
            //         .status(400)
            //         .render(path.resolve('../frontend/views/layouts/admin/cadastroUsuario'), {message});
            // }

        }

    } catch (err){

        return res.status(400).send({error: 'Update failed: ' + err });
    }
});

Exemplo de Retorno via frontend:
user/id =======> 5df4932bfc08782574c9cf56
req.body => {'{"_id":"5de9cc215f40d1626cabe9c9"
   ,"email":"email@example.com","name":"Vitor
   TE22STE","userType":"adminNv2"}': ''
 }

Answer: Aparentemente você está misturando os tipos string e objectid em _id.
Trocar
let updateUser = await User.updateOne({_id}, {$set:{ email, name, userType }});
por
let updateUser = await User.updateOne(ObjectId(_id), {$set:{ email, name, userType }});
deveria resolver.


O comando prompt muda o valor?

Question: Fazendo um código simples de calcular quanto eu preciso para alcança a média da minha faculdade.
O problema que não consigo receber os valores pelo teclado, uso o comando prompt mas o resultado não fica o mesmo.
Eu coloco esse código e calcula normalmente.

Mas com o prompt o resultado fica errado.

Comment: Alguma das respostas resolveu sua dúvida? Acha que pode aceitar uma delas? Veja o [tour] como fazer isso, se ainda não o fez. Você ajudaria a comunidade identificando qual foi a melhor solução para você. Pode aceitar apenas uma delas. Mas pode votar em qualquer pergunta ou resposta que achar útil no site todo (quando tiver pontuação suficiente).
Answer: Não, ele não muda, não tem como ele mudar. Na verdade a pergunta prate de uma premissa errada.
Em tudo o que você for fazer em um código precisa entender tudo o que está acontecendo. Em especial em uso de funções precisa ler a documentação por completo antes de usá-la. No caso da função prompt() )não é um comando) a documentação diz que o retorno dela é um dado do tipo string. Isso faz toda diferença. Se o retorno é um texto e você tentar fazer uma conta aritmética com ela não acontecerá o que espera. Então seu primeiro código é completamente diferente do segundo, um calcula números e o outro calcula textos.
Como você ainda quer operar em números precisa converter o resultado de prompt() em números. Partindo do princípio que usa valores com ponto decimal e que não é necessário exatidão no cálculo, pode usar a função parseFloat(). O que fará antes de usá-la?
O código poderia ficar assim:

var ap3questoes = (5 - (parseFloat(prompt("Nota da ap1")) + parseFloat(prompt("Nota da ap2"))) * 0.3) / 0.16;
document.write(ap3questoes * 0.4);
document.write(Math.round(ap3questoes));

Então está resolvido? Não, ainda há problemas. Como eu disse só funciona se você não quer exatidão, teste números diferentes e verá que há casos que não dá o número que deseja. E nada tem a ver com o prompt(), e sim com o tipo float que não é adequado para exatidão, então dá erro até com o número direto. A maioria dos programadores ignoram isto e tem seus códigos errados sem perceber por anos.
Existe um erro de encavalamento da informação apresentada em tela nos dois códigos, é secundário, mas é bom deixar claro que há.
Por fim, e se a pessoa digitar um formato inválido? Um código correto não pode exigir que a pessoa digite certo para funcionar, a não ser que ele informe isso depois de validar. Claro, ele não faz milagre, não vai arrumar o problema, mas seu código precisa identificar que houve um erro de digitação, como por exemplo uma letra ter sido digitada, ou um ponto equivocado. Seria algo assim:

function teste() {
    var t1 = prompt("Nota da ap1");
    if (isNaN(t1)) return;
    var t2 = prompt("Nota da ap2");
    if (isNaN(t2)) return;
    var ap3questoes = (5 - (parseFloat(t1) + parseFloat(t2)) * 0.3) / 0.16;
    document.write(ap3questoes * 0.4);
    document.write(" - ");
    document.write(Math.round(ap3questoes));
}
teste();

Coloquei no GitHub para referência futura.
Answer: Deve converter os valores passados via prompt para float:

    var ap1 = parseFloat(prompt("Nota da ap1"));
    var ap2 = parseFloat(prompt("Nota da ap2"));
    var ap3nota = 5 - ((ap1 + ap2) * 0.3);
    var ap3questoes = (ap3nota / 0.16);
    var nota = ap3questoes * 0.4;

    document.write(nota);
    document.write(Math.round(ap3questoes));

PS: Você deve digitar os valores com . (ponto) como separador decimal. Ex.: 1.2 ao invés de 1,2.

O comando prompt muda o valor?


Absolute and conditional convergence of series containing trigonometric functions

Question: I have a slight problem with this kind of exercise. For example, if we have:
$$\sum_{n=1}^\infty \frac{\cos{\frac{n\pi}{4}}}{n^a}, a>0$$
Now, for example, say I want to check the absolute convergence of this example. I know that there are negative terms depending on $n$, and the maximum value $\cos{\frac{n\pi}{4}}$ can attain is $1$.
$$\vert\frac{\cos{\frac{n\pi}{4}}}{n^a}\rvert\le \frac{1}{n^a}$$

Was I correct to make this deduction?

Do I proceed like this any time I have a $sin$ or $cos$ function when checking for absolute convergence?

If I am correct, my series absolutely converge for $a>1$. How do we check if it conditionally converges for $0<a<1$?

We are not allowed to use any integration techniques (Abel's and Dirichlet's test are encouraged).
Thanks!
Comment: Actually I originally wrote $1$ but changed it as I was a little bit tired last night and didn't think properly.
Answer:
Yes.
It's always a good thing to try.
You are correct about when it converges absolutely, but keep in mind that so far you haven't shown it doesn't converge absolutely for any $a\le 1,$ only that it does converge absolutely for $a>1.$ (Hint: you can lower bound it too, though some terms are zero so it's a little trickier.) The fact that it converges for any $a>0$  follows from one of the two tests you mentioned.
Comment: I tried lower-bounding it by $\frac{-1}{n^a}$  to try to prove divergence by comparison for $a\le1$  but it does not work as the series I am comparing it to diverges $-\infty$. I do not know how to proceed.
Comment: @john You are checking absolute convergence so everything should be positive. You should be proving it is greater than something that diverges to infinity.


Conditional Probability Question from Prob and Stats by Example - Suhov and Kelbert

Question: The following question is taken from Probability and Statistics by example by Yuri Suhov and Mark Kelbert.
Problem 1.9 At the station there are three payphones which accept 20p pieces. One
never works, another always works, while the third works with probability $1/2$. On my
way to the metropolis for the day, I wish to identify the reliable phone, so that I can use
it on my return. The station is empty and I have just three 20p pieces. I try one phone
and it does not work. I try another twice in succession and it works both times. What is
the probability that this second phone is the reliable one?
The initial part of the solution is as follows:
Solution Let $A$ be the even in question: the first phone tried did not work and second worked twice. Clearly:
$$ \mathbb{P}(A | \text{1st reliable}) = 0 $$
$$\mathbb{P}(A | \text{2nd reliable}) = \mathbb{P}(\text{1st never works} | \text{2nd reliable}) +\frac{1}{2}\mathbb{P}(\text{1st works half-time}|\text{2nd reliable})$$
...
I understand intuitively why the first line holds - clearly the first reliable contradicts it ever failing. However, I do not understand the second line or where it has come from.
Any help would be appreciated!
Answer: It is the Law of Total Probability:
Let $N=n$ be the event for phone#$n$ never working, $H=n$ that it works half-times, and $R=n$ that it is always reliable.   (For $n\in\{1,2,3\}$ of course).   Note: Since the first cannot be reliable when the second is, therefore events $N=1,H=1$ partition $R=2$.
Take $A$: as the event for the data, "first did not work and second worked twice".   Now, the probability that this happens when the first never works and the second is reliable is $1$.   Whereas the probability for this when given the first is half reliable and the second is reliable is $1/2$.
$$\begin{split}\mathsf P(A\mid R{=}2) &=\mathsf P(A,N{=}1\mid R{=}2)+\mathsf P(A,H{=}1\mid R{=}2)\\ &=\mathsf P(A\mid R{=}2,N{=}1)\mathsf P(N{=}1\mid R{=}2)+\mathsf P(A\mid R{=}2,H{=}1)\mathsf P(H{=}1\mid R{=}2)\\&= \mathsf P(N{=}1\mid R{=}2)+\tfrac 12\mathsf P(H{=}1\mid R{=}2)\\&=\tfrac 12+\tfrac 12\tfrac 12\\&=\tfrac 34\end{split}$$
Similarly, and can you see why?
$$\begin{split}\mathsf P(A\mid R{=}3)&=\mathsf P(A\mid R{=}3,N{=}1,H{=}2)\mathsf P(N{=}1\mid R{=}3)+\mathsf P(A\mid R{=}3,H{=}1,N{=}2)\mathsf P(H{=}1\mid R{=}3)\\&= \tfrac 14\mathsf P(N{=}1\mid R{=}3)+0\mathsf P(H{=}1\mid R{=}3)\\&=\tfrac 18\end{split}$$
And as you already stated: $\mathsf P(A\mid R{=}1)=0$... because the data can never happen when the first phone is reliable.
So again by the Law of Total Probability, the (prior) proability for the data is:$$\begin{split}\mathsf P(A)&=\mathsf P(A\mid R{=}1)\mathsf P(R{=}1)+\mathsf P(A\mid R{=}2)\mathsf P(R{=}2)+\mathsf P(A\mid R{=}3)\mathsf P(R{=}3) \\ &=0+\tfrac 34\tfrac 13+\tfrac 18\tfrac 13\\&=\tfrac 7{24}\end{split}$$
Comment: Many thanks for the comprehensive answer. It seems my downfall was the inability to use the identity in the second line of equation. By the definition of conditional probability, I can now see this holds. Thank you very much!
Comment: $+1$. Then the required probability will be: $P(R=2|A)=\frac{P(R=2\cap A)}{P(A)}=\frac{P(R=2)P(A|R=2)}{P(A)}=\frac{\frac13\cdot \frac 34}{\frac 7{24}}=\frac 67$. For comparison I have an alternative solution below with the probability tree diagram.
Answer: Let $H,D,W$ be "half-work", "does not work" and "work" phones, respectively.
Also, let "$X,Y$" be "not work" and "work", respectively.
Refer to the probability tree diagram:

The required probability is:
$$\frac{\frac1{12}+\frac16}{\frac1{12}+\frac1{24}+\frac16}=\frac67.$$
Comment: Thank you. My pleasure.
Comment: Correct answer. Simple , Easy to understand, and Elegant.
Answer: I tried to follow the first answer but I'm not getting it. For example: trying to see how to calculate $ P(A\mid R{=}2)$ should consider getting the outcome A versus any other outcome when $R=2$. That is $0,1,1$ outcomes versus the only other possible $1,1,1$ outcome where $0$ is a failure and $1$ a success. For N(never) H(half) and R(reliable), the phone configurations are $1 3 2$ and $3 1 2$.
Update: Ok, now I get it.

From the above table my answer is  $$P(A\mid R{=}2)= \frac{1+\frac{1}{2}}{1+\frac{1}{2}+\frac{1}{2}} = \frac{3}{4}$$
Comment: I must admit, intuitively there seems to be something missing in the calculation. That is, nowhere does anything appear about the probability of two successes of the second phone, whereby it is solely based on a single failure of the first,
Comment: No.  $P(\text{first-not-working-once}\mid \text{second-reliable},\text{only-tried-the-first-once})=2/3$.  That is *not* the probability that it *never-works* given the second-reliable.
Comment: Yes, I'll delete it and give it some more thought. It's tricky.
Comment: @Graham. Is this the probability of the first phone being the phone that never works or, whatever phone it is, the probability it will never work?
Comment: Suppose I ask what is the optimal strategy by which I can identify the always reliable phone.  By optimal, I mean the strategy that has the smallest expectation of # calls.  What would that be?


How does the Rectified Linear Unit (ReLU) activation function produce non-linear interaction of its inputs?

Question: When used as an activation function in deep neural networks The ReLU function outperforms other non-linear functions like tanh or sigmoid . In my understanding the whole purpose of an activation function is to let the weighted inputs to a neuron interact non-linearly. For example, when using $sin(z)$ as the activation, the output of a two input neuron would be:
$$ sin(w_0+w_1*x_1+w_2*x_2) $$
which would approximate the function
$$  (w_0+w_1*x_1+w_2*x_2) - {(w_0+w_1*x_1+w_2*x_2)^3 \over 6} + {(w_0+w_1*x_1+w_2*x_2)^5 \over 120} $$
and contain all kinds of combinations of different powers of the features  $x_1$ and $x_2$.
Although the ReLU is also technically a non-linear function, I don't see how it can produce non-linear terms like the $sin(), tanh()$ and other activations do.
Edit: Although my question is similar to this question, I'd like to know how even a cascade of ReLUs are able to approximate such non-linear terms.
Comment: IMHO this question is much more clearly stated than the one it's marked as a duplicate of. So then to ask his question the OP would have to edit the other post. Or he could make a comment on the other post, but then he's limited by number of words and formatting. Also, the OP is asking for addition information. So what is the standard practice when a duplicate doesn't quite answer your question, or it's poorly phrased?
Comment: @orodbhen I think these are great questions to raise on Meta.
Comment: There's a similar question asked before: https://stats.stackexchange.com/questions/275358/why-is-increasing-the-non-linearity-of-neural-networks-desired though it's probably not a duplicate
Answer: Suppose you want to approximate $f(x)=x^2$ using ReLUs $g(ax+b)$. One approximation might look like $h_1(x)=g(x)+g(-x)=|x|$.

But this isn't a very good approximation. But you can add more terms with different choices of $a$ and $b$ to improve the approximation. One such improvement, in the sense that the error is "small" across a larger interval, is we have $h_2(x)=g(x)+g(-x)+g(2x-2)+g(-2x+2)$, and it gets better.

You can continue this procedure of adding terms to as much complexity as you like.
Notice that, in the first case, the approximation is best for $x\in[-1,1]$, while in the second case, the approximation is best for $x\in[-2,2]$.

<code>x <- seq(-3,3,length.out=1000)
y_true <- x^2
relu <- function(x,a=1,b=0) sapply(x, function(t) max(a*t+b,0))

h1 <- function(x) relu(x)+relu(-x)
png("fig1.png")
    plot(x, h1(x), type="l")
    lines(x, y_true, col="red")
dev.off()

h2 <- function(x) h1(x) + relu(2*(x-1)) + relu(-2*(x+1))
png("fig2.png")
    plot(x, h2(x), type="l")
    lines(x, y_true, col="red")
dev.off()

l2 <- function(y_true,y_hat) 0.5 * (y_true - y_hat)^2

png("fig3.png")
    plot(x, l2(y_true,h1(x)), type="l")
    lines(x, l2(y_true,h2(x)), col="red")
dev.off()
</code>
Comment: Define $g(x)=\max\{x,0\}$. Neural networks are parameterized by affine transformations $ax+b$, so if we combine these operations together we get $g(ax+b)$, which is a composition of one layer's parameters and activation functions into a single operation. It's just notationally convenient for this answer.
Comment: Sorry if this is dumb question, ReLu = max(0, x), can you please explain why you used ReLu as g(ax+b)
Comment: Thanks for the quick reply. Learnt a lot from several of your answers in the forum. They are very clear.
Comment: For a simple higher-dimensional version of this, see e.g. https://datascience.stackexchange.com/q/76022/55122
Answer: Think of it as a piecewise linear function. Any segment of the function that you want to model (assuming it's smooth) looks like a line if you zoom in far enough.


Qmail Log: lots of UNAUTHENTICATED SENDER

Question: On qmail logs there are lots of the following lines:
2012-12-14 18:04:49.314299500 simscan:[9999]:CLEAN (4.00/50.00):2.2875s:Delivery Status Notification (Failure):aa.aa.aa.aa::email@example.com
2012-12-14 18:04:49.657999500 CHKUSER accepted rcpt: from <::> remote <utility-xxxx.it:unknown:aa.aa.aa.aa> rcpt <email@example.com> : found existing recipient
2012-12-14 18:04:49.658005500 policy_check: local  -> local email@example.com (UNAUTHENTICATED SENDER)
2012-12-14 18:04:49.658016500 policy_check: policy allows transmission
2012-12-14 18:04:49.658019500 spamdyke[9945]: ALLOWED from: (unknown) to: email@example.com origin_ip: 220.127.116.11 origin_rdns: utility-xxxxx.it auth: (unknown)

and
12-14 18:03:57 CHKUSER accepted rcpt: from <::> remote <utility-xxxx.it:unknown:aa.aa.aa.aa> rcpt <email@example.com> : found existing recipient
12-14 18:03:57 policy_check: local  -> local email@example.com (UNAUTHENTICATED SENDER)
12-14 18:03:57 spamdyke[9945]: ALLOWED from: (unknown) to: firstname.lastname@example.com origin_ip: aa.aa.aa.aa origin_rdns: utility-xxxx.it auth: (unknown)
12-14 18:03:59 simscan:[9999]:CLEAN (4.00/50.00):2.4153s:Delivery Status Notification (Failure):aa.aa.aa.aa::email@example.com
12-14 18:04:00 CHKUSER accepted rcpt: from <::> remote <utility-xxxx.it:unknown:aa.aa.aa.aa> rcpt <email@example.com> : found existing recipient
12-14 18:04:00 policy_check: local  -> local email@example.com (UNAUTHENTICATED SENDER)
12-14 18:04:00 spamdyke[9945]: ALLOWED from: (unknown) to: email@example.com origin_ip: aa.aa.aa.aa origin_rdns: utility-xxxx.it auth: (unknown)
12-14 18:04:02 simscan:[9999]:CLEAN (4.00/50.00):2.5481s:Delivery Status Notification (Failure):aa.aa.aa.aa::firstname.lastname@example.com
12-14 18:04:02 CHKUSER accepted rcpt: from <::> remote <utility-xxxx.it:unknown:aa.aa.aa.aa> rcpt <email@example.com> : found existing recipient
12-14 18:04:02 policy_check: local  -> local email@example.com (UNAUTHENTICATED SENDER)
12-14 18:04:02 spamdyke[9945]: ALLOWED from: (unknown) to: firstname.lastname@example.com origin_ip: aa.aa.aa.aa origin_rdns: utility-xxxx.it auth: (unknown)

Does this mean something unwanted?
Thank you... I'm completely new to qmail
Answer: possibly these are the bounce message recieved by the user firstname.lastname@example.com

12-14 18:03:57 CHKUSER accepted rcpt: from <::> remote  rcpt  : found existing recipient

It is possible that someone has spoofed the mail id of sender and might be performing some  spam activity. And as we all know spammers send mails to random ids and most of which do-not exists. In return the sender id would get a bounce message.
Just verify it.


Infinity vs. mantl

Question: I recently stumbled upon http://mantl.io/ and https://mesosphere.com/infinity/. However, I am unsure about the advantages of each approach.
So far I know mantl integrates some components like ELK, calico, vault, traefik which are nice to have out of the box for a common application. Whereas infinity seems to be well suited for IOT /big-data analytics applications.
Can you help me to explain the difference / advantages of each approach.
Answer: A bit comparing apples and oranges. Infinity is what we call a DCOS stack, it's a combo of different services (in this case Kafka, Spark, C*, and Akka) for a specific domain, in this case IoT apps.
I wouldn't say that ELK is a unique thing to mantl, since it's also available on the DCOS and in fact I did install ES on DCOS myself a while ago, with little effort. The same is true for Vault, etc.
DCOS comes with a number of services, growing every week, ready to be used in different application areas: from pure stateless deployments (for example a Web server farm) to CI/CD envs to analytics (and IoT).

Infinity vs. mantl


transferring userId from one component to another using vue router

Question: I have a list of users obtained from the api. I need to make sure that when you click on the user's name, a page with his information opens with a separate link
Component UsersList
<button @click="showUserPage(user.id)">Go to the user's page</button>

data() {
  return {
    users: []
  }
}

showUserPage(userId) {
  // Navigation to user details
  this.$router.push({ name: 'user-page', params: { userId: userId } })
}

fetchUsers() {
  axios.get('https://jsonplaceholder.typicode.com/users/')
      .then(response => {
        this.users = response.data;
      })
      .catch(error => {
        console.error('Error loading users', error);
      });

Component UserPage
data(){
    return{
      user: {},

    }
  },
methods:{
  getUser(userId) {
    axios.get(`https://jsonplaceholder.typicode.com/users?userId=${userId}`)
        .then(response => {
          this.user = response.data;
        })
        .catch(error => {
          console.error('Error loading users', error);
        });
  }

created() {
  this.getUser(this.$route.params.userId)

router.js
const routes = [
    { path: '/', component: UserList },
    { path: '/user/:userId',name:'user-page', component: UserPage }
]

after clicking on the button, a link with the correct id appears (like 'http://localhost:8080/#/user/8').But if I'm trying to display user information {{user.name}} I'm getting an error 'Uncaught ReferenceError: user is not defined'.After trying to console.log(this.$route.params.userId) i get error "cannot read properties of null (reading '$route')
What am I doing wrong?
Comment: `this.user` is set in `getUser()` so it is undefined, until `getUser()` is called. Maybe set it to a mocked value to see if that is displayed and then think about when to call `getUser()`
Comment: if you mean passing the id to a separate variable, then I've already tried and get error "cannot read properties of null (reading '$route')"
Comment: No that's not what i mean; I thought that your error is not what you think (because the passing of `userId` seems to be correct). You could try to pass it as query parameter (google that) just to test a different way.

But first: can you make sure which variable is undefined
is it `this.$route`?  or `this.$route.params`? or `this.$route.params.userId` or is it `this.user` (as i am expecting)
Therefore add a console.log(this.$route) and so on to created() on the user page and check the log in your browser dev utils.

And if i am right setting `user: {'name': 'unknown'}`, will fix it
Answer: It sounds like your template is attempting to render the user object before it has a chance to get a response from your API.
You may need to surround your {{ user.xx }} calls with a v-if to prevent Vue from trying to render it.
Something like this:

    Hello, {{ user.firstName }}

To get real fancy, you could add some sort of loading indicator for your users.
Something like this:

Then in your template you could do something like this:

    Getting user info...

    Hello, {{ user.firstName }}


Monowall can't connect via Cisco DPC3941B Modem/Router

Question: We have a monowall router behind DPC3941B, having trouble connecting to internet. Just purchased static IP and still can't get it to work. Comcast says everything looks good on their side. Modem is in Bridge Pass-through mode.
On the monowall on WAN interface we tried entering static IP and gateway they gave us and still no go. Also, there is field for entering MAC address, I assume MAC address from the modem, we tried both of them as well.
If we connect desktop directly to the modem we get 169.x.x.x address not our static IP.
What else can we do to get it going?
Thanks
Answer: Check you Netmask, it should probably be /30 (and I think monowall defaults* to /31).  Comcast should have given you three numbers (well, not counting the two DNS servers):

Your usable IP address
The gateway IP
The Netmask to use

For single static IP accounts, this is usually 255.255.255.252 (or /30).  For reference, see http://www.subnet-calculator.com/cidr.php
Also, be sure to set the WAN Type drop-down to 'Static' in the monowall config page as it defaults to DHCP.  Leave the rest of the fields blank, including MAC spoofing.
To talk to the Comcast router you'll need to put static IP info into the computer/laptop you're plugging in to it.  By default, Comcast routers will not have DHCP running but should be listening on 10.1.10.1  Change your computer from using DHCP to using a fixed IPv4 of 10.1.10.2 and then plug into the Comcast box.  You should then be able to open 10.1.10.1 in a web browser and get the modem's login page.
*I haven't used monowall in ages, and could very well be wrong on this
Comment: Thank you for your help. It was exactly these things you mentioned that needed to be configured in order to work.


Why is the i–VII–VI–VII progression written as Am–G–F–G in puget sound's music theory book?

Question: I was flipping through Puget Sound's free music theory book, and saw this page https://musictheory.pugetsound.edu/mt21c/i-VII-VI-VII.html
Why did he write the i–VII–VI–VII progression as Am–G–F–G instead of Am-G#-F#-G#. And why did he not write out i-bVII-bVI-bVII ?
He writes out a similar progression but notes that it is 1-b7-b6-5  and I find this confusing.
Answer: First, Roman numeral analysis presumes natural minor, so G and F are correct for the VII and VI chords in A minor.
There are various conventions for writing Roman numerals for music. The one being adhered to here uses VII for the "seven chord" in minor, because the "flat seven" is native to the key (i.e., not an alteration to the underlying scale) and because it's a major chord. For a major key the symbol would be viio.
(See also: Why the flat roman numerals in minor when they aren't needed?)
However, when describing the 1-b7-b6-5 bass line, individual scale degrees are being specified (as opposed to chords), and the mode is not indicated. In this case, major is the reference point, so the flats are included.


How to numerically evaluate large binomial coeffcient terms?

Question: I am looking at a linear program (Eq (72) of https://arxiv.org/pdf/1807.05354.pdf). $r$ is an $n$-dimensional vector with elements $r_k$ and $d=2$. One of the constraints is
$$\sum_{k=0}^{n}\left(\begin{array}{l}
n \\
k
\end{array}\right)\left(\frac{1}{d}\right)^{k}\left(d-\frac{1}{d}\right)^{n-k} r_{k}=1$$
The authors are able to evaluate such terms for $n = 10,000$. However, when I choose even $n=100$, MATLAB is unable to store the coefficients accurately since the binomial coefficient is just too large and the solver starts to generate warnings.
Is there a trick to numerically evaluate these for a linear program solver?
Comment: Are you using factorials to calculate the binomial coefficients?
Comment: No, I am using MATLAB's nchoosek(n,k) function
Comment: You may get some ideas searching for "fast binomial coefficient" on [StackOverflow](https://stackoverflow.com).
Answer: As $k$ increases, $\binom nk$ may increase, but the other factors $(1/2)^k$ and $(3/2)^{n-k}$ decrease. So I suggest combining the calculations to keep the product at a moderate size: $$\sum_ka_kr_k=1$$ $$a_k=\binom nk\left(\frac12\right)^k\left(\frac32\right)^{n-k}$$ $$a_0=\left(\frac32\right)^n,\quad a_{k+1}=a_k\cdot\frac{n-k}{k+1}\cdot\frac13$$ I haven't tested this, though. And for $n=10000$ the leading term $a_0$ is still greater than $\sqrt2^{10000}=2^{5000}$, so standard 64-bit floating-point numbers are not sufficient.
Comment: Thanks, it's a good idea but as you say, still insufficient. Not sure how those authors did it
Answer: Writing
$$
  {n \choose k} = \frac{n}1\ \frac{n-1}2\ \frac{n-2}3\ \ldots \ \frac{n-(k-1)}k
  $$
I would write a subroutine that starts by multiplying the first few terms above until it gets bigger than some
predefined
threshold.  I would then turn to successively multiplying  the above by $1/2$ until it gets below a predefined $\varepsilon >0$.
In between one could also sprinkle some factors $3/2$ in order to balance the growth of the product.
Thus, unless the
final result of    ${n \choose k} (1/2)^k(3/2)^{n-k}$ is too big for your system to handle, you will never  face any overflow.


Has a "lucky loser" ever won an ATP or WTA tournament?

Question: This question made me wonder if a "lucky loser" has ever won a big tournament (ATP, WTA etc.)? If it has happened, is there some kind of overview of all the players that did so?
Comment: Wikipedia article has a section named [Lucky losers as tennis tournament winners and finalists](https://en.wikipedia.org/wiki/Lucky_loser#Lucky_losers_as_tennis_tournament_winners_and_finalists). However, the information given there seems a bit incomplete and lacking references.
Comment: Some related information can also be found here:
[The Luck of the Loser: Tennis' Legendary (LL)s](http://thetennisisland.com/2015/01/07/the-luck-of-the-loser-tennis-legendary-lls/),
[Best "Lucky Losers" list](http://tt.tennis-warehouse.com/showthread.php?t=426667)
Comment: [This post](http://www.menstennisforums.com/showthread.php?t=147569&page=5) mentions 6 case where it happened in ATP events. Wikipedia claims there were seven, but does not list the names. [This article](http://tennisnews.com/exclusive.php?pID=23983) mentions 5 names.
Comment: I think that the articole you mentioned is before Ram's victory in Newport
Answer: Those players have won an ATP tournament as a lucky loser:

Heinz Gunthardt (Springfield 1978)
Bill Scanlon (Maui 1978)
Francisco Clavet (Hilversum 1990)
Christian Miniussi (Sao Paulo 1991)
Sergiy Stakhovsky (Zagreb 2008)
Rajeev Ram (Newport 2009)
Andrey Rublev (Umag 2017)
Leonardo Mayer (Hamburg 2017)
Marco Cecchinato (Budapest 2018)
Answer: Lucky losers that won WTA tournaments:1

Olga Danilović (Moscow 2018)

Sources

Wikipedia article Lucky loser
Danilovic claims first title in Moscow after all-teen tussle - WTA website (Wayback Machine)
38 years later Lucky Loser win again WTA tournament - Tennis Forum

1Several sources claimed that actually the first lucky loser WTA winner was Andrea Jaeger in 1980 Las Vegas. (For example, several revisions of the Wikipedia article on Lucky loser, another article on WTA website.)


@Prompt ([YesNo] does not return expected value

Question: I am new in this forum, Thank you for your welcome.
I am developping a db.
I am using @Prompt ([YesNo] formula but when I get the rep, it is empty.
rep = @Prompt ([YesNo];"C.C.F - Consolidation des repas";"Etes-vous sûr de continuer ?");
@Prompt ([Ok];""; @Text(rep));
@If (rep=1;@Command([ToolsRunMacro];"Consolidation Repas Cantine");@Nothing)

Why is that so ? I should receive 1 or 0.
Regards.
Comment: The = is always a comparison operator in Formula language.
Answer: You have to assign a value to a variable with :=.
Change your code to
rep := @Prompt ([YesNo]...


Construct confidence interval of the mean for auto-correlated data

Question: I feel like I'm missing something obvious, but here we go. I have auto-correlated data measured in triplicate for two (or more) treatments. Something like this:
t <- 3:20 #times in my real dataset are possibly not always equidistant
a <- structure(c(0.652492388457625, 0.905172522010166, 1.23437705454616,
                 1.48003667490842, 1.77876898946135, 1.99175317367897, 2.31666502140984,
                 2.43520651415548, 2.67903421794922, 2.84115747823017, 2.89693734873647,
                 2.91199679761145, 2.85645436179354, 2.99371033437697, 2.99965220711105,
                 2.84984814715963, 2.64275376547326, 2.64060469520379, 0.481029734912324,
                 0.8466803252367, 1.31126162780809, 1.56745630574946, 1.74865844658142,
                 1.80367117155375, 2.06688393210808, 2.24500095501872, 2.52978288460243,
                 2.69073206006205, 2.89657418056785, 2.93759772556246, 2.99305951550274,
                 2.89146932307489, 2.88890777189028, 2.7974672802907, 2.70933381639295,
                 2.66799551352975, 0.624178180970784, 0.867127935268765, 1.09752295578438,
                 1.35037796202753, 1.60094288950107, 1.97949255710341, 2.15496378191076,
                 2.42556913246041, 2.54331160179646, 2.67440414122285, 2.84249532365163,
                 2.95278639560433, 3.06192227561515, 3.03297885461444, 3.04101341059534,
                 3.01736966686846, 2.80061410999215, 2.69852643323913),
               .Dim = c(18L, 3L), .Dimnames = list(NULL, c("a1", "a2", "a3")))
b <- structure(c(0.516527990622755, 0.84883434472028, 1.04202664437099,
                 1.3100841689546, 1.48050413266838, 1.7824492800856, 1.96557179831706,
                 2.17419105778186, 2.2453178060978, 2.35460428313729, 2.49308342865959,
                 2.62343038370418, 2.70831189685371, 2.79459971623943, 2.94938536147398,
                 3.04822554887815, 3.00287042052314, 2.91673487674283, 0.589490441973075,
                 0.751768045201717, 0.917973959434798, 1.17617337222852, 1.39497560590896,
                 1.65920945485901, 1.87749014780468, 2.11880355292648, 2.372755207219,
                 2.46211141942227, 2.59688733749884, 2.72270421752644, 2.79848710425447,
                 2.81134394947587, 2.75390203306788, 2.78499114431362, 2.86001341271914,
                 2.95652300178809, 0.558662398944567, 0.834996005844121, 0.988238211915554,
                 1.27569591423003, 1.38577342414377, 1.62664982549252, 1.83299700801392,
                 2.04943560731628, 2.22950648854987, 2.38533269800646, 2.49845003387994,
                 2.60036098089373, 2.61941602504858, 2.71298500309883, 2.78126388719353,
                 3.04792375845498, 3.02691814463875, 3.06667590650438),
               .Dim = c(18L, 3L), .Dimnames = list(NULL, c("b1", "b2", "b3")))

matplot(t,a,pch=1,xlab="",ylab="",col="blue")
matlines(t,a,col="blue", lty=2)

matpoints(t,b,pch=16,col="red")
matlines(t,b,col="red", lty=2)

I would like to know in which time periods the treatments differ. I would like to avoid fitting any kind of model. (There are models for my kind of data from science, but they are known to be only an approximation for some ranges of my data and I'm afraid that model error might mask differences.) My idea is to calculate the mean and construct confidence intervals (using an assumption of normality) like this:
a_means <- apply(a,1,mean)
a_sds <- apply(a,1,sd)
a_lwr <- a_means-qt(0.975,3)*a_sds/sqrt(3)
a_upr <- a_means+qt(0.975,3)*a_sds/sqrt(3)

b_means <- apply(b,1,mean)
b_sds <- apply(b,1,sd)
b_lwr <- b_means-qt(0.975,3)*b_sds/sqrt(3)
b_upr <- b_means+qt(0.975,3)*b_sds/sqrt(3)

DF <- data.frame(treat=factor(rep(1:2, each=length(t))),
                 time=rep(t, 2),
                 mean=c(a_means,b_means),
                 lwr=c(a_lwr,b_lwr),
                 upr=c(a_upr,b_upr))

library(ggplot2)
p <- ggplot(DF, aes(x=time, y=mean, ymin=lwr, ymax=upr)) +
  geom_ribbon(aes(fill=treat), alpha=0.3) +
  geom_line(aes(color=treat))
print(p)

The way I'm constructing the confidence intervals obviously doesn't consider auto-correlation.

Is there a way to construct some kind of "auto-correlated confidence interval"?
Can I use the "un-correlated confidence interval"? Can I somehow estimate if it is too narrow or too wide in comparison to the auto-correlated confidence interval?
Is there a better approach to my problem?
Comment: Fascinating question, and it seems like this is a problem still being debated. Here's an interesting paper on the subject http://mpra.ub.uni-muenchen.de/31840/
Answer: Here are a couple thoughts that may be helpful:

Auto-correlation doesn't matter when you only look at a single t at a time. So, at a fixed time t, you could just run a t-test to check for a difference in means. If you run the t-test for each time separately, then you get a bunch of p-values. Because of auto-correlation these p-values are not independent, but each p-value considered alone is just fine.
So now you want to find the times for which there is a difference in means. I would try using false discovery rate (FDR) methods (see the "Benjamini-Hochberg procedure" at http://en.wikipedia.org/wiki/False_discovery_rate). Luckily, this procedure controls the FDR even when there is positive dependence among your p-values. (see "The Control of the False Discovery Rate in Multiple Testing under Dependency", free version here http://thom.jouve.free.fr/work/thesis/sitecopy_save/Biblio/ToCheck/fdr/Benjamini2001.pdf) This should give you a reasonable first answer to your original question.
Finally, I think the two plots you drew are very clear. They are probably more informative than any kind of statistical analysis you can run... Good luck!

Edit by Roland:
Here is an R implementation of the FDR method for the example in the question. The result looks reasonable.
dat <- setNames(cbind(stack(as.data.frame(t(a))),
                      stack(as.data.frame(t(b)))),
                c("a", "i", "b", "i"))
dat <- dat[,-4]
library(plyr)
p.raw <- ddply(dat, .(i), function(df) t.test(df$a, df$b)$p.value)
p.fdr <- cbind(p.adjust(p.raw[,2], method="fdr"),
               t[as.numeric(gsub("V","",p.raw[,1]))])
p.fdr[order(p.fdr[,2]),]

#             [,1] [,2]
#  [1,] 0.63001435    3
#  [2,] 0.19439226    4
#  [3,] 0.06200315    5
#  [4,] 0.07335654    6
#  [5,] 0.05336699    7
#  [6,] 0.06115999    8
#  [7,] 0.06115999    9
#  [8,] 0.06103370   10
#  [9,] 0.04324050   11
# [10,] 0.04324050   12
# [11,] 0.04324050   13
# [12,] 0.04324050   14
# [13,] 0.06103370   15
# [14,] 0.05533972   16
# [15,] 0.15489402   17
# [16,] 0.58234624   18
# [17,] 0.05533972   19
# [18,] 0.04324050   20

Comment: Thank you for pointing me to the FDR method. This looks promising. I took the liberty to add an implementation to your answer.