How do I display my output comparing the effect of variables on classification of disease from a random forest analysis in R using an AUROC?

Question: I am using a random forest classification to compare how the classification of disease improves when combining metabolites with two other measures ( visceral fat and CRP-1 levels) to see if adding the metabolite information improves classification than just visceral fat and CRP-1 levels together.

Adding metabolites only improves classification slightly ( I have small sample numbers and a small number of metabolites which doesn't help).
Here is the output from metabolites, visceral fat and CRP-1 levels

Here is the output from just the visceral fat and CRP levels

Whilst from this tutorial using the iris data, three lines are present on the ROC ( one for each species). https://www.blopig.com/blog/2017/04/a-very-basic-introduction-to-random-forests-using-r/
Please could anybody tell me how I would be able to plot two lines for the ROC curve for the disease group ( false positive vs true positive) showing one with the metabolites + visceral fat + CRP-1, whilst another with just visceral fat + CRP-1 ( a bit like the image above but the graph will only have two lines). I cannot seem to find any example online at the moment. My outcomes are not just from one model as with the iris data, as I ran two different ones ( one with the two variables, the other with the two variables + metabolites).
Any help or link to an example would be very appreciated.
Comment: I think the main problem here is that you are having $55$ points in your OOB predictions. Use repeated resampling (repeated $k$-fold, stratified bootstrap, pick your favourite) to get more stable estimates.
Answer: You can use pROC to add the two lines on to one plot
<code>  ###model with metabolites, visceral fat and CRP-1
 result.predicted.prob <- predict(rf.fit, mod_test.newy, type="prob")

  result.roc <- roc(mod_test.newy$Disease, result.predicted.prob$UC)

 ##model with just visceral fat and CRP-1
 result.predicted.prob2 <- predict(rf.fit2, justviscfat.crp.test, type="prob")

 result.roc2 <- roc(justviscfat.crp.test$Disease, result.predicted.prob2$UC)
</code>
From the CRAN pages for pROC https://cran.r-project.org/web/packages/pROC/pROC.pdf
<code>  # We need a plot to be ready
  plot(result.roc, type = "n") # but don't actually plot the curve
  # Add the line
  lines(result.roc, type="b", pch=21, col="cadetblue", bg="grey")
  # Add the line of an other ROC curve
  lines(result.roc2, type="o", pch=19, col="chocolate")
  legend("bottomright", legend=c("Metabolites + Visceral Fat + CRP-1", "Visceral Fat +
  CRP-1") ,col=c("cadetblue", "chocolate"), lwd=2)
</code>


How do I add a specific class in a row of a table output depending on a field content?

Question: I use the Views module to list the content of a custom entity, using the Table format.
I'd like to add the myClass CSS class to each row where a given field is equal to zero.
How can I achieve this?
Edit I found out that I could use 'Rewrite results' (Overriding the output of a field with custom text) with twig.
For example:
{% if nombreproduits == '0' %}
{{ '99/99/9999' }}
{% else %}
{{ datedistribution }}
{% endif %}

How could I use that to add a class to the corresponding row?
Answer: Finally, I made it work this way:
In Page>Format>Settings, I set 'Row class' to "myClass"~{{ nombreproduits }} where nombreproduits is the field to be checked equal to zero.
The result is something like
 in the corresponding rows (and, of course, myClass1, myClass2, etc. when nombreproduits = 1, 2 etc.).
Then, just have to add tr.myClass0to my custom CSS file...
Answer: Two options:

You alter your view with a View hook and you add to the row class value your own class based on one of the field value
You use this solution, and you can check with twig the actual row content and add a class based on that(use devel module and {{ kint(row) }} to understand how to reach the values you want)
Comment: Tried to use kint but, so far, without success. Will dig in...
Comment: Twig is heavily cached, you will have to turn that off, else you always will have to clear the cache with drush cr
Comment: By the way, I'm not sure to know where to put `{{ kint(row) }}`. In one field 'Rewrite results'? Elsewhere?
Comment: Well, you have a "for" loop {% for row in rows % }. You have to put it there. But you can try it anywhere to print out twig variables!


Does a density forecast add value beyond a point forecast when the loss function is given?

Question: Density forecasts are more universal than point forecasts; they provide information on the whole predicted distribution of a random variable rather than on a concrete function thereof (such as predicted mean, median, quantile, etc.). Availability of a density forecast allows different users pick out relevant elements -- point forecasts -- that are of their interest. Some users will focus on the predicted mean, others on the predicted median, etc., depending on the loss function by which the forecast is evaluated (and which may differ from user to user). Given a density forecast, every user's needs will be satisfied regardless of the loss function, because the density forecast contains all probabilistic information about the random variable.
However, if we have a concrete user in mind and know his/her loss function, then

Does the density forecast provide any added value over a point forecast tailored to the loss function?
If the answer is No in general, what are the conditions to make it a Yes?

P.S. @hejseb draws an interesting parallel between a point forecast tailored to the loss function and a sufficient statistic; perhaps this can inspire an answer.
Comment: @Glen_b, I will think more and try to explain better. Thank you for your input so far!
Comment: Thanks to @StephanKolassa's answer including counterexamples to my initial thoughts, I have expanded the question (added the second part).
Comment: How are you generating the density forecast?
Comment: @Glen_b, I have not thought of that. I hope the question makes sense for generic point and density forecasts. If not, could you suggest any concretization?
Comment: Well, for example, if the density forecast is obtained by basing it on the loss function (say where $L = -log(f)$ for some $f$, specified up to a scaling constant), then that would be quite different than if it was derived in some other way.
Comment: @Glen_b, Different in which way, with effects on what? I suppose this has to do with what precision/accuracy one can expect from a density forecast vs. a point forecast. Conceptually, this is not the most interesting point for me (though I might be missing its importance). I could be willing to assume that the density forecast is of approximately equal quality or inferior (due to its complexity) to point forecast, in the sense of user's loss due to forecast imprecision/inaccuracy.
Comment: I mean it would result in a different answer to the question
Comment: @Glen_b, sorry, I still do not understand. You seem to just state the fact but not explain how it arises.
Comment: minimizing the loss function would maximize the likelihood; anything else would not.
Comment: @Glen_b, OK, but the user does not care about the likelihood, the user cares about the loss he/she is about to incur. I was trying to get at it in [this](https://stats.stackexchange.com/questions/311417/estimator-that-is-optimal-under-all-sensible-loss-evaluation-functions) thread, and it was pointed out to me that an estimator that is optimal under all loss functions does not exist. Hence, we need to tailor estimators to loss functions. I presume the same holds for forecasts in place of estimators.
Comment: .... and we have cycled all the way back to "how are you generating the distribution for your forecasts?" ....
Comment: @Glen_b, I think now I see what you are getting at. But since we need to tailor forecasts to loss functions, I am conjecturing that a density forecast is irrelevant given a point forecast if the latter is tailored to the loss function, regardless of what the density forecast is tailored to. Does that make sense?
Comment: Your discussion appears to mirror the notion of a sufficient statistic to a large degree. I think it makes a lot of sense that you don't need the density (which collects all information) but just a (sufficient) summary of it if that's your aim. And just like sufficient statistics are different for different parameters precisely what summary of the density you need will vary.
Comment: @hejseb, thank you for a very interesting parallel. So, any ideas for an answer?
Comment: @Glen_b, regarding how I would generate the density forecast: I think I would tailor it to the loss function, that is only logical.
Comment: Okay, but *how*? I had planned to try to suggest some potential answers to your question but it's difficult to be explicit when the question is so vague with the details.
Comment: @Glen_b, The question is intentionally generic, though I understand some level of specificity is needed to make it answerable. The sources I have read (e.g. Elliott & Timmermann, 2016a) suggest that density forecasts are superfluous in presence of a known loss function, but they do not give the details. I presume this is correct and so the details should not be too difficult to work out. If you have an answer in mind, could you just lay out your assumptions and the answer itself? It would be easier to discuss then and it could help me formulate the question better if there is a need for that.
Comment: Surely it depends on the purposes of the forecasting. If I am an insurer forecasting liabilities, I'll be forecasting the mean (required in some jurisdictions -- so presumably by their lights I should use a quadratic loss in that case), but to make sure I have sufficient capital - perhaps I use calculations of VaR and TailVaR; that I have reinsurance arrangements that actually serve to improve my long term probability of ruin; or to find out the probability that I'll be able to pay a dividend to shareholders, then I need to know more than the mean. ... ctd
Comment: ctd...  Assuming I want all those purposes to be consistent (i.e. I don't want to use different sets of predictions that may not be consistent in what they tell me so that I don't end up concluding I have a high risk of failure, requiring more capital and stronger reinsurance arrangements  *and* concluding I can afford to pay a fat dividend.), then I'm interested in the distribution of future liability (spread, tail heaviness etc), not just the mean. Without context for the claim, the question seems impossibly broad. I don't see how it could possibly be a reasonable claim in general.
Comment: @Glen_b, All of that just defines your loss function. Once it is defined, you can find a point forecast that will suggest the same action as a density forecast. The remaining question is, can you solve for the point forecast without knowing the form of the density (this holds, for example, under square loss), or do you have to model the density first. For example, under square loss a density forecast that puts a point mass at the mean will be optimal, and of course it coincides with the optimal point forecast. Hence, there is no need for a density forecast there, given a point forecast.
Comment: How can a single point forecast simultaneously tell me my mean reserve, the 99% VaR the 99.5% TailVar, and the effect of my reinsurance on the probability of my future solvency?
Comment: @Glen_b, They cannot, but why would you need that? All of these things are combined into one via the loss function (which is scalar valued), so you only need to know the combination to determine which action (or equivalently, which point forecast) will bring you the smallest loss. I think I have figured it out. The question can be split into two parts: (1) Does a perfect density forecast have added value over a perfect point forecast under particular loss? and (2) What is the effect of forecasts being imperfect? I think the answer to (1) (which seems to be the more confusing part) is "No".
Comment: ...ctd: (At least in "well-behaved" situations.) The answer to (2) has been indicated in my answer below and suggests the advantage of point forecasts over density forecasts when it comes to coming up with actual (imperfect) forecasts.
Comment: I must be missing something -- I'm afraid I don't follow the first part of your response above at all. The issue I was getting at is that in practice forecasts have multiple uses and a distribution of future values can address all of them, but I don't see how a scalar forecast does so. Of course if you're allowing a vector of quantities of interest to be forecast, you might well ask "why forecast the whole distribution when you're just using it to produce these quantities?"
Answer: I can think of one-and-a-half more or less realistic situations where a full density is better than a point forecast, even if the loss function is known.

The nitpicky situation is the one where the user's loss function depends not only on the point forecast, but on a two-sided prediction-interval, or even the entire density, i.e., the loss function is a scoring-rules.
Yes, a loss function is typically defined to depend on a single point forecast, so I'm loose with nomenclature here. Nevertheless situations like these do occur, e.g., in financial volatility forecasting. Or where I work, in retail replenishment forecasting: we may want to achieve a 95% service level, so on the face of it, we may only be interested in that (point) quantile forecast. However, a 95% quantile forecast may be 4, while we may be constrained to replenish in pack sizes of 8. In such a situation, it can be valuable to know what percentage 8 units correspond to.

The more relevant situation is one where we are interested in functions of predictive densities. Again, consider retail forecasting: because of the delivery schedule, our replenishment order may need to cover three days, Tuesday to Thursday. However, we forecast on daily granularity. So we may be interested in the 95% quantile forecast of the sum of the demands, and for the convolution, we need the full densities. (We could also try to forecast on three-day bucket granularity, but that becomes problematic if, say, a promotion starts in the middle of the bucket.)
Comment: Thank you for your answer. I am thinking in decision-theoretic terms as follows. A user chooses an action to maximize expected utility (negative expected loss). The choice is based on the forecast. Given a density forecast, a user can calculate the expected utility of a particular action by integrating utility of that action over the predicted density of the outcome. Then he/she chooses the action (among all possible ones) that maximizes this expected utility. If the utility function has a unique maximum (loss function has a unique minimum), the optimal action is unique.
Comment: Crucially, there exists a point in the outcome distribution that yields exactly the same expected utility as above, and that point defines the target of the "relevant" point forecast. Hence, the user will get exactly the same maximized (over all possible actions) expected utility regardless of whether the forecast he gets is a density forecast or the "relevant" point forecast, provided the quality of the two forecasts is "equally good". Does any of your examples violate this?
Comment: Perhaps your example of [an action based on] a prediction interval is a valid counterexample, though I doubt it (based on the decision-theoretic viewpoint above)... I wonder then how I could qualify the statement in the OP (add some condition to it) to make the answer "a density forecast has no added value" correct. Of course, this is not to invalidate your answer, but just for my own sake to understand the situation better. Regarding scoring rules, it would also be interesting to get an example where a scoring rule makes intuitive sense as a loss function for a particular user. (+1)
Comment: Actually, a similar argument applies to interval forecasts as to density forecasts. The argumentation in my answer suggests that for a given loss function, a interval forecast will not have added value beyond a relevant point forecast. Regarding loss functions depending on forecasts, this is possible when a user tailors his/her actions to the forecast, but an interval or density forecast can be replaced by a relevant point forecast, and the loss function would be formulated on the point forecast.
Comment: I mean the loss inevitably depends on the outcome but not necessarily on an interval or density forecast if the latter can be replaced by a point forecast. The outcome is a fundamental argument to the loss function, but the type of forecast is not if the user is allowed to choose between different types of forecasts (point vs. interval vs. density). Hence your first example is not a valid counterexample. Your second example does not seem to be valid either since as you say, we could also try to forecast on three-day bucket granularity.
Comment: Regarding my first example: I agree that we can simply forecast the profit or loss from each (here: discrete) potential action (replenish 0 packs of 8, replenish 1 pack, replenish 2 packs etc.). Insofar, you are correct.
Answer: Background (may be skipped)
I will be thinking in decision-theoretic terms as follows. A user must choose an action $a$ among a set of possibilities $A$. The action will bring him/her some "utility" (a notion commonly used in economics) $u(a;s)$ depending on the state of nature $s$ that will be realized in the future, where $s \in S$, a set of all possible states. (Utility is basically the negative of loss, and what follows could be reformulated equivalently either in terms of utility or loss.) The user aims at maximizing the expected utility (or equivalently, minimizing the expected loss) w.r.t. the action,
$$
\max_{a \in A} \mathbb{E}_{S} u(a;s).
$$
The choice of action is based on the forecast of the state of nature to be realized. Given a density forecast $\hat f_S(\cdot)$, a user can calculate the expected utility of a particular action by integrating the utility of that action over the predicted distribution of the states of nature,
$$
\mathbb{E}_{\hat S} u(a;s) = \int u(a;s) \hat f_S(s) ds.
$$
Then he/she chooses the action (among all possible ones) that maximizes this expected utility, $\hat a^* := \arg\max_{a \in A} \mathbb{E}_{\hat S} u(a;s)$. The expected value of utility at this action, for this density forecast is $\hat u^*:=u(\hat a^*)$.
If the utility function has a unique maximum (loss function has a unique minimum), the optimal action is unique. If the state of nature is a continuous random variable, there exists a point in the distribution (a state of nature) that yields exactly  $\hat u^*$. That point defines the target of the "relevant" point forecast. Hence, the user will get exactly the same maximized (over all possible actions) expected utility regardless of whether the forecast he gets is a density forecast or the "relevant" point forecast (a unit probability mass on a certain state of nature), provided the quality of the two forecasts is "equally good" (the easiest to intuitively understand the latter is to consider the case where both the point and the density forecast are perfect).
Main part (see background for more details)
I think it is reasonable to assume that the usefulness of a forecast is fully reflected by the loss it incurs to a given user. Then the aim of a user is to choose a forecast that minimizes the expected loss. Hence, given a predicted distribution, the user will take a concrete function thereof (e.g. predicted mean) that minimizes the expected loss. The rest of the predicted density will not have any added value to the user.
If the loss function has a unique minimum, the function will be single-valued, and that value will be the point forecast relevant for the user. For example, if the user's loss function is quadratic (which has a unique minimum at the mean of the true distribution), he/she will only care about the forecast of the mean. If another user is facing absolute loss (which has a unique minimum at the median of the true distribution), he/she will only care about the forecast of the median. Providing a density forecast for either of these users in addition to forecasts of mean and median, respectively, will be of zero added value to them.
Elliott and Timmermann (2016a) write on p. 423-424 (regarding evaluation of density forecasts):

One way to [evalute a density forecast] would be to convert the density forecast into a point forecast and use the methods for point forecast evaluation. This simple approach to evaluating density forecasts might be appropriate for a number of reasons. <...> [D]ensity forecasts can be justified on the grounds that there are multiple users with different loss functions. Any one of these users might examine the performance of a density forecast with reference to the specific loss function deemed appropriate for their problem. The relevant measure of forecast performance is the average loss calculated from each user's specific loss function.

Moreover, given a known loss function, a density forecast may even be inferior to a relevant point forecast, for the following two reasons. First, density forecasts are typically more difficult to produce than point forecasts. Second, they might trade off precision/accuracy at a particular point (say, mean or median) for precision/accuracy across the whole distribution that is being predicted. That is, if one is predicting the whole density, one might have to sacrifice some precision/accuracy for the forecast of the mean so as to get greater precision/accuracy elsewhere. As Elliott and Timmermann (2016b) write,

[T]he relationships between the scoring rules popular in the literature and the underlying loss functions for individual users is not clear. Thus, it could well be that the scoring rule used provides a poor estimate of the feature of the conditional distribution that some users wish to construct.

A similar quote can be found in Elliott and Timmermann (2016a), p. 277-278:

It would seem that provision of a predictive density is superior to reporting a point forecast since it both (a) can be combined with a loss function to produce any point forecast; and (b) is independent of the loss function. In classical estimation of the predictive density, neither of these points really holds up in practice. <...> [I]n the classical setting the estimated predictive distributions depend on the loss function. All parameters of the predictive density need to be estimated and these estimates require some loss function, so loss functions are thrown back into the mix. The catch here is that the loss functions that are often employed in density estimation do not line up with those employed for point forecasting which can lead to inferior point forecasts. <...> Moreover, conditional distributions are difficult to estimate well, and so point forecasts based on estimates of the conditional density may be highly suboptimal from an estimation perspective.

Hence, when a loss function is given, it might make sense to focus on forecasting the particular point tailored to the loss function rather than attempt to forecast the whole distribution. This might be easier to do and/or more accurate.
A critical question to myself: may it be that the "relevant" point forecast cannot be expressed as a function of the unknown density but rather be different (as a function, not just its value) for different densities? Then a density forecast would be needed to find out which point forecast one is interested in, making a density forecast an inevitable step in the point forecasting process.
References:

Elliott, G., & Timmermann, A. (2016a). Economic forecasting. Princeton: Princeton University Press.
Elliott, G., & Timmermann, A. (2016b). Forecasting in economics and finance. Annual Review of Economics, 8, 81-110.
Comment: Another relevant reference is Granger and Machina (2006). According to Hall & Mitchell's chapter 5 on density forecasting in Patterson & Mills (editors) "Palgrave Handbook of Econometrics" (2009), they *show that, under conditions on the second derivative of the loss function, there is always some point forecast which leads to the same loss as if the decision maker had minimized loss given the density forecast.* Given more time, this could be incorporated in the answer.


Como eu posso chamar um método void da classe para mostrar uma mensagem em um formulário?

Question: Tenho um método public void listarProduto(). Ele precisa ter todas as informações de entrada pelo usuário. O meu problema está na hora de chamar esse método dentro de um MessageBox() no formulário para que a mensagem seja exibida.
Comment: Se você estiver tentando acessar o método sem uma instância, coloque public static void listarProduto() e veja se funciona
Comment: obrigatoriamente tem que ser void ?
Comment: Void define que o método não tem retorno. Você quer retornar algo ? um int ? uma string ?
Comment: Mostre o seu código, e alertando métodos `void` não tem retorno.
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).
Comment: Você pode postar o código do que você está tentando fazer? Porque você quer chamar um método `void` dentro de um `MessageBox`? Porque não chamá-lo antes ou depois?
Answer: Não é possível, pelo menos se entendi a colocação. Se o método faz algo mas não resulta em nada ele não pode ser usado como expressão em um lugar que espera alguma informação, método de retorno void só podem ser chamados como statement.
Ou deve modificar o método para retornar o que deseja usar no MessageBox() ou deve pegar outra informação em algum lugar se ela estiver disponível.
Provavelmente há um erro neste método, porque se ele lista alguma coisa mesmo, ou seja, se é algo de tela, ele já faz o que deveria e não precisa passar isso para o MessageBox(), provavelmente deveria ter um `MessageBox() dentro dele mostrando o que deseja.
Por outro lado o mais provável é que ele só entregue os dados do produto para fazer o que deseja, aí deveria retornar um objeto ou uma string, ou seja, ele não deveria tratar da tela, são responsabilidades diferentes.
Answer: Do jeito que você tá falando, acho que seria o contrário, o jeito seria chamar o método e executar a chamada do MessageBox() dentro desse método.


How are both of these true: $J = \nabla f ^T $, and also $\nabla f = J^T f$?

Question: From questions such as this one: Gradient and Jacobian row and column conventions I understand that for cases where $f$ maps from $\mathbb{R}^n$ into $\mathbb{R}$ , i.e. $f: \mathbb{R}^n \rightarrow \mathbb{R}$,  the transpose of the gradient is equal to the jacobian:  $J = \nabla f ^T $.  Again, see Gradient and Jacobian row and column conventions as my resource.
However, I am still occasionally confused by this, because when finding an expression of the gradient for when $f: \mathbb{R}^n \rightarrow \mathbb{R}^m$ I see expressions such as $\nabla f = J^T f$.   An example of this is in Nocedal and Wright, first edition on page 260:

Question is how are both of these true:  $J = \nabla f ^T $, and also $\nabla f = J^T f$ ?
Answer: They can both be true because the $f's$ and corresponding Jacobians are different. Nonlinear least squares has its own notation and conventions for what the Jacobian is (is applied to, namely to residual functions which are squared and summed and multiplied by 1/2).
I am looking at the 2nd edition of Nocedal and Wright, whereas you must apparently be looking at the 1st edition. Perhaps there is a typo in that ediition uding f where there should have been an r (see next paragraph).
In the Nocedal and Wright extract pertaining to a nonlinear least squares problem, f = 1/2 of sum squared residuals = $\frac{1}{2}\Sigma_{i=1}^nr_i^2$, where $r_i$ are the individual residual functions. The Jacobian J, in this nonlinear least squares context, is the matrix of partial derivatives of $r_i$ with respect to variable $x_j$, o.e., the ith row of $J$ is the transpose of the gradient of $r_i$. Then it works out that gradient of f = $J^Tr$, where $r = $ column vector of $r_i's$   So this is true under these definitions and conventions, which differ from life outside nonlinear least squares.
Comment: @jaja There are n variables (components of $x$) to solve for. There are m data points, for each of which there is a component of the residual vector $r$, which is $m$ by by $1$.  The objective function $f: \mathbb{R}^n \rightarrow \mathbb{R}$.  The jacobian $J$ is $m$ by $n$. So $J^Tr$ is an $n$ by $m$ matrix times an $m$ by $1$ vector, which results in an $n$ by $1$ vector, which is the gradient of $f$ with respect to its $n$ variables. All dimensions are entirely consistent.
Comment: Even so, if $f=J^Tr$, I still do not understand how the dimensions will work out for that.  $r$ has the same domain and codomain as $f$, right? i.e. $r: \mathbb{R}^n \rightarrow \mathbb{R}$, so I still do not see how this will work.
Answer: If $A=B^T$, then $B=A^T$. It is simply a consequence of the fact that ${\left(A^T\right)}^T=A$.
Comment: Indeed. Well, for starters, if $m>1$, then $f$ does not have a gradient. A gradient is defined for scalar functions.
Comment: I think perhaps you misread the question
Answer: First, let's clarify the notation first. To be precise, the notation for Jacobian of $f$ is $J_f$, and the notation for the gradient is $\nabla f^T$.
Then, regarding $f=(f_1,\dots,f_m)=f(x)=(f_1(x), \dots, f_m(x))$ as a $m$-dimensional coloum vector,
$$
J_f =
\begin{bmatrix}
\nabla f_1^T \\
\cdots \\
\nabla f_m^T
\end{bmatrix}
$$
where each $\nabla f_i$ is a column vector that consist of partial derivatives in the conventional way.
On the other hand, to consistently interpret $\nabla f^T$, first regard $f^T$ as a row vector $f^T = [f_1, \dots, f_m]$. Then,
$$
\nabla f^T = [\nabla f_1, \dots, \nabla f_m].
$$
What we really have is $J_f^T = \nabla f^T$ and $J_f = (\nabla f^T)^T$.
$\nabla f$ cannot be defeind in a consistent way onece we regard $f$ as a column vector and $\nabla$ as an operation applied to a scalr function to produce a column vector.


Can I use TLS with the domain name automatically assigned by an ELB?

Question: When setting up an ELB, a subdomain is automatically provisioned (something like some-junk-here.us-west-2.elb.amazonaws.com). For my use-case this ugly domain is fine, and it works for raw HTTP and TCP connections, but we'd like to enable TLS. Is there a way to use TLS without setting up a custom domain? I think this would work by having the ELB use an Amazon-provided wildcard cert to unwrap TLS connections, and proxy the bare connection to my EC2 instance (I believe this is what  services like Heroku, ngrok etc do)
Just connecting over HTTPS (or a TLS-wrapped TCP connection) doesn't seem to work by default, and I haven't found any documentation about this (everything I've seen to do with TLS involves adding my own domain and cert)
Thanks!
Answer: This won't work.  A TLS certificate provides two things: keys for setting up encryption and an assurance that the server is not an impostor and is authorized to serve requests for the given domain.  Obtaining such a cert requires you to own or control the domain, but amazonaws.com isn't yours.  This is why all the examples involve a custom domain.  The hostname of an AWS load balancer is there to give you a DNS target that isn't an IP address, something to point your domain to in DNS, because the IP addressss of load balancers will change over time due ro scaling, failures, or upgrades.
You can create your own self-signed certificates or even your own private certificate authority using openssl (or easyrsa, a wrapper for openssl) and if your clients are such that you can update their trust stores, but the simplest solution is just get a domain, or create a subdomain from one you already have.  The domain doesn't technically even have to be hosted in Route 53.  Then get the cert from Amazon Certificate Manager, which is free.
Comment: Yes, I understand that Amazon isn't going to give me their certs, but could they not unwrap a TLS connection using that cert for me? My understanding is that a number of other services that provide their users TLS on dynamic subdomains (eg https://yourapp.herokuapp.com) do this by having a wildcard cert that they use to unwrap the incoming connection, and then pass the unencrypted traffic on to your app. Couldn't AWS do the same thing? Or are you just saying that they _could_ but choose not to?
Comment: Yes, that's right.  They technically *could* furnish a wildcard cert -- they do this on `*.s3.amazonaws.com` and `*.cloudfront.net` -- but they don't do this for ELBs.  And since they are the only ones who could, it isn't otherwise possible.  Let's Encrypt, for example, has specific rules that prevent them from generating certs for anything in the amazonaws.com domain, even though http nonce validation would technically work fine.


getting ipv6 via radvd/dhcpd6 in an LXC guest working

Question: what i want
my setup has a dynamic amount of LXC containers and therefore i need some dynamic ipv6 address allocation. the interface brNC-internet is a simple bridge which is mapped into the LXC based container.
i need a way to assign ipv6 addresses in LXC containers to the internet interface of each. manually doing so works, as shown below but this should be automated using dhcpd6 (or something similar).
i'd love to try:

stateful dhcp: where a client is reassigned the same address when rebooted within some time limit (days, weeks)
stateless dhcp: a client gets just any address for the time it is up

note: i can't use radvd with SLAAC because my network prefix is /66 and radvd requires at least a /64 for this, see this.
note: i'd like to focus on ipv6 for the moment.
note: i'm using nixos linux and i did probably just configure something wrongly, have a firewall rule which breaks things or a general misunderstanding about ipv6 or even some LXC specific internal. in either case, please point out what i could be trying next.
my problem
i've setup radvd and dhcpd6 on the host (a VM) but while radvd is able to push a ipv6 default gateway and a prefix the client never seems to talk to the dhcpd6 server using dhcpcd from the client.
if i disable the dhcpcd client on the guest LXC instance i can assign a ipv6 address within the prefix and ping6 to google works:
[root@10:/]# ip a replace 2a01:4f8:221:3744:4000::4 dev internet

[root@10:/]# ping -6 -I internet 2a00:1450:4001:80b::2003
PING 2a00:1450:4001:80b::2003(2a00:1450:4001:80b::2003) from fe80::10af:ffff:fef4:318a internet: 56 data bytes
From fe80::2044:c6ff:fef3:cd5d%internet icmp_seq=1 Destination unreachable: Beyond scope of source address
64 bytes from 2a00:1450:4001:80b::2003: icmp_seq=2 ttl=55 time=5.36 ms
64 bytes from 2a00:1450:4001:80b::2003: icmp_seq=3 ttl=55 time=5.26 ms
64 bytes from 2a00:1450:4001:80b::2003: icmp_seq=4 ttl=55 time=5.27 ms

i've also tried to disable the firewalls on both host and LXC client but no change.
dhcpcd from lxc
dhcpcd -6  --config /nix/store/7n7ysqf92rlafihs9dm2gzsbh06cw64z-dhcpcd.conf
DUID 00:01:00:01:22:4f:af:36:ee:ae:40:b5:d7:d3
internet: IAID 98:0e:c7:c8
internet: soliciting an IPv6 router
internet: Router Advertisement from fe80::2044:c6ff:fef3:cd5d
forked to background, child pid 1238

tcpdump on the VM
tcpdump -i brNC-internet ip6

14:36:18.618554 IP6 fe80::dc5d:98ff:fe0e:c7c8 > ff02::2: ICMP6, router solicitation, length 16
14:36:18.618681 IP6 status.nixcloud.io > fe80::dc5d:98ff:fe0e:c7c8: ICMP6, router advertisement, length 112
14:36:20.578582 IP6 status.nixcloud.io > ff02::1: ICMP6, router advertisement, length 112
14:36:24.059514 IP6 status.nixcloud.io > fe80::dc5d:98ff:fe0e:c7c8: ICMP6, neighbor solicitation, who has fe80::dc5d:98ff:fe0e:c7c8, length 32
14:36:24.059598 IP6 fe80::dc5d:98ff:fe0e:c7c8 > status.nixcloud.io: ICMP6, neighbor advertisement, tgt is fe80::dc5d:98ff:fe0e:c7c8, length 24

dhcpd6 log on the vm
journalctl -u dhcpd6 -f
-- Logs begin at Tue 2018-02-13 02:31:51 CET. --
Mar 30 14:00:08 status.nixcloud.io dhcpd[17605]: Wrote 0 NA, 0 TA, 0 PD leases to lease file.
Mar 30 14:00:08 status.nixcloud.io dhcpd6[17605]: Bound to *:547
Mar 30 14:00:08 status.nixcloud.io dhcpd[17605]: Bound to *:547
Mar 30 14:00:08 status.nixcloud.io dhcpd[17605]: Listening on Socket/5/brNC-internet/2a01:4f8:221:3744:4000::/66
Mar 30 14:00:08 status.nixcloud.io dhcpd[17605]: Sending on   Socket/5/brNC-internet/2a01:4f8:221:3744:4000::/66
Mar 30 14:00:08 status.nixcloud.io dhcpd6[17605]: Listening on Socket/5/brNC-internet/2a01:4f8:221:3744:4000::/66
Mar 30 14:00:08 status.nixcloud.io dhcpd6[17605]: Sending on   Socket/5/brNC-internet/2a01:4f8:221:3744:4000::/66
Mar 30 14:00:08 status.nixcloud.io systemd[1]: dhcpd6.service: Can't open PID file /run/dhcpd6/dhcpd.pid (yet?) after start: No such file or directory
Mar 30 14:00:08 status.nixcloud.io dhcpd6[17615]: Server starting service.
Mar 30 14:00:08 status.nixcloud.io systemd[1]: Started DHCPv6 server.

my setup
host vm
ip -6 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 state UNKNOWN qlen 1000
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 2a01:4f8:221:3744::1:26/128 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fefb:d8d0/64 scope link
       valid_lft forever preferred_lft forever
3: enp0s2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 fe80::5054:ff:fe08:4db9/64 scope link
       valid_lft forever preferred_lft forever
4: brNC-hostonly: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 fe80::5880:6aff:fe77:cd16/64 scope link
       valid_lft forever preferred_lft forever
5: brNC-internet: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 2a01:4f8:221:3744:4000::2/128 scope global
       valid_lft forever preferred_lft forever
    inet6 fc00::261/128 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::2044:c6ff:fef3:cd5d/64 scope link
       valid_lft forever preferred_lft forever
121: vethVIEF2K@if120: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 fe80::fc55:8fff:fe5d:a50a/64 scope link
       valid_lft forever preferred_lft forever
123: vethPIKVFW@if122: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 fe80::fc4f:adff:fe61:180b/64 scope link
       valid_lft forever preferred_lft forever
133: vethC387B7@if132: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 fe80::fc5c:16ff:fe64:444b/64 scope link
       valid_lft forever preferred_lft forever
135: vethE0I0FG@if134: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 fe80::fcbf:d4ff:fe33:a9d0/64 scope link
       valid_lft forever preferred_lft forever

ip -6 r
2a01:4f8:221:3744::1:26 dev enp0s3 proto kernel metric 256 pref medium
2a01:4f8:221:3744:4000::2 dev brNC-internet proto kernel metric 256 pref medium
2a01:4f8:221:3744:4000::/66 dev brNC-internet proto kernel metric 256 expires 9700sec pref medium
fc00::26 dev enp0s3 metric 1024 pref medium
fc00::261 dev brNC-internet proto kernel metric 256 pref medium
fe80::/64 dev enp0s3 proto kernel metric 256 pref medium
fe80::/64 dev brNC-hostonly proto kernel metric 256 pref medium
fe80::/64 dev brNC-internet proto kernel metric 256 pref medium
fe80::/64 dev enp0s2 proto kernel metric 256 pref medium
fe80::/64 dev vethVIEF2K proto kernel metric 256 pref medium
fe80::/64 dev vethPIKVFW proto kernel metric 256 pref medium
fe80::/64 dev vethE0I0FG proto kernel metric 256 pref medium
fe80::/64 dev vethC387B7 proto kernel metric 256 pref medium
default via fc00::26 dev enp0s3 metric 1024 pref medium

dhcpd configuration
cat /nix/store/5zvcjwvlj9n7cvrppkw1mxsxwhxwx3cm-dhcpd.conf
default-lease-time 600;
max-lease-time 7200;
authoritative;
ddns-update-style interim;
log-facility local1; # see dhcpd.nix

subnet6 2a01:4f8:221:3744:4000::/66 {
  #range6 2a01:4f8:221:3744:4000::/66 temporary;
  option dhcp6.name-servers 2a01:4f8:0:1::add:1010, 2a01:4f8:0:1::add:9999, 2a01:4f8:0:1::add:9898;
}

radvd configuration
cat /nix/store/89j6hg4qhnd9nyijf9p2dcr4f5ygjz6r-radvd.conf
interface brNC-internet {
  AdvSendAdvert on;
  MinRtrAdvInterval 3;
  MaxRtrAdvInterval 10;
  prefix 2a01:4f8:221:3744:4000::/66 {
    AdvOnLink on;
    AdvAutonomous off;
  };
  RDNSS 2a01:4f8:0:1::add:1010 2a01:4f8:0:1::add:9999 2a01:4f8:0:1::add:9898 { };
};

guest LXC
[root@10:/]# ip -6 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 state UNKNOWN qlen 1000
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
132: hostonly@if133: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 fe80::484f:50ff:fe0c:fa62/64 scope link
       valid_lft forever preferred_lft forever
134: internet@if135: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 2a01:4f8:221:3744:4000::4/128 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::10af:ffff:fef4:318a/64 scope link
       valid_lft forever preferred_lft forever

[root@10:/]# ip -6 r
2a01:4f8:221:3744:4000::4 dev internet proto kernel metric 256 pref medium
2a01:4f8:221:3744:4000::/66 dev internet proto kernel metric 256 expires 86395sec pref medium
fe80::/64 dev hostonly proto kernel metric 256 pref medium
fe80::/64 dev internet proto kernel metric 256 pref medium
default via fe80::2044:c6ff:fef3:cd5d dev internet proto ra metric 1024 expires 25sec hoplimit 64 pref medium

lxc config
lxc.uts.name = 10

# Fixme also support other architectures?
lxc.arch = x86_64
# Not needed, just makes spares a few cpu cycles as LXC doesn't have
# to detect the backend.
#lxc.rootfs.backend = dir
lxc.rootfs.path = /var/lib/lxc/10/rootfs
lxc.init.cmd = /init/container/init
#lxc.rootfs = /var/lib/lxc/10/rootfs

# Ensures correct functionality with user namespaces. Since mknod is not possible stuff like
# /dev/console, /dev/tty, /dev/urandom, etc. need to be bind mounted. Note the order
# of the file inclusion here is important.
lxc.include = /nix/store/3hz7xkd86pzrvr4z53fa079q61qar02x-lxc-2.1.1/share/lxc/config/common.conf
lxc.include = /nix/store/3hz7xkd86pzrvr4z53fa079q61qar02x-lxc-2.1.1/share/lxc/config/userns.conf

## Network
# see also https://wiki.archlinux.org/index.php/Linux_Containers
lxc.net.0.type = veth
lxc.net.0.name = hostonly
#lxc.net.0.ipv4.address = 10.101.0.63 (we assign this using nix, not from lxc)
lxc.net.0.flags = up
lxc.net.0.link = brNC-hostonly

lxc.net.1.type = veth
lxc.net.1.name = internet
lxc.net.1.flags = up
lxc.net.1.link = brNC-internet

# Specifiy {u,g}id mapping.
lxc.idmap = u 0 100000 65536
lxc.idmap = g 0 100000 65536

# FIXME apparmor support
# Nixos does not provide AppArmor support.
#lxc.aa_profile = unconfined
#lxc.aa_allow_incomplete = 1
lxc.apparmor.profile = unconfined
lxc.apparmor.allow_incomplete = 1

# Tweaks for systemd.
lxc.autodev = 1

# Additional mount entries.
lxc.mount.entry = /nix/store nix/store none defaults,bind.ro 0.0
lxc.mount.entry = /nix/var/nix/profiles/nixcloud-container-10 init none defaults,bind.ro 0 0

# Mount entries that lead to a cleaner boot experience.
lxc.mount.entry = /sys/kernel/debug sys/kernel/debug none bind,optional 0 0
lxc.mount.entry = /sys/kernel/security sys/kernel/security none bind,optional 0 0
lxc.mount.entry = /sys/fs/pstore sys/fs/pstore none bind,optional 0 0
lxc.mount.entry = mqueue dev/mqueue mqueue rw,relatime,create=dir,optional 0 0

# LXC autostart
lxc.start.auto = 0

lxc.rootfs.path = dir:/var/lib/lxc/10/rootfs

Answer: ok, here we go:
after 3 full days of trying different configurations, reading about 40 webpages and a hell of luck, here is how i got it working:

needed a special dhcpcd.conf (default won't work)
needed a special dhcpd6.conf (default won't work either)
needed a special radvd.conf  (there was no default)
and only with the nixos firewall disabled (will post the rules modification when i found out what needs to be done) -> systemctl stop firewall

the missing firewall rules in the nixos firewall were those:
ip6tables -A INPUT -p tcp -m tcp -m multiport -i brNC-internet -j ACCEPT --dports 546,547
ip6tables -A INPUT -p udp -m udp -m multiport -i brNC-internet -j ACCEPT --dports 546,547

summary: the state of ipv6 documentation, ipv6 default configurations (in ubuntu server) and best practices guides is a shame and shows once more why ipv6 it is not deployed on more sites and with that i mean servers (not even talking about client configurations as laptops or mobile devices here).
my current setup deploys the ipv6 gateway via radvd and assigns ipv6 addresses using dhcpd6 in parallel as SLAAC can't be used in my setup as my prefix is /66 and needs to be (/64, /63, ..., a smaller number than 64). see http://www.teaparty.net/technotes/home-ipv6.html (section radvd) for more details.
note on dhclient: oh, and unlike dhcpcd which requires a very special configuration to work using dhclient on my ubuntu test machines i got a lease without any modification to the dhclient configuration. this is a huge plus compared to the dhcpcd implementation.
documentation
note on documentations and blogs: thanks so much to sixxs.net and the authors of these webpages. without your great work i couldn't have made it!

https://www.sixxs.net/wiki/Configuring_ISC_DHCPv6_Server
https://blog.cepharum.de/en/post/lxc-host-featuring-ipv6-connectivity.html
http://sophiedogg.com/radvd-and-dhcpd6-server-configuration-for-dynamic-dns/
https://k3a.me/setting-up-ipv6-using-a-dhcp-client/

radvd configuration
  interface brNC-internet {
    AdvSendAdvert on;
    MinRtrAdvInterval 3;
    MaxRtrAdvInterval 10;
    #prefix 2a01:4f8:221:3744:4000::/66 {
    #  AdvOnLink on;
    #  AdvAutonomous off;
    #};
    #RDNSS 2a01:4f8:0:1::add:1010 2a01:4f8:0:1::add:9999 2a01:4f8:0:1::add:9898 { };

dhcpcd output
[root@11:~]# dhcpcd --config /root/dhcpcd6.conf
DUID 00:01:00:01:22:52:a7:e3:0a:79:bb:c7:9c:d6
internet: IAID fc:bf:59:37
internet: IAID 00:00:00:01
internet: confirming prior DHCPv6 lease
internet: REPLY6 received from fe80::e4d2:fbff:feab:81dd
internet: adding address 2a01:4f8:221:3744:4000::300/128
internet: renew in 40000, rebind in 64000, expire in 86400 seconds
forked to background, child pid 12363

dhcpcd.conf (client configuration)
# Inform the DHCP server of our hostname for DDNS.
hostname

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# options to request from the DHCP
option domain_name_servers, interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# only configure ipv6
ipv6only

# disable routing solicitation
noipv6rs

# don't touch these interfaces at all
denyinterfaces hostonly

interface internet
 # enable routing solicitation get the default IPv6 route
 #ipv6rs
 # request a normal (IA_NA) IPv6 address with IAID 1
 ia_na 1

dhcpd6 configuration
  services.dhcpd6 = {
    enable = true;
    interfaces = [ "brNC-internet" ];
    extraConfig = ''
      ddns-update-style interim;
      ddns-updates on;
      ddns-domainname "your.domain.com";
      ddns-rev-domainname "ip6.arpa";
      allow client-updates;
      update-conflict-detection false;
      update-optimization false;
      authoritative;
      option domain-name-servers dns.your.domain.com;
      default-lease-time 86400;
      preferred-lifetime 80000;
      allow leasequery;
      option dhcp6.name-servers 2001:0db8:edfa:1234::1;
      option dhcp6.domain-search "your.domain.com","domain.com";
      #include "/etc/rndc.key";
      option dhcp6.preference 255;

      subnet6 2a01:4f8:221:3744:4000::/66 {
        #range6 2a01:4f8:221:3744:4000::/66 temporary;
        range6 2a01:4f8:221:3744:4000::129 2a01:4f8:221:3744:4000::300;
        option dhcp6.name-servers 2a01:4f8:0:1::add:1010, 2a01:4f8:0:1::add:9999, 2a01:4f8:0:1::add:9898;
        # option dhcp6.gateway 2001:db8:2:3::1;
      }
    '';
  };

tcpdump output
tcpdump -i brNC-internet ip6
13:47:01.854794 IP6 fe80::d4e8:fcff:febf:5937 > status.nixcloud.io: ICMP6, neighbor solicitation, who has status.nixcloud.io, length 32
13:47:01.854827 IP6 status.nixcloud.io > fe80::d4e8:fcff:febf:5937: ICMP6, neighbor advertisement, tgt is status.nixcloud.io, length 24
13:47:05.649860 IP6 status.nixcloud.io > ff02::1: ICMP6, router advertisement, length 24
13:47:06.772849 IP6 fe80::d4e8:fcff:febf:5937.dhcpv6-client > ff02::1:2.dhcpv6-server: dhcp6 solicit
13:47:06.773021 IP6 status.nixcloud.io.dhcpv6-server > fe80::d4e8:fcff:febf:5937.dhcpv6-client: dhcp6 advertise
13:47:06.773344 IP6 fe80::d4e8:fcff:febf:5937.dhcpv6-client > ff02::1:2.dhcpv6-server: dhcp6 request
13:47:06.774004 IP6 status.nixcloud.io.dhcpv6-server > fe80::d4e8:fcff:febf:5937.dhcpv6-client: dhcp6 reply
13:47:06.777782 IP6 fe80::d4e8:fcff:febf:5937 > ff02::16: HBH ICMP6, multicast listener report v2, 2 group record(s), length 48
13:47:07.071788 IP6 fe80::d4e8:fcff:febf:5937 > ff02::16: HBH ICMP6, multicast listener report v2, 2 group record(s), length 48
13:47:07.423792 IP6 :: > ff02::1:ff00:300: ICMP6, neighbor solicitation, who has 2a01:4f8:221:3744:4000::300, length 32

dhcpd6 log
Apr 01 13:35:41 status.nixcloud.io dhcpd6[9225]: Copyright 2004-2016 Internet Systems Consortium.
Apr 01 13:35:41 status.nixcloud.io dhcpd6[9225]: All rights reserved.
Apr 01 13:35:41 status.nixcloud.io dhcpd6[9225]: For info, please visit https://www.isc.org/software/dhcp/
Apr 01 13:35:41 status.nixcloud.io dhcpd6[9225]: Wrote 0 NA, 0 TA, 0 PD leases to lease file.
Apr 01 13:35:41 status.nixcloud.io dhcpd[9225]: Wrote 0 NA, 0 TA, 0 PD leases to lease file.
Apr 01 13:35:42 status.nixcloud.io dhcpd6[9225]: Bound to *:547
Apr 01 13:35:42 status.nixcloud.io dhcpd[9225]: Bound to *:547
Apr 01 13:35:42 status.nixcloud.io dhcpd[9225]: Listening on Socket/5/brNC-internet/2a01:4f8:221:3744:4000::/66
Apr 01 13:35:42 status.nixcloud.io dhcpd[9225]: Sending on   Socket/5/brNC-internet/2a01:4f8:221:3744:4000::/66
Apr 01 13:35:42 status.nixcloud.io dhcpd6[9225]: Listening on Socket/5/brNC-internet/2a01:4f8:221:3744:4000::/66
Apr 01 13:35:42 status.nixcloud.io dhcpd6[9225]: Sending on   Socket/5/brNC-internet/2a01:4f8:221:3744:4000::/66
Apr 01 13:35:42 status.nixcloud.io systemd[1]: Started DHCPv6 server.
Apr 01 13:35:42 status.nixcloud.io dhcpd6[9227]: Server starting service.
Apr 01 13:44:47 status.nixcloud.io dhcpd6[9227]: Solicit message from fe80::d4e8:fcff:febf:5937 port 546, transaction ID 0x693A9D00
Apr 01 13:44:47 status.nixcloud.io dhcpd6[9227]: Picking pool address 2a01:4f8:221:3744:4000::300
Apr 01 13:44:47 status.nixcloud.io dhcpd6[9227]: Advertise NA: address 2a01:4f8:221:3744:4000::300 to client with duid 00:01:00:01:22:52:a7:e3:0a:79:bb:c7:9c:d6 iaid = 1 valid for 86400 seconds
Apr 01 13:44:47 status.nixcloud.io dhcpd6[9227]: Sending Advertise to fe80::d4e8:fcff:febf:5937 port 546
Apr 01 13:44:47 status.nixcloud.io dhcpd6[9227]: Request message from fe80::d4e8:fcff:febf:5937 port 546, transaction ID 0x8694C500
Apr 01 13:44:47 status.nixcloud.io dhcpd6[9227]: Reply NA: address 2a01:4f8:221:3744:4000::300 to client with duid 00:01:00:01:22:52:a7:e3:0a:79:bb:c7:9c:d6 iaid = 1 valid for 86400 seconds
Apr 01 13:44:47 status.nixcloud.io dhcpd6[9227]: Sending Reply to fe80::d4e8:fcff:febf:5937 port 546
Apr 01 13:45:38 status.nixcloud.io dhcpd6[9227]: Release message from fe80::d4e8:fcff:febf:5937 port 546, transaction ID 0x176D6200
Apr 01 13:45:38 status.nixcloud.io dhcpd6[9227]: Client 00:01:00:01:22:52:a7:e3:0a:79:bb:c7:9c:d6 releases address 2a01:4f8:221:3744:4000::300
Apr 01 13:45:38 status.nixcloud.io dhcpd6[9227]: Sending Reply to fe80::d4e8:fcff:febf:5937 port 546
Apr 01 13:45:44 status.nixcloud.io dhcpd6[9227]: Solicit message from fe80::d4e8:fcff:febf:5937 port 546, transaction ID 0x9D658700
Apr 01 13:45:44 status.nixcloud.io dhcpd6[9227]: Advertise NA: address 2a01:4f8:221:3744:4000::300 to client with duid 00:01:00:01:22:52:a7:e3:0a:79:bb:c7:9c:d6 iaid = 1 valid for 86400 seconds
Apr 01 13:45:44 status.nixcloud.io dhcpd6[9227]: Sending Advertise to fe80::d4e8:fcff:febf:5937 port 546
Apr 01 13:45:44 status.nixcloud.io dhcpd6[9227]: Request message from fe80::d4e8:fcff:febf:5937 port 546, transaction ID 0xBF064200
Apr 01 13:45:44 status.nixcloud.io dhcpd6[9227]: Reply NA: address 2a01:4f8:221:3744:4000::300 to client with duid 00:01:00:01:22:52:a7:e3:0a:79:bb:c7:9c:d6 iaid = 1 valid for 86400 seconds
Apr 01 13:45:44 status.nixcloud.io dhcpd6[9227]: Sending Reply to fe80::d4e8:fcff:febf:5937 port 546
Apr 01 13:46:20 status.nixcloud.io dhcpd6[9227]: Unable to add forward map from 11.your.domain.com to 2a01:4f8:221:3744:4000::300: timed out


How to tell if a view is cached from generated HTML output?

Question: I have a view on my page and I've cached it using Views caching. Is there a way to tell that the view is cached from the output or the headers? This question says that Drupal sets the header X-Drupal-Dynamic-Cache but I don't see that in my browser's inspector. I do see the header X-Generator:Drupal 7 (http://drupal.org) so that's nice.
It would be nice to see an HTML comment, like what the Boost module does.
Comment: What version of Drupal? 6, 7, or 8?
Comment: 7. Sorry, I should have specified. Mind you, I wouldn't mind knowing the same thing for 8.
Answer: The answer you linked to is wrong. X-Drupal-Dynamic-Cache only exists in Drupal 8. Beyond that, the answer itself is also wrong. Will comment there.
In Drupal 7, you can't tell that the view is cached based on output (HTML markup) or headers.
Comment: Now commented there. Correct answer: http://drupal.stackexchange.com/a/195078/7632.
Comment: Ah! Thank you - I'm sorry I didn't notice that the question I linked to was tagged with Drupal 8.


Why do men and women have different pitch?

Question: I experienced that men and women have some difference in pitch.
Suppose, normal men can sing a song around middle C comfortably, women will have some difficulty, either its a little low or a little high. Due to this , an average pitch is always required to be searched, maybe lower or higher.
Why is it like this?
Comment: I think why is not answerable but how is. It depends on many anatomical details. I don't know much about hormonal effects etc. but [Farinelli](http://www.imdb.com/title/tt0109771/) is a good movie ;)
Comment: I don't know anyone who sings chords, so edited the question a little :-)
Answer: The/a reason is that the difference in vocal ranges is usually not a multiple of an octave. So, suppose a woman can sing A3-A5, where A3 is the A below middle C, and a man can sing E2-E4. Let's say the song has a range of 1,5 octaves, originally written from C4 to G5. Now the woman can sing it but the man can't, since when you transpose the song by an octave or two, it will contain either too high or too low notes for the man (one octave down and the G4 is too high, two octaves down and the C2 is too low). The only way is actually to write the song so it goes from A3 to E5. Then the woman can sing it as written and the man by transposing down one octave.
Answer: Purely anatomical. Women have smaller vocal folds(aka vocals cords) in the glottis. It's simply one of the secondary sexual characteristics of humans, such as facial hair.
The size of the vocal folds and to some extend their spacing determines the range of possible excitation frequencies. Smaller folds -> higher pitch.


Running CoreOS across multiple data centers -howto?

Question: I'd like to use CoreOS as my base OS going forward.
I run a lot of apps in multiple data centers, and I fully believe that I should containerize the lot. This has thrown up a lot of questions, notably control and access of resources.
My dream - is to have a cluster that runs my apps across multiple hosts and scales as required. When I (or the team) wish to make any changes to the cluster, we set a flag or variable in etcd which should trigger a script that updates the cluster - which I feel is possible
My fear comes when I realise that we have a lot of none routable networks that where data is stored, and multiple locations across the world -- Am I going to have to make all these networks routable, if I am to utilize the distributed keychain?
If so, then this kills my dream of running a local instance of CoreOS and connecting it to the cluster, and having access to all the information without having to actually log into a production cluster member?
I hope this makes sense -- I guess I'd like to control my cluster by sending requests to an end point, rather than having to be locally present on the cluster to make the changes. This allows an easy integration path for our existing control scripts and automated systems, which I'd really do not want to have to rebuild all of that!
Comment: It's time to get IPv6.
Comment: Isn't that the true!!!
Answer: You could setup a VPN across the cluster to use as your private network for etcd and the like.
Another option is to build a small app that that acts as the endpoint and talks to the various data centers for you. This is might scale better but it depends on your needs.
Comment: Thanks Randall -- I was thinking in this direction, to have a small etcd daemon running at all times, which is responsible for maintaining the persistence of cluster information. This box will need to be separate from the cluster, and I think is the way to go. I'll have to get to testing though


Drupal 8 Webform - Loop the Result in Remote Post

Question: I am a PHP and Drupal 8 newbie.  I am working on a module based on Drupal 8 Webform and remote post.
I'd like to loop the request sent rather than doing a request->get('keyname') on each.  I'm hoping to using the parameter name to search another string and then replace it with the parameter's value in that string.
Any small foreach example would be appreciated.
Answer: Assuming $request is a Symfony request object:
foreach ($request->request->all() as $key => $value) {
  // ...
}


Is it normal to have different results pattern if data sort is different but the covariances are the same when doing propensity score matching in R?

Question: Is it normal to have different results pattern if data sort is different but the covariances are the same when calculating with propensity score matching in R?
There is data with sample size of about 100.
If I calculate for P-value of the operation time from the data sorted by the operated day, there is no significant difference.
However, it shows significant difference if the imported data is sorted by the operation time descending even though the propensity score is calculated with the same covariances.
Why? and what should be the correct way?
It seems you can manipulate the result by sorting the target item descending even though calculating with the exact same data and the exact same procedure.
Comment: I think you mean "covariates" (i.e., variables to adjust for) rather than "covariances" (i.e., the correlation between two variables).
Comment: @Noah Thanks for correction!
Answer: If you use nearest neighbor matching, the result is sensitive to the order of the matches. The relationship between the order of matches and match quality has been studied in the literature, but the results only apply in general and may not apply to your specific dataset. You should see matching order as one of many tuning parameters that can be adjusted in matching. The best matching order is the one that yields the best balance.
You can simply avoid making this choice by using optimal matching, which is deterministic and doesn't depend on order. Optimal matching minimizes the overall within-pair distances between units. With larger samples, optimal matching may be slow or intractable, so nearest neighbor matching can be a fast alternative. Otherwise, optimal matching should be preferred when possible.
Comment: Thanks for answering. I'm using nearest neighbor within caliper matching(Caliper width=0.2). I'd say that nearest neighbor matching without caliper would bring the wider range of different result patterns. Do you think that Optimal matching provide less different result pattern when compared to Greedy matching(Nearest neighbor within caliper)?
Comment: Did you try matching without a caliper and decide that a caliper was needed to achieve balance, or did you just decide to use a caliper from the start? If you can get good balance without a caliper, then there isn't a large benefit to using one. The question of which method to prefer depends on which method yields the best balance while preserving the size of the remaining sample and ensuring generalizability to the correct target population. Use those metrics to decide how to select a match. This is described in the `MatchIt` vignettes.


Must new tables be created in hook_update_N()?

Question: When you create a new table in hook_schema(), should that table be added in a hook_update_N() as well? Or is there some trick, or something I missed, to have databae-updates automatically add tables?
The documentation of hook_update_N() does not explain anything about introducing new tables, whereas the documentation of hook_schema() says:

The tables declared by this hook will be automatically created when the module is first enabled, and removed when the module is uninstalled.

(Highlight is mine)
And if so, how to best avoid duplicating the schema definitions for the new table in both hook_update_N() and hook_schema(). Simply referring to the schema as follows:
 function hook_update_N(&$sandbox) {
   $schema = hook_schema();
   $name = "foo";
   $table = $schema["foo"];
   db_create_table($name, $table);
 }

Seems to work, but on changing the table again, will fail if a user runs the updates and gets to run two or more hook_update_N()s. After all: the first hook_update_N will then already install the correct database and the second hook_update_M() will try to add/change/alter columns that were already up-to-date.
How do you deal with this?
Comment: So there is no way to avoid violating DRY, it seems. Pity.
Comment: Refer to http://drupal.org/node/150215 for documentation. So basically to add a new table after a module is installed is via hook_update_N but you also add the table definition to the hook_schema for new users or fresh installs. So sum it up if you make any table changes to update the current tables via hook_update_N but you also merge the changes in the hook_schema.
Comment: nothing that I am aware of. But you can write a small function which has the schema definition and call that definition in both the functions.
Comment: @berkes One could define another function that returns the additional schema and refer to it in both the update and install hooks.
Answer: So just a copy paste from drupal.org. You also need to add the schema definition to hook_schema.
/**
 * Create new database table {mytable2}.
 */
function mymodule_update_7101() {
  $schema['mytable2'] = array(
     // table definition array goes here
  );
  db_create_table('mytable2', $schema['mytable2']);
}

Comment: @berkes spot on...there's a very good explanation why that is [here](http://drupal.org/node/150220) in case you haven't already seen it
Comment: Do you mean that there is no other way then copying the table-definition from hook_schema() into hook_update_N(). In other words: that there is no way to avoid violating DRY?
Comment: @Clive That is an awesome example. Never saw it before.  +1
Comment: @junedkazi There's a link to it on the link you provided in your comment ;)
Answer: It's worth to mention that db_create_table function is deprecated and has been removed from Drupal 9. Instead you should use:
/**
* Create new database table {mytable2}.
*/
function mymodule_update_9000() {
  $schema['mytable2'] = [
     // table definition array goes here
  ];
  \Drupal::database()->schema()->createTable('mytable2', $schema['mytable2']);
}


Showing content in popup in Drupal 7

Question: Like Modal Frame API in Drupal 6, is there a similar solution to load content in popup(without page refresh) in Drupal 7?
Answer: Take a look at

Modal Forms (with ctools)
Colorbox
Lightbox2

to name a few.  There are probably more out there, but one of those should do what you want.

Showing content in popup in Drupal 7


Does negative sampling sacrifice performance?

Question: I am implementing a Seq2Seq model. Each step of the decoder has |N| outputs (the number of unique words). Since |N| is huge, I am trying to speed up the training by negative sampling (n_sample=100). I can see the training time for one epoch is reduced by 25%. However, the performance (crossentropy loss) is not as good as full prediction. Is it normal?
Answer: Depending on your model and dataset, I think this type of result can be normal. If your vocabulary size is very large using negative sampling can offer much more than a 25% speedup. You would be able to compensate for the decrease in performance by training for more epochs and still come out ahead in terms of performance per computation time.


Azure Devops 'Publish Test Results' should have an output for the test url

Question: For the Azure DevOps 'Publish Test Results' pipeline, when the task is run I get an output like below:
<code>2022-02-01T18:40:55.7299825Z ##[section]Starting: Publish Test Results **/e2eResults.xml
2022-02-01T18:40:55.7308111Z ==============================================================================
2022-02-01T18:40:55.7308433Z Task         : Publish Test Results
2022-02-01T18:40:55.7308846Z Description  : Publish test results to Azure Pipelines
2022-02-01T18:40:55.7309270Z Version      : 2.198.0
2022-02-01T18:40:55.7309681Z Author       : Microsoft Corporation
2022-02-01T18:40:55.7310042Z Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/test/publish-test-results
2022-02-01T18:40:55.7310427Z ==============================================================================
2022-02-01T18:40:57.2361642Z [command]/usr/bin/dotnet --version
2022-02-01T18:40:57.2362016Z 5.0.404
2022-02-01T18:40:58.9100220Z Result Attachments will be stored in LogStore
2022-02-01T18:40:58.9582047Z Run Attachments will be stored in LogStore
2022-02-01T18:40:59.0471397Z ##[section]Async Command Start: Publish test results
2022-02-01T18:40:59.3342360Z Publishing test results to test run '1024564'.
2022-02-01T18:40:59.3377826Z TestResults To Publish 2, Test run id:1024564
2022-02-01T18:40:59.3419843Z Test results publishing 2, remaining: 0. Test run id: 1024564
2022-02-01T18:41:00.2260832Z Published Test Run : https://<test run URL here>
2022-02-01T18:41:00.7854816Z ##[section]Async Command End: Publish test results
2022-02-01T18:41:00.7857495Z ##[section]Finishing: Publish Test Results **/e2eResults.xml
</code>
It would be VERY helpful if the test run url could be output by the task, so i could add some bash/powershell task afterwards to send an email or PR comment that says 'hey, here are the results of your test run'.  Is there a way to do this already, or is this a feature I have to request?
Comment: No, i ended up just sending a comment to the PR with a link to the general test run page, with instructions on what to filter them by.  Ugly, but works for now!
Comment: Did you end up getting this to work with @jessehouwing's suggestion?
Answer: You can send the good folks at the azure-pipelines-tasks repo a pull request, or you can add a task to download the logs from the previous task and parse out the url from there.
I provided the code to do that in a very similar, but not duplicate question:
https://stackoverflow.com/a/69995041/736079


Don't understan how to implement simple_form create action

Question: Note: I'm using Rails 3.2
I'm trying to implement a simple_form by following this sample code: https://github.com/rafaelfranca/simple_form-bootstrap/blob/master/app/controllers/articles_controller.rb. I have a Summary model instead of an Article model.
I understand most of what's going on, except for the two private methods. I tried basically copying the code except for the two private methods, and what it does is it creates a new Summary, but the attributes are all nil.
1) How are attributes saved? What's the difference between .new and .save?
2) What is available in the create action? When you reach the create action, you've just filled out a form, so something must be available, but I don't know what it is, or how it becomes available.
3) What's going on with the before_action and the two private methods?
Summaries Controller
class SummariesController < ApplicationController
    before_filter :set_summary, only: [:show, :edit, :update, :destroy]

    def index
        @summaries = Summary.all
    end

    def show
    end

    def new
        @summary = Summary.new
    end

    def edit
    end

    def create
        @summary = Summary.new(params[:summary])

        if @summary.save
            redirect_to @summary, notice: 'Summary created.'
        else
            render :new
        end
    end

    def update
        if @summary.update(params[:summary])
            redirect_to @summary, notice: 'Summary updated.'
        else
            render :edit
        end
    end

    def destroy
        @summary.destroy
        redirect_to summaries_url, notice: 'Summary destroyed'
    end

    private
        # sets @summary to make available for show, edit, update
        # and destroy actions so code isn't repetitive
        def set_summary
          @summary = Summary.find(params[:id])
        end

        # Only allow a trusted parameter "white list" through.
        # def summary_params
        #  params[:summary].permit!
        #end

end

Answer: To answer your questions:
1) new is a Ruby method for initializing a new instance of an object. So when you call Article.new, you get a new instance of the Article class.
save is a Rails method for saving a record to the database. If your object instance is instantiated with new, it calls create under the hood. If you loaded the object through a finder (find, all, where, etc.), then it will call update under the hood instead of create.
2) A hash named params is available in all actions (and in the view). In the case of the create action, params[:article], which is the data posted by the form. At the top of create, try calling raise params[:article].to_yaml to see what's going on in there.
Heck, even try raise params.to_yaml to see what's in there.
3) The call to before_action runs the set_article private method before the show, edit, update, and destroy actions. Without that, you'd need to manually call @article = Article.find(params[:id]) in every single one of those actions. So this eliminates quite a bit of repetition!
You'll notice that the first line of the create action calls the article_params method. This is a common way of implementing what are called strong parameters in Rails. Strong parameters are new in Rails 4 but can be added to earlier versions of Rails via the strong_parameters gem.
Comment: Thanks for the help! I'm slightly confused by `params[:article]`. Is it a 2d array? Like `params[:article][:id]`?
Comment: Also, the update action isn't working. It's giving me this error: `private method `update' called for #`. Would you mind explaining to me what's wrong and how to fix it? I added my Summaries Controller to the question.
Comment: `params[:article]` is a hash of everything submitted by the form. Hashes are kind of like associative arrays in other languages. So it may contain keys like `params[:article][:id]`, `params[:article][:title]`, and `params[:article][:content]`, for example.
Comment: Change `@summary.update(params[:summary])` to `@summary.update_attributes(params[:summary])`. `update_attributes` was renamed to `update` in Rails 4, but you'll need to call `update_attributes` in earlier versions of Rails like 3.2.
Comment: You're welcome. Keep going. You'll find Ruby on Rails to be a very enjoyable development environment once you learn the ropes!


percorrer listas int em python pulando numeros consecutivos

Question: Gente, estou tentando eliminar números consecutivos em uma lista de inteiros. Quando a lista for por exemplo 1,2,3,5,6,7,8,9... ele mostrar: 1-3, 5-9
Tentei de diversas maneiras e cheguei nesse codigo:
def apresenta(lst):

for i in lst:
    x = i #1
    a = i+1 #2
    b = i+2 #3
    c = i+3 #4
    d = i+4 #5
    e = i+5 #6
    f = i+6 #7
    g = i+7 #8
    h = i+8 #9
    z = i+9 #10
    j = i+10 #11
    l = i+11 #12
    m = i+12 #13
    if len(lst) > 2:
        while b > x:
            lst.pop(a)
        while d > b:
            lst.pop(a)
        while f > d:
            lst.pop(e)
        while h > f:
            lst.pop(g)
        while j > h:
            lst.pop(z)
    return lst

quando testo em apresenta([1,2,3,4])
Ele me diz IndexError: pop index out of range
Alguém pode me dar uma luz?
Sei que falta muita lógica nesse codigo, mas depois de varias tentativas eu to perdida...
Answer: Se entendi sua dúvida, segue o script para fazer o que precisa:
from itertools import groupby, count

l = [1,2,3,4,5,6,8,10,11]

l = list(set(l)) # Remove números duplicados
l.sort() # Ordenar os números

def apresenta(iterable):
  return ','.join(as_range(g) for _, g in groupby(l, key=lambda n, c=count(): n-next(c)))

def as_range(iterable):
    l = list(iterable)
    if len(l) > 1:
        return '{0}-{1}'.format(l[0], l[-1])
    else:
        return '{0}'.format(l[0])

print(apresenta(l))

As duas linhas comentadas podem ser utilizadas ou não, dependendo de sua necessidade.
Comment: Obrigada pela resposta. O código funciona bem quando temos uma lista pré-definida l = [], mas quero fazer essa nova lista pulando nṹmeros consecutivos para indicar aparição de palavras em um índice, e testei esse código puxando a função em 'apresenta([1,2,3,4,5,6,8,10,11])' e não funciona, pode me explicar por que?
Comment: Desculpe, talvez o código não ficou tão claro, vou atualizar ele. De qualquer forma se passar a lista direto no lugar do 'g' ali no 'apresenta' ele não funciona mesmo, pois a sequencia é gerada pelo groupby logo a frente.


ajax json object doesn't update in IE8

Question: I'm working on a project with an heavy use of Ajax & Json and I tend to refresh the data every second.
Everything works great, Json Parse works well in Google Chrome, but at IE8 my object does not updates from its initial state, forcing me to clear the browser cache in order to see the changes.
With Chrome everything works as expected, changes are seen live. I tried both the native JSON.parse() and jQuery.parseJSON().
Would be glad to have some help with this to make the project run on IE just as good as on Chrome.
Here is this section of the code:
    function get_tables()
    {
       $.ajax(
       {
         url:  'index.php?a=1',
         type: 'GET',
         dataType: 'html',
         success: function(data){
            to_object = JSON.parse(
            console.log('requested');
         },
       });
    }
setInterval(get_tables,1000);

Thanks in advance.
Comment: Why are you telling jQuery to ignore the content-type of the response and treat it as HTML and then parsing it as a string of JSON?
Answer: You are making same request all the time, so it caches your request. You can disable caching in two way,
This will make cache false for all ajax requests
$(document).ready(function() {
  $.ajaxSetup({ cache: false });
});

or
This will disable cache for only this request
$.ajax(
{
 url:  'index.php?a=1',
 type: 'GET',
 dataType: 'html',
 success: function(data){
    to_object = JSON.parse(
    console.log('requested');
 },
 cache: false
});

ajax json object doesn't update in IE8


Como criar uma margem padrão no ckeditor?

Question: Comecei a utilizar CKEditor
E ao inicializar ele, vem da seguinte forma:

E gostaria que ele viesse com uma margem padrão(Quero que fique semelhante a folha A4)
Como poderia fazer com que ele já viesse com um espaçamento?
Comment: Estou tentando formular uma resposta, porém vem a dúvida, a margem que você quer é interna(margem do conteudo do CK editor) ou externa? Fui claro em minha pergunta?
Comment: @SamuelDiogo margin interna
Answer: O CKEditor permite que você passe estilos para dentro do editor, caso você esteja usando a versão 3 você deve usar o seguinte código javascript para adicionar estilos:
CKEDITOR.stylesSet.add( 'estilos-personalizados',
[
    { name : 'MarginA4', element : 'body', styles : { 'margin' : 'suamargin' } },
    { name : 'TamanhoDoTitulo' , element : 'h1', styles : { 'font-size' : 'tamanho da fonte' } },
]);

Isso cria uma "Folha de estilos", agora você precisa setar esta folha de estilos no seu editor, para isso você usa o seguinte código:
config.stylesSet = 'estilos-personalizados';

Onde estilos-personalizadosrepresenta o nome do estilo criado no stylesSet.add
Também há como colocar isso em arquivo externo conforme explicado neste site: Developer Guides - Style
Na versão 4 do CKEditor há uma nova API que usa um objeto de estilo a var style = new CKEDITOR.style( { element : 'body', attributes: { 'style' : 'margin: 10em' } } ); e este deve ser aplicado editor.applyStyle( style );
Mais informações sobre isso podem ser encontradas na documentação localizada em Dev#styles
Espero que isso responda sua pergunta.


How to get program variable set correctly

Question: I'm trying to write code that will return equal dividers of a given number. I don't know where I'm wrong. Any help?
Code:
#include <iostream>
#include <stdlib.h>

using namespace std; // So the program can see cout and endl

int main()
{
    int Numerator;
    cout<<"Enter Numerator: ";
    cin>>Numerator;

    int Denominator = 1;
    while (Denominator < Numerator) {
        int divresult;
        int check;
        divresult = (Numerator / Denominator);
        check = divresult * Denominator;
        if(check = Numerator){
                cout << divresult <<endl;
        }
        Denominator++;

    }

    return 0;
}

Desired Output:
9
3
1

Comment: http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
Comment: you probably mean `if(check == Numerator)` but it is unclear what you are asking.
Answer: The line:
if(check = Numerator){

should be
if(check == Numerator){

You need == to check equality. = is for assignment. Your compiler should have given you a warning.
Also, if you want the output 1 you also need to change the line:
while (Denominator < Numerator) {

to
while (Denominator <= Numerator) {

Comment: thanks! I figured that out after playing around with it.
Answer: This line:
if(check = Numerator){

is wrong.  Checking for equality is done with ==, while = causes the value of Numerator to be assigned to check, and then the if expression is true if the new value is true.  Your compiler should have given you a warning about this mistake; if it didn't, turn on warnings.  If it did, pay more attention to the warnings.
Answer: In C++ the comparison operator is ==
if ( check == Numerator ) { ...


UIImage, is there an easy way to make it darker or all black

Question: I want to take an objective-c UIImage and make it all black, but still have the same alpha values so that it becomes a silhouette of its former image.  I was wondering is there any more convenient way to do this than just taking the CGImage data and changing the values for each pixel?
Answer: You can extract the alpha info by creating a CGBitmapContext with kCGImageAlphaOnly, and 1 component and draw into that. Then you'd have an image with alpha only.
Then you could composite that onto an entirely black image with kCGBlendModeDestinationIn. That should leave you with an image that's all black with the original alpha values.
Answer: Here is a function I have used to make a colorized version of an image:
<code>@interface NSImage( ColorizedImageAdditions )

- (NSImage*) colorizedImage: (NSColor*) color;

@end

- (NSImage*) colorizedImage: (NSColor*) color
{
    NSSize imageSize = [ self size ];
    NSImage* result = [ [ [ NSImage alloc ] initWithSize: imageSize ] autorelease ];

    [ result lockFocus ];
    [ NSGraphicsContext saveGraphicsState ];

    NSRect imageBounds = NSMakeRect( 0, 0, imageSize.width, imageSize.height );

    [ color setFill ];
    [ NSBezierPath fillRect: imageBounds ];

    [ self drawInRect: imageBounds fromRect: NSZeroRect
            operation: NSCompositeDestinationIn fraction: 1.0 ];

    [ NSGraphicsContext restoreGraphicsState ];
    [ result unlockFocus ];

    return result;
}
</code>
It utilizes the NSCompositeDestinationIn operation to fill in opaque areas of the image with the desired color.


Sequential approach to differentiability of complex valued function

Question: Let $f$ be analytic function on an open set $G$. Let $z\in G$. Let $\{z_n\}$ and $\{w_n\}$ be two sequences in $G$ which converges to $z$. Then show that $lim_{n \to \infty} \frac{f(z_n)-f(w_n)}{z_n-w_n}=f'(z)$.
It feels like this should follow just by the definition of differentiability. But can we do the proof in $\epsilon$ and $n$ argument?
I also thought of keeping one n fixed say for $\{z_n\}$ and letting another n tend to infinity we may get $\frac{f(z_n)-f(z)}{z_n-z}$ which will converge to $f'(z)$. But I could not write proper argument for this. Any hint would be helpful.
Comment: $|z_n-z|\lt \epsilon$ and $|w_n-z|\lt \epsilon$ for large enough $n$ could be used to flesh out a proof.
Answer: Let's use the Taylor expansion of $f$. Suppose $w_n,z_n \to z_0$ and let $\sum_{n \ge 0} a_n (z-z_0)^n$ be the Taylor expansion of $f$ around $z_0$. Then
$$
f(z_n) - f(w_n) = \sum_{n \ge 0} a_n \left( (z_n-z_0)^n - (w_n-z_0)^n \right) \\
= \sum_{n \ge 1} a_n \left( (z_n-w_n) \left(\sum_{i=0}^{n-1} (z_n-z_0)^i (w_n-z_0)^{n-1-i} \right) \right) \\
= a_1(z_n-w_n) + (z_n - w_n) \left( \sum_{n \ge 2} a_n \left(\sum_{i=0}^{n-1} (z_n-z_0)^i (w_n-z_0)^{n-1-i} \right) \right).
$$
Dividing by $z_n - w_n$ and letting $n \to \infty$ proves that
$$
\lim_{n \to \infty} \frac{f(z_n) - f(w_n)}{z_n-w_m} = a_1 = f'(z_0)
$$
since all the terms in the big sum go to zero (because $z_n,w_n \to z_0$). For details, if $|z_n-z_0|,|w_n-z_0| < \varepsilon$, then the big sum's absolute value is $\le \sum_{n \ge 2} |a_n| \varepsilon^{n-1}$ which goes to $0$ with $\varepsilon$ since this is equal to $g(\varepsilon)$ where
$$
g(w) = \frac{f(z_0+w) - a_0 - a_1w}{w}
$$
which is analytic when $f$ is analytic.
Hope that helps,


Atualização de variváveis OnInit - Angular 2

Question: Tenho a variável:
compromissoInicio = '';

No onInit, tenho:
this.enviaForm(this.funcoes.homeAtualiza);

Ou seja, se homeAtualiza for true, o sistema atualiza as informações, conforme abaixo:
... submita form ...
this.compromissoInicio = retorno['compromisso_inicio'];

No HTML, tenho:
{{ compromissoInicio | date:'dd/MM/yyyy HH:mm:ss' }}

O problema é que, caso homeAtualiza seja true, toda vez que voltar à página home, o sistema irá consultar o webservice, desnecessariamente.
E, se homeAtualiza for false, o conteúdo de {{ compromissoInicio | date:'dd/MM/yyyy HH:mm:ss' }} fica vazio.
Preciso de uma forma em que compromissoInicio permaneça sempre com o último conteúdo carregado, caso a página não seja atualizada, no onInit.
Answer: Você pode deixar essa variável no service e alimentar ela assim que recebe o valor do webservice. e quando for false, você analisa se essa variável esta com valor caso ela esteja nula ai sim você consome o web service de novo.


How does WindowStartupLocation CenterOwner play with a view model?

Question: In a WPF MVVM application, you have view models that contain all the logic behind the view, and views that display things. Doing things is linked through commands, which are implemented in the view model class.
When I want to open a new dialog window at the center of the initiating window, I need to set WindowStartupLocation = CenterOwner as well as Owner = something to the new dialog window. Unfortunately, the Owner property must be set to a view, but the view is never known in a view model.
So how is that supposed to work together?
Wild guess: Do I have to bind the view's location and size to the view model and position the new dialog manually, not using the CenterOwner automatics?
Comment: _but the view is never known in a view model_ - ideally not, correct. But this rule is not set in stone. ViewModels often have a (generalized) reference to the View.
Comment: Where does that reference come from? Will I pass it to the ViewModel's constructor myself?
Comment: Depends on how you connect and setup  View and ViewModel. Passing it ti the ctor is OK, as is setting a property.
Comment: Thank you, that works well. If you can put this as an answer, I will accept it (since nobody else has another idea).
Answer:
but the view is never known in a view model.

Ideally the ViewModel would be totally unaware of the View(s) that use it. But as you found out that is not always practical.
It is therefore common to have a light coupling, for example as a View property in BaseViewModel.
But your VM should not use any specific Controls or other details from the View.


ElasticBeanstalk Leaving Wide Open SSH Inbound Rules on Security Group?

Question: I am doing a security audit through the Amazon Inspector and it has pointed out that my elastic beanstalk ec2 instances have port 22 open to the internet. I thought this didn't sound right because I don't remember opening that up. But when I looked I found that all of the ec2s created in my beanstalk were associated with a security group, generated by the beanstalk, that had port 22 open to the internet.

Why is this?
Can I remove this?
Is there a way to have it automatically removed so I don't have to do this manually for every beanstalk application going forward?
Comment: I don't think you can stop it doing this by default, but you should be able to modify security groups with `.ebextensions`. Take a look at this answer as a starting point; https://serverfault.com/a/924375
Comment: @markwalker_ That's unfortunate. It's strange they would create a default SG with what they themselves consider a vulnerability. I'm about to do some testing but do you know if it's safe to delete that rule once it's created. I am using my own security groups from the CF template, this gets bolted on regardless.
Comment: You should be ok to remove it. After all you can still login to the console to put it back in if something stops working while you decide what you need to provide your service.
Answer: Yes, you can remove the default security group that allows traffic on port 22 by using a Lambda function. Alternatively, if you remove the SSH key from Elastic Beanstalk, it will no longer create a security group that allows traffic on port 22 for the entire 'Hello World'.
For example below is the CloudFromation stack with ElasticBeanstalk and here I need to remove this to avoid creating a default security group ssh.
<code>  ElasticBeanstalkEnvironment:
    Type: 'AWS::ElasticBeanstalk::Environment'
    Properties:
      EnvironmentName: !Sub '${Project}-${Environment}'
      ApplicationName: !Ref ElasticBeanstalkApplication
      SolutionStackName: '64bit Amazon Linux 2 v3.7.1 running Docker'
      OptionSettings:
        - Namespace: 'aws:autoscaling:launchconfiguration'
          OptionName: 'EC2KeyName'
          Value: 'my_ssh_key'
</code>


Unable to create a Group Policy in Windows Server 2003 to install software

Question: This is my first attempt at creating a Group Policy to install a software product for computers on our domain. When I attempt to add a package I receive the following error:

Add operation failed. Unable to extract deployment information from the package. Run validation on the package to ensure that the package is correct.

Here are the steps I have taken to get to this point:

Within Active Directory, right-click on the Domain and choose Properties
Click on the New button to create a New Group Policy Object
Named the object
Selected the new Group Policy Object and clicked on the Edit button
On the Group Policy Editor dialog, under Computer | Software Settings | Software Installation node,  right-click and choose the New Package command.
The path to the MSI file is a valid UNC path (the share where the MSI file resides has been shared to users within our Domain - full control).
Click "Open" to select the MSI file
Under the Deploy Software dialog, select "Assigned" and click OK
After a few moments (10 - 15 seconds) the error message described above is displayed

Troubleshooting Steps I've tried to Date:

Made sure that the software is not installed on the server already
Used the MSI file to install the software on another machine to make sure the MSI works.
Verified that the Windows Volume on the server has adequate free disk space (100+GB).
Comment: I take it at the command line your passing the unattended and silent commands?
Comment: Yes - I think. I used the /qn command
Answer: That's bad mojo, then. That's nothing that you're doing w/ your procedure, but rather something wrong with the MSI. Did you build the MSI yourself or is it 3rd party? If it's third party, does the manufacturer indicate the MSI works in this type of deployment scenario?
I can't tell you which specific validations you should run because I don't know exactly what Windows is doing when it "extracts" the "deployment information" out of the MSI. I know that I've seen this with a couple of fairly poorly made MSIs from third parties. I belive that I ended up giving up on them, extracting the contents myself, and re-packaging them into MSIs w/ WiX.
(This is one of those places in Windows where I'd love to have some visibility into the source code...)
Comment: Microsoft could have done MSI's so much better if they had forced some things, such as admin installs and un-attended installs as must support options
Comment: @SpaceManSpiff: Total agreement. Sysadmins need to be up in arms and very vocal and outraged with software "manufacturers" who don't use Windows Installer properly. EXE-based setups, poorly made MSI's, etc, are not acceptable. Especially when the tools to make good MSI packages are out there and free. (I can't tell you how many times I've wanted to say to a software manufacturer "Look-- pay for a plane ticket to fly me out there to meet your "setup people" and I'll build an MSI package for you *for free* just so I can have it for my Customers...)
Comment: The MSI is one we built ourselves using a third party tool to create the MSI (AdvancedInstaller).
Answer: Some .msi packages arent designed for unattended installation. Which might explain why it installed ok when you ran it manually.  I've seen this a couple of times when extracting the .msi from an .exe. As Evan said, you are doing everything you should to make this work.


How to Update Related Models in Laravel

Question: Here in this documentation Laravel Inserting Related Model
there is no method to update the current related model.
Have a look:
   Relation Between two Models
private function UserToken($token,$expire,$user_id){

    if($JetUserPass=JetUserPass::find($user_id)->token){
        $JetT = new JetTokens(['id_token' =>$token,'expires_on'=>$expire]);
        $JetUserPass2=JetUserPass::find($user_id);
        $JetUserPass2->token()->save($JetT);//NOT WORKING

    }else{
        $JetT = new JetTokens(['id_token' =>$token,'expires_on'=>$expire]);
        $JetUserPass=JetUserPass::find($user_id);
        $JetUserPass->token()->save($JetT);
    }
}

Possible Error: Integrity Violation ...

Here in if block It is checking that the token is there for the user , if true then it will update the existing one,else it will create new. I want to update the JetTokens Model from JetUserPass Model i.e How to update Related Model?
Comment: @mrun That will not work, read the docs correctly.
Comment: It looks like you're looking for Eloquent's `updateOrCreate()` method. Also, please try to follow conventions for naming: methods should be camel-cased (`userToken` not `UserToken`) and it's a good idea to return the related model to facilitate method chaining, or just to be able to use the updated/newly created `JetUserPass` instance further in the application.
Comment: @MartinBean here I have tried to solve the problem via many different methods works perfectly, but my query is how to update the model via Related model for example: "token belongs to user ". We can save the token via use of user model by calling the function ` $jetUserPass->token()` token function in user model :                                                   `public function token(){
    return $this->hasOne('App\JetTokens','jetuserinfo_id');
  } `
on this function save() is working fine but I want to update the existing record .  :)
Answer: Since you have not provided the error message, I won't be able to help you out properly. But there is another method called create on the same documentation page. It says:

In addition to the save and saveMany methods, you may also use the
  create method, which accepts an array of attributes, creates a model,
  and inserts it into the database. Again, the difference between save
  and create is that save accepts a full Eloquent model instance while
  create accepts a plain PHP array:

So, to answer your solution, you can do like this:
private function UserToken($token, $expire, $user_id)
{
    $jetUserPass = JetUserPass::find($user_id);

    $insertValues = [
        'id_token'   => $token,
        'expires_on' => $expire
    ];

    // Since you have same code, I have replaced it
    // in a single line following the principle of DRY.
    // Read the link below.
    $jetUserPass->token()->create($insertValues);
}

Just a side note:
Your code is violating the principles of DRY. This is because, your method's if and else block are having the same code except the JetUserPass and JetUserPass2 properties. That should be avoided under any circumstances.
Hope this helps you out. Happy Coding. Cheers.
Comment: There is no repetition in the code , sorry but you didn't got the logic there, what is happening I'll Brief you – Here in if block It is checking that the token is present there for the user , if true than it will update the existing one,else it will create new . I know how to save new but don't know how to update the related model

How to Update Related Models in Laravel


What is the appropriate test when dependent variable is ordinal binary and independent variable is continuous?

Question: I am curious what is the most appropriate test to use when the outcome variable is an ordinal binary (test score of pass or fail) with a set of four unordered treatment conditions (A,B,C,D) as the independent variable.
I think Chi-Squared test could work here but I wonder if Kruskal-Wallis test might be a better choice since the outcome is technically ordinal.
Answer: You want to use a chi-squared test since your data is all categorical. The Kruskal-Wallis is a nonparametric test similar to ANOVA which requires numerical data (a continuous variable).
EDITS:
Edits here are to address the comment below

Thanks for the link but that document seems to imply the same thing I was suggesting. If the outcome variable was instead categorical with 0%, 25%, 50%, 75%, 100% scores as the five levels, wouldn't this imply an ordering: 0 < 25 < 50 < 75 < 100? Doesn't the same thing apply if we just reduce this to pass or fail as 0 < 100?

To answer this, I will present the following example. Consider three medical treatments (A, B, and C). Each treatment results in a certain amounts of deaths (alive vs dead). The null hypothesis I am concerned with is this: not all treatments have the same effect on death (e.g. Treatment B may have the lowest death rates).
$$
H_0: p_A \neq p_B \neq p_C
$$
In this example, with my outcome variable being status=alive or status=dead, I can suggest that alive > dead (as most people would probably like to live). However, my null hypothesis (and research goals) are not concerned with ranking (e.g. alive > dead or alive < dead). Instead, it is concerned with how treatments affects the outcome status (alive or dead). Thus, the type of test I'd be concerned with is a $\chi^2$-test (see: WHAT STATISTICAL ANALYSIS SHOULD I USE? STATISTICAL ANALYSES USING STATA)
So to answer your question, if your research question is concerned with outcome status (instead of ranking order) then a $\chi^2$-test will be appropriate.
References:

Chi-Square Independence Test – What and Why?
Kruskal-Wallis Test
WHAT IS THE DIFFERENCE BETWEEN CATEGORICAL, ORDINAL AND INTERVAL VARIABLES?
Comment: Okay, but I read that Kruskal Wallis (or at least Mann Whitney) can also use ordinal data as its dependent variable. If that's the case, since the binary in this particular case is an ordinal categorical, why would it be incorrect to use Kruskal Wallis here?
Comment: It's not though. You're putting your own preferences on "fail" or "pass". The events are outcomes, not choices. It's not like choosing 1 < 2 < 3 ...
Comment: Okay, so if I understand correctly, you're saying the distinction is whether the meaning of the dependent variable is known to the users producing it versus only known to the experimenter? If the experiment design had instead measured the same two options (pass or fail) but in terms of users self-reporting their perceptions of what their grade would be, would that change the statistical test applied? If so, could you provide some reference material that discusses this standard?
Comment: I suggest you read https://stats.idre.ucla.edu/other/mult-pkg/whatstat/what-is-the-difference-between-categorical-ordinal-and-interval-variables/
Comment: Thanks for the link but that document seems to imply the same thing I was suggesting. If the outcome variable was instead categorical with 0%, 25%, 50%, 75%, 100% scores as the five levels, wouldn't this imply an ordering: 0 < 25 < 50 < 75 < 100? Doesn't the same thing apply if we just reduce this to pass or fail as 0 < 100?
Comment: Thanks for the update and example! Just to clarify a little further, could you give a similar example, preferably in the same context, where Kruskal-Wallis *would* be appropriate?