ARMA parameters

Question: I am currently doing a short term forecast using ARIMA model.I have been following Box and Jenkins method and to choose the best ARIMA parameters to do do my forecast I tested various(p,q) combinations and took the one with the lowest aic(akaike information criteria). I assigned a d value as the number of differenciation required. My problem is that my forecast is converging into a straight line after 2 hours. Did I choose a wrong method? Is it because I have to try higer AR(p) and MA(q) parameters. I put a threshold for AR(p) at 4 and for MA(q) at 2. I saw in some articles, they were going upt to 24 to do there forecast. Is there a limit for choosing parameters? Can you give me some references please?
Answer:
My problem is that my forecast is converging into a straight line after 2 hours.

This is not an abnormal behavior for ARMA models, they're stationary. You're probably talking about the mean forecast, i.e. $E[y_{t}]$. For instance, in AR(1) model: $y_{t+1}=c+\phi y_t+\varepsilon_t$, the mean forecast is $E[y_t]=\frac{c}{1-\phi}$, i.e. a constant.
This MATLAB help may be helpful in understanding the convergence of ARIMA models.
Take a look at a typical AR(p) forecast, it's basically a smooth line in long horizon forecast, it has some interesting structure only in the short range forecast horizon:

(source: mathworks.com)
Comment: What can I do to improve the model. Do I have to choose higher values of AR(p) and MA(q) parameters.
Actually,I am doing the forecast using ARIMA with I(d=1)
Comment: What are you trying to accomplish? All ARIMA models' mean forecasts converge to something in a long run. Do you want to see more "structure" in the forecast? Increasing the lags will only help in this regard in short term.
Comment: Think of this: at 10 mins interval, you have 36 intervals to forecast. Your ARIMA must have comparable number of lags, if you want to produce _interesting_ forecast, i.e. the one which is not a straight line. I can't tell you how many lags, but it's got to be more than handful, maybe 18 or more. Then you run into different issues. Did you consider [ARIMAX](http://www.mathworks.com/help/econ/arima-model-including-exogenous-regressors.html) or [VAR](http://en.wikipedia.org/wiki/Vector_autoregression)? I bet that the temperature or pressure could be important exogenous or endogenous variables.
Comment: You might also look into exponential smoothing methods. See the forecast package in R.
Comment: I'm sure there are topics in SE on Kalman filters.
Answer: You cannot say that you choose a wrong model just because the forecasts are converging to a straight line. But it may be due to the fact that you didn't pick up the right order. Note that higher orders are much more difficult to estimate.
The search limits for the AR and MA parts most of the time comes from your own knowledge. But in the forecast package in R (that uses different criteria like "aicc","aic", "bic"  to find the best model),  they set by default max.p=5, max.q=5, max.P=2, max.Q=2, max.order=5, max.d=2, max.D=1, where the capital letters (P, D, Q) refer to seasonal orders. However, as mentioned in the book R Cookbook by Paul Teetor, P. 384, if you think that your models needs more coefficients, then you need to expand the search limit. On the other hand, if you look at the book  Introduction to Time Series and Forecasting (2nd Ed.) by Peter J. Brockwell, Richard A. Davis, P. 161, the maximum range for both p and q is from 0 to 27. Note that they use AICC rather than AIC. Therefore , to my knowledge, there is no universal agreement on these limits.
One last thing, in practice, you normally end up with some competitive models and not just one model based on one criteria. Then at the end of the day, you will again double check those models and pick up one of them to use.

ARMA parameters


Why is UUID column VARCHAR(128)?

Question: Just wondering if anyone knows why uuid columns created by Drupal 8 in MySQL are of type VARCHAR(128), not CHAR(36)?
Comment: Good question. Related issue on drupal.org: https://www.drupal.org/node/1805576.
Answer: Basing on this comment by Damien Tournoud, the idea was to support arbitrary string identifiers.
Since Drupal uses a service to generate UUIDs, using a VARCHAR(128) as database field for the UUID would allow a module to override the current service with one using a different implementation, and using more bytes for the UUID.

Why is UUID column VARCHAR(128)?


Alesis DM10 (2011) with Logic Pro x

Question: I have a Alesis DM10 (2011 model) connected to my MacPro via USB and my Logic Pro X sees the DM10 and is getting inputs as I can see the sound bars moving, but obviously I am not getting any sound as I need to get a sound pack.
This is my question
Which sound pack should I get ? I have seen various ones EZdrummer, Superior Drummer, BFD etc.
I am mainly going to be using it at home for my own stuff with friends etc but would like the best quality for the best price of course or if someone has any better ideas.
I would also like to be able to add further sounds such as orchestral drums, world sounds etc for some projects I might like to do.
Comment: imnsho, EZdrummer would be easiest to handle, Superior best overall [but with a lot more work] & I haven't looked at BFD in years, I never liked their over-processed sounds, personally.
Comment: imnsho thanx for that, ill have a further look into EZdrummer, there website didnt really give me much to go by as it looked like it was more for musicians who need basic drums, ill see if there is a trial or something to play with
Comment: Hi @AJHenderson Yes I have been on the Video Production, im also a amateur musso, I didnt see a group for music practice and theory but I could have just missed it, cheers for pointing it out, but I will be using my drums for doing simple scores for my films as well as making music etc, but I will head over there and ask the question but the EZdrummer looks good but I found a comparison with EZdrum and SupDrums
Answer: Any VST drums that you buy will work with DM10 module. It's all a matter of your budget I think, especially if you don't plan to do it professionally. My personal favourite is EZDrummer 2 which is ultra-easy, has great sounds and it's one of the cheapest VST drums on the market. It also has a compability mode for Alesis drum modules which will help you overcome some of the annoyances of the module.
I've written posts about this on my blog here and here.
I'm personally very happy about this setup. The EZD2 samples are great. If I was to point of the feature I'd like to add to EZD2 is to have the possibility to edit the assignment of MIDI notes to drum kit parts. But from what I was able to find out it's only possible in Superior Drummer 2 and BFD3 which are much more expensive. I've also worked with Superior Drummer and while this software has much more possibilities that EZD I found out that I wasn't using most of them anyway.
The feature that is my favourite in EZD2 is by far the Song Builder, which allows you to fine tune the midi patters and generate the whole song structure based on the single MIDI pattern. That's great for recording as you can have a basic drum track done in 5 minutes and focus on recording guitars and vocals and at the end you can sit back and finish polishing the drum track.
Comment: Wow had a quick read through and you seems to have written a thorough blog post/s. Ill give it a try when I get some time to sit and configure it all, first things first is getting EZDrummer2
Comment: Hi, I have tried EZdrummer 2 and it is great but due to issues I cannot afford to buy it yet, I have tried to use the LPX built in sounds but I loose 2nd floor tom, 1 cymbal and I cannot get it to separate into individual tracks without having to spend just as much time renaming and sorting copying them into new tracks, any advice ?

Alesis DM10 (2011) with Logic Pro x


Asp.net 4.5 "multi-core jitting" not working

Question: I'd like to take advantage of the new multi-core jitting feature in .net 4.5.

My web.config is set to targetFramework="4.5"
The application pool framework in IIS is set to v4.0 (from what I understand, that is correct)
My processor is an i7 with 4 cores (or 8 with hyperthreading) - http://ark.intel.com/products/52214/

But it doesn't seem to have decreased the JIT compilation time (based on performance profiling), and I can see no evidence of any *.prof files being created in ASP.NET Temporary Files.
How can I track down the reason for this?
Comment: Can you please file a connect issue and let me know the issue id?http://connect.microsoft.com/VisualStudio
Comment: Done - https://connect.microsoft.com/VisualStudio/feedback/details/770871/asp-net-4-5-multi-core-jitting-not-working
Comment: Thanks. Sebastian from Microsoft Replied as answer to this post. I will update the connect bug later with KB article link or something.
Answer: Background JIT compilation might not work in some specific scenarios. You can debug it using PerfView http://www.microsoft.com/en-us/download/details.aspx?id=28567
From the documentation, here are the main reasons:

When modules are loaded, a module constructor could be called, which could have side effects (even this is very rare).   Thus if background JITTing would cause a module to be loaded earlier than it otherwise would be, it could expose (rare) bugs.  Because background JIT had a very high compatibility bar, it protects against this by taging each method with the EXACT modules that were loaded at the time of JIT compilation, and only allows them to be background JIT compiled after all those EXACT modules were also loaded in the current run.   Thus if you have a scenario (say a menu opening), where sometimes more or fewer modules are loaded (because previous user actions caused different modules to load), then background JIT may not work well.

If you have attached a callback to the System.Assembly.ModuleResolve event, it is possible (although extremely unlikely and very bad design) that background JITing could have side effects if the ModuleResolve callback returned different answers on the second run than it did on the first run.   Because of this background JIT compilation is suspended the first time an ModuleResolve callback in invoked.

Because any module lookup that fails, WILL call the ModuleResolve event before it finally fails, this means that any probing for modules which fail will also inhibit background JIT compilation.

I would suggest to check if the assembly(ies) which is failing the background JIT is exposing one of these issues. To do so, start a new Collection before your application is starting, and Stop it when it's done. Don't forget to check the Background JIT option in the Advanced section.
In the JITStats section you should get something like this:
<code>Total Number of JIT compiled methods : 10,673
Total MSec JIT compiling : 9,873
This process uses Background JIT compilation (System.Runtime.ProfileOptimize)
WARNING: Background JIT aborted at 11,847.909 Msec
The last assembly before the abort was 'NHibernate.XmlSerializers' loaded unsuccessfully at 11,793.741
Methods Background JITTed : 0
Percent # Methods Background JITTed : 0.0%
</code>
Update
Related to scenario 3, in the case of ASP.NET, ASP.NET itself handles the ModuleResolve event, so any module that fails to load will cause MCJ to abort in an ASP.NET app.


How to resolve mvn variables?

Question: Two questions in one:

Given a variable ${project.build.directory}, how can i find out what exactly this resolves to on my machine?
Where can i find a list of all maven variables?
Answer: If you like to know to which it is expanded simply do a:
mvn help:effective-pom

The existing list of variables can be found in the documentation or here.

How to resolve mvn variables?


Proof of Zariski's lemma in Atiyah-MacDonald

Question: I'm currently working through the proof of the weak Nullstellensatz in Atiyah & MacDonald's Introduction to Commutative Algebra, but I'm stuck at the Proof of Proposition 7.9 (Zariski's Lemma):
Let $k$ be a field, $E$ a finitely generated $k$-algebra. If $E$ is a field, then it is a finite algebraic extension of $k$.
Let $E=k[x_1,\ldots,x_n]$, $F=k(x_1,\ldots,x_r)$, where $x_1,\ldots,x_r$ are algebraically independent and $x_{r+1},\ldots,x_r$ are algebraic over $F$.
Then it is shown that $F$ is a finitely generated $k$-algebra.
Say $F=[y_1,\ldots,y_k]$, where $y_i = \frac{f_i}{g_i}, \enspace f_i,g_i \in k[x_1,\ldots,x_n]$. Up to this point everything is clear to me.
Then the proof goes on: Since there are infinitely irreducible polynomials in $k[x_1,\ldots,x_n]$ there exists an irreducible polynomial $h$ which is prime to each of the $g_j$ (for example $h=g_1g_2\cdots g_k + 1$).
Here I'm stuck, I can't see why $g_1g_2\cdots g_k + 1$ would necessarily be irreducible (maybe we could take an irreducible factor), and why we need to know that there are infinitely many irreducible polynomials in $k[x_1,\ldots,x_n]$ to say such a polynomial $h$ exists.
Any help would be appreciated.
Comment: I also can't see why $h$ is irreducible, but an irreducible factor of $h$ does the job.
Answer: It is not necessarily true that $h=g_1g_2\cdots g_k + 1$ is irreducible.  However, it has no (non-unit) common factors with the $g_j$.  This is because any common factor of $h$ and $g_j$ would also be a factor of $h-g_1g_2\cdots g_k=1$.  So, if you let $p$ be any irreducible factor of $h$, $p$ must be an irreducible polynomial that does not divide any of the $g_j$. (Such an irreducible factor exists as long as the $g_j$ are not all constant so $h$ is not constant; if they are all constant, you could just take $x_1$ as your irreducible polynomial instead.)
(This is essentially the same as the classic proof that there are infinitely many prime integers: if you have finitely many primes, multiply them together and add $1$, to get a number whose prime factors are not on your list.)
Alternatively, if you already know that there are infinitely many irreducible polynomials in $k[x_1,\dots,x_n]$ (up to units), you can just define $h$ to be any irreducible polynomial that is not a factor of any of the $g_j$.  This is possible since each $g_j$ has only finitely many irreducible factors (up to units).
Comment: It must be noted that having $r\ge 1$ is vital for the existence of $p$.


Damped wave equation does not increase the energy

Question: Consider the system: (functions are smooth) and $g$ has compact support.
$$\begin{cases} u_{tt}-u_{xx}+u_t = 0 \qquad x\in \mathbb{R}, t>0 \\
u(x,0)=f(x) \qquad \qquad x \in \mathbb{R}\\
u_t(x,0)=g(x)
\end{cases}$$
Prove that $E(t)=\int_\mathbb{R} u_t^2+u^2_x dx$ is nonincreasing.
When we put derivative inside use equation and integrate by parts we get
$$E'(t)=u_tu_x |_{x=-\infty}^{x=+\infty}-2\int_\mathbb{R} u_t^2 dx$$
How to prove that the boundary term vanishes?
Comment: you still can solve it first with the Fourier series $g(x) = \sum_n c_n e^{2 i \pi n x / T}$ where $T$ is greater than the size of $support(g)$, and $E(t)$ will be obtained from the Parseval theorem
Answer: The damped wave equation has finite propagation speed (see below), as the standard wave equation. Hence, for every fixed $t$ the function $x\mapsto u(x,t)$ has compact  support, which implies $u_tu_x$ vanishes at infinity.
Finite propagation speed
I'll work in $\mathbb{R}^n$ since this proof is the same. The precise claim is that if $f,g$ vanish on the ball $\{x:|x-x_0|\le r\}$, then $u(x,t)$ vanishes on the cone $C=\{(x,t):|x-x_0|\le r-t\}$.
Proof. (Following PDE by Evans, p. 86) Consider the energy within a time slice of the cone $C$:
$$E(t) = \frac12\int_{|x-x_0|\le r-t} (u_t^2  +|\nabla_x u|^2)\,dx$$
Differentiation yields
$$
E'(t)=\int_{|x-x_0|\le r-t} (u_tu_{tt}  + \nabla_x u \nabla_{xt} u)\,dx
-\frac12\int_{|x-x_0| = r-t} (u_t^2  +|\nabla_x u|^2)\,dx
$$
The second term here comes from the fact that the ball is shrinking. Using the elementary inequality $a^2+b^2\ge 2ab$ we get
$$
\frac12\int_{|x-x_0| = r-t} (u_t^2  +|\nabla_x u|^2)\,dx \ge
\int_{|x-x_0| = r-t} |u_t| |\nabla_x u |\,dx
$$
which means that this subtracted term is enough to offset the boundary term coming from integration by parts:
$$
\int_{|x-x_0|\le r-t} (u_tu_{tt}  + \nabla_x u \nabla_{xt} u)\,dx
 = \int_{|x-x_0|\le r-t} (u_tu_{tt} - \Delta u u_t)\,dx + \int_{|x-x_0| = r-t}  u_t \nabla_xu  \,dx
$$
In conclusion,
$$
E'(t) \le \int_{|x-x_0|\le r-t} (u_tu_{tt} - \Delta u u_t)\,dx =
\int_{|x-x_0|\le r-t} (-u_t^2 )\,dx \le 0
$$
This proves that $E(t)=0$ for $0\le t\le r$, hence $u$ vanishes in the cone $C$.
Comment: Thank you! I have a question regarding the formula for $E'(t)$, how to show rigorously that $- \frac{1}{h} \int_{r-t-h \leq |x| \leq r-t} f(x,t) dx$ converges to the boundary integral in your formula ($f$ being the integrand) as $h\rightarrow 0$?
Comment: Uniform continuity gives this. On each short radial segment, consider the maximum and minimum of f. These are functions of polar angle. The integral over the shell is between the integrals of those. But the maximum and minimum converge to boundary values uniformly.


$A\neq\emptyset,\; B\neq \emptyset, \;A\times B \;\text{finite} \rightarrow A\; \text{and} \;B $ are both finite too.

Question:
$A\neq\emptyset,\; B\neq \emptyset, \;A\times B \;\text{finite} \rightarrow A\; \text{and} \;B $ are both finite too.

Assume on contrary that one of $A$ or $B$ is infinite. WLOG let $A$ infinite and $B$ finite.
$A $ infinite $\rightarrow$ $\exists f:N\to A$ an injection
$B$ finite $\rightarrow \exists g:[n]\to B$ a bijection for some $n\in N$
Since $B\neq \emptyset$ $\rightarrow \exists b_0\in B$
then $h:N \to A\times B$ where
$k\mapsto (f(k),g(k)) $ if  $k\in [n]$  and
$k\mapsto  (f(k),b_0) $ if $k>n$
This map is injection so $A\times B$ becomes infinite contradiction
Is this proof okay?
Comment: Proof is ok, yes. Notice that $f(k), b_0$ was already a good function to use
Comment: @FranciscoJoséLetterio Nice observation, thank you
Comment: The proof is not ok as written, though. One has to translate what you write to understand what you meant to say instead. For instance, the sentence starting with "then $h$" makes no sense.
Comment: A slight nitpick.  You didn't not consider if $A$ and $B$ are *both* infinite.  Which is to say just assume wolog $A$ is infinite and assume nothing about $B$ except it is non empty.  Otherwise your proof is fine but a bit stiff and overly formal.  It'd be a lot simpler to say: let $b\in B$ then $f(x)=(x,b);f:A\to A\times\{b\}\subset A\times B$ is easily shown to be a bijection.  So if $A$ is infinite we have an injection from an infinite set to a finite set.
Answer: Your proof is fine. But you can do it directly: fix $a\in A;\ b\in B$ and note that the inclusions $i_b:A\to A\times B:x\mapsto (x,b)$ and $j_a:B\to A\times B:y\mapsto (a,y)$ are injections into a finite space.


Merge row data based on the column value of two 2d arrays

Question: How can I merge these two array together?
Array
(
[0] => Array
    (
        [id] => 5
        [cnt] => 14
    )

[1] => Array
    (
        [id] => 8
        [cnt] => 2
    )

)

Array
(
    [0] => Array
        (
            [id] => 8
            [binding] => hardcover
        )

    [1] => Array
        (
            [id] => 5
            [binding] => softcover
        )
)

The expected result is:
Array
    (
        [0] => Array
            (
                [id] => 5
                [binding] => softcover
                [cnt] => 14
            )

        [1] => Array
            (
                [id] => 8
                [binding] => hardcover
                [cnt] => 2
            )

    )

The merge of these two array should happen on the [id] value and not on any sort of the array. How can I do this with php in a fast way?
Answer: $output = array();

$arrayAB = array_merge($arrayA, $arrayB);
foreach ( $arrayAB as $value ) {
  $id = $value['id'];
  if ( !isset($output[$id]) ) {
    $output[$id] = array();
  }
  $output[$id] = array_merge($output[$id], $value);
}

var_dump($output);

Optionally if you want to reset output's keys, just do:
$output = array_values($output);

Comment: If I did NOT know the number of arrays ( `$arrayA`, `$arrayB`, ..., etc) ahead of time, how does the `array_merge` part go in that case?
Answer:
Merge the input arrays, then
Loop the rows and merge associative row data with the array union operator (+).  The array union operator should only be used with associative, non-numeric keyed arrays.

The first time that a given id is encountered, there will be no "group" in the result array yet.  To avoid a Warning generated by trying to merge row data with an undeclared variable, use the null coalescing operator (??) to fallback to an empty array.
The snippet below will be highly efficient because it makes no iterated function calls.
If you do not want the first level keys in the result array, then call array_values() to re-index the array.
Code: (Demo)
$a1 = [
    ['id' => 5, 'cnt' => 14],
    ['id' => 8, 'cnt' => 2],
];
$a2 = [
    ['id' => 8, 'binding' => 'hardcover'],
    ['id' => 5, 'binding' => 'softcover'],
];

$result = [];
foreach (array_merge($a1, $a2) as $row) {
    $result[$row['id']] = ($result[$row['id']] ?? []) + $row;
}
var_export(array_values($result));

Output:
array (
  0 =>
  array (
    'id' => 5,
    'cnt' => 14,
    'binding' => 'softcover',
  ),
  1 =>
  array (
    'id' => 8,
    'cnt' => 2,
    'binding' => 'hardcover',
  ),
)


Is there a notion that $0 + \mathbb Ri$ or $\mathbb R + 0i$ has an 'internal complexification' equal to 'external complexification' of $\mathbb R$?

Question: I started studying the book of Daniel Huybrechts, Complex Geometry An Introduction. I tried studying backwards as much as possible, but I have been stuck on the concepts of almost complex structures and complexification. I have studied several books and articles on the matter including ones by Keith Conrad, Jordan Bell, Gregory W. Moore, Steven Roman, Suetin, Kostrikin and Mainin, Gauthier
I have several questions on the concepts of almost complex structures and complexification. Here is one:

Note: For the question stated next, I mean 'internal' and 'external' as something like internal vs external direct sum. What I mean by 'internal' and 'external' complexification is not the same as in these articles: Article 1, Article 2, Article 3
In the articles, we have 'external complexification' as complexification like $\mathbb R^2$ to $\mathbb C^2$ and 'internal complexification' as adding almost complex structures/complex structures like $\mathbb R^2$ to $\mathbb C$.

Question: In Conrad, is there some kind of notion of 'internal' vs 'external' complexification, such that, for example, the 'internal' complexification of the $\mathbb R$-subspace $\mathbb R + 0i$ of $\mathbb C$ is actually 'literally' the same (and not merely $\mathbb C$-isomorphic) as the 'external' complexification of $\mathbb R$?

Here, I mean 'literally' as with the following examples

Example 1: $GL(\mathbb R,n)$ is a set of matrices while $Aut(\mathbb R^n)$ is a set of maps so they are not 'literally' equal since they do not have the same underlying set.
Example 2: I consider $\mathbb R^{\mathbb C}$, $(\mathbb R^2,J)$ (see below) and $\mathbb C$ as literally equal to each other and literally unequal to $(\mathbb R^2,-J)$, even though they are all $\mathbb C$-isomorphic to each other.

Below, I try to use the symbol '=' to denote what I believe are literal equalities (under certain conventions) and use the symbol '$\cong$' for isomorphisms.

What I understand:

It seems in Conrad that the 'complexification' of $\mathbb R$ is, not merely $\mathbb C$-isomorphic, but actually literally the same as both of the 'complexifications' of the $\mathbb R$-subspaces $\mathbb R + 0i$ and $0 + \mathbb Ri$ of $\mathbb C$. (I kind of don't see $\mathbb R + 0i$ as literally the same thing as $\mathbb R$, but if you do, then you may focus on $0 + \mathbb Ri = \mathbb Ri$ instead of $\mathbb R + 0i$).
The complexification of $\mathbb R$ to be $\mathbb R^{\mathbb C} = \mathbb C = (\mathbb R^2,J)$, with $J:\mathbb R^2 \to \mathbb R^2$, $J(u,v) := (-v,u)$, for $u,v \in \mathbb R$. Here, we have $\mathbb R^{\mathbb C}$'s underlying set ($\mathbb R^2$) to be a subset of the underlying set of $\mathbb C$ (which is also $\mathbb R^2$).
$(0 + \mathbb Ri)^{\mathbb C} = ((0 + \mathbb Ri)^2,K)$, with $K((0,vi),(0,wi)) := ((0,-wi),(0,vi))$. Here, we have $(0 + \mathbb Ri)^{\mathbb C}$'s underlying set as a subset of the underlying set of $\mathbb C^2$ (which is $\mathbb R^2 \times \mathbb R^2$ or $\mathbb R^4$, depending on convention).

Here's my guess: I kind of think the definition of internal complexification as that for $U$ an $\mathbb R$-subspace (or $(\mathbb R+0i)$-subspace) of a $\mathbb C$-vector space $W$, we have $U^{\text{internal}-\mathbb C} = W$ if and only if any of the following, which I think are equivalent

any $\mathbb R$-basis (or $(\mathbb R+0i)$-basis) of $U$ is a $\mathbb C$-basis of $W$
(for finite dimensions) $\dim_{\mathbb R} U = \dim_{\mathbb C} W$ and $\mathbb C$-span $U$ = $W$

I think of condition (1) as the generalisation of condition (2), similar to this question I just posted.

$iU := \{iu | u \in U\}$ is an $\mathbb R$-subspace of $W$ such that $U \cap iU = \{0_W\}$. Then $W_\mathbb R$ can be written as an internal direct sum $W_\mathbb R = U \bigoplus iU$, where $W_\mathbb R$ is $W$ treated as an $\mathbb R$-vector space.

I was also thinking something like if $U^{\text{internal}-\mathbb C} \ne W$, then at least $U^{\text{internal}-\mathbb C}$ is the unique $\mathbb C$-subspace of $W$ such that internally, $(U^{\text{internal}-\mathbb C})_{\mathbb R} = U \bigoplus iU$.

Additional note based on the comments of reuns: I think that Suetin, Kostrikin and Mainin, like Conrad, also have some notion of internal complexification.
In Suetin, Kostrikin and Mainin, specifically 12.15 of Part I, the authors seem to be talking about how complexification is or can be seen as (by some isomorphism I guess) a specific case of the more general notion of extension of scalars, as Wikipedia does. (Note: The authors don't introduce tensor products until 3 chapters later.)
The definition is that for $\mathcal K$ a subfield of a field $K$ and for a $\mathcal K$-vector space $L$, $L$ has extension $L^{K}$, a $K$-vector space given by formal linear combinations. The definition they gave is for finite $L$, but I believe the same idea works for infinite $L$. I believe the intended definition extended to allow for infinte-dimensional $L$ is as follows:
For $L$ with basis $E=\{e_{\alpha}\}_{\alpha \in A}$
$$L = \{\sum_{j=0}^{n} b_j e_j | \text{for unique} \ b_j \in \mathcal K, e_j \in E, n \ge 0, j \in A \}$$
$$L^{K} := \{\sum_{j=0}^{n} a_j e_j | \text{for unique} \ a_j \in K, e_j \in E, n \ge 0, j \in A \}$$
Applied to $\mathcal K = \mathbb R$ and $K = \mathbb C$ (treating $\mathbb R$ as identical to $\mathbb R + 0i$), it seems then that this generalisation is what one (or maybe just 'I' instead of 'one') might call internal rather than external complexification.

Reason this could be important and is not some nitpicking that is resolved with 'up to isomorphism':
If both $\overline {\mathbb C}$ and $\mathbb C$ have $\mathbb R$-form $0 + i\mathbb R$, but $0 + i\mathbb R$'s (internal) complexification is $\mathbb C$, then it seems $\overline {\mathbb C}$ is never the literal (internal or external) complexification of any $\mathbb R$-vector space. (Of course, this may depend on your definition of complexification, and I do kind of assume that the '$0 + i\mathbb R$' $\subseteq \mathbb C$ is the same as the '$0 + i\mathbb R$' $\subseteq \overline{\mathbb C}$.) However, that $\overline{\mathbb C}$ has conjugations but has no $\mathbb R$-forms seems to contradict Conrad Theorem 4.11.
Comment: $\Bbb{C}W=\{ zw\in V,z\in \Bbb{C},w\in W\}$. And on a real vector space there are only complex structures, no almost complex structure (which is when we try to glue together some complex structures on a bunch of tangent spaces to obtain a complex structure on a real manifold, for example the complex structure on the sphere $S^2\subset \Bbb{R}^3$ makes it isomorphic to the Riemann sphere $\Bbb{C}\cup\infty$, and the "almost complex structure problem" is to define such a global complex structure by some local constraints).
Comment: I think there is a [problem p.8](https://kconrad.math.uconn.edu/blurbs/linmultialg/complexification.pdf), with $W$ a real subspace of a complex vector space $V$ then the complexification of $W$ is never $V$. He meant $\dim_\Bbb{R}(W)=\dim_\Bbb{C}(V)$ and $\Bbb{C}W=V$. A complex vector space is a real vector space together with a $\Bbb{R}$-linear operator $I$ satisfying $I^2=-1$, so that we have $\Bbb{C}$-action $(a+ib).v=av+b I(v)$, it is the knowledge of this action that we call "complex vector space", thus there are often several different complex vector space structures.
Comment: @reuns Thanks. What is '$\mathbb C W$' ? Also about a real subspace $V$ of $W$ never having its complexification as $W$, right so, this is what makes me think of $W$ as a different kind of complexification of $V$. I mean, $(\mathbb Ri)^{\mathbb C}$ is indeed $\cong$ even though not equal to $(\mathbb R)^{\mathbb C}$. As I mentioned in my guess above, I do think $\dim W = \dim V$ (Condition 2) is I think a way to rectify the problem in p.8 for finite dimensional $V$ and $W$, but for infinite dimensional $W$ and $V$, is the analogue of Condition 2 indeed Condition 1?
Comment: @reuns Thanks! about almost complex structures: in the book of Daniel Huybrechts, Complex Geometry An Introduction, for vector space $V$, an almost complex structure is defined as $J: V \to V$ and a complex structure is defined as $s_V^{\#}: \mathbb C \times V \to V$. Of course, there are bijections between the two notions, proving that they are equivalent notions for $\mathbb R$-vector spaces. I think it's just convention. I know for vector spaces wikipedia just says '[linear complex structure](https://en.wikipedia.org/wiki/Linear_complex_structure)'
Comment: @reuns So, $\mathbb C W = \mathbb C-span W$?
Comment: @reuns About $\mathbb C W$, Question 1. Is my proposed definition of internal complexification of $W$ in $V$, which is the unique subspace $X$ of $V$ such that internally $X_{\mathbb R} = W \bigoplus Wi$, equivalent to what Conrad might have meant which is $\mathbb C W$ and $\dim W = \dim V$?
Comment: @reuns About $\mathbb C W$, Question 2. Is '$\dim W = \dim V$ and $V = \mathbb C W$' equivalent to 'any $\mathbb R$-basis of $V$ is a $\mathbb C$-basis of $W$' ?
Comment: @reuns About $\mathbb C W$, Question 3. In [Suetin, Kostrikin and Mainin 12.15 of Part I](https://i.stack.imgur.com/BAvYT.png), the authors seem to be talking about how complexification is or can be seen as (by some isomorphism I guess) a specific case of the more general notion of extension of scalars, as Wikipedia does. Is this then actually a generalisation of what one (or maybe just 'I' instead of 'one') might call internal rather than external complexification? (Note: i'm going to edit my question to include this)
Comment: @reuns I added a bounty to this question.
Comment: @reuns Never mind I figured it out. (see my answer below, if you want) You can answer if you want and then I'll award bounty to you I guess.
Comment: @reuns new question: [When or only when a complex vector space is the external complexification of a real vector space](https://math.stackexchange.com/questions/3527949/when-or-only-when-a-complex-vector-space-is-the-external-complexification-of-a-r)
Answer: Two things:

First thing:
Conrad actually gives the definition, of $\mathbb C$-vector space $V$ as the internal complexification of $\mathbb R$-subspace $W$ of $W$, just before Theorem 3.2 as $V=W + iW$ and $W \cap iW = 0$, which I think is equivalent to saying $V_{\mathbb R} = W \bigoplus iW$ I just wish 2 things.

That this definition was more explicit. Perhaps as something like

Definition 3.2 We say that $V$ is the internal complexification, or just complexification if the context is clear, of $W$ if $V=W + iW$ and $W \cap iW = 0$

That we could define internal complexifications of any $\mathbb R$-subspace $W$ of $V$ as something like $W \bigoplus iW$ or like $\mathbb C$-span$(W)$. In this case of $W \bigoplus iW$, I think we would have to restrict to considering $\mathbb R$-subspaces such that $W \cap iW = 0$, thus excluding $W = V_{\mathbb R}$

Second thing: The unresolved issue is whether or not Suetin, Kostrikin and Mainin has implicit notion for internal complexification such that it is internal and not external complexification that gets generalised by 12.15 of Part I (and 12.4 of Part I).


NgRx Effect - inner catchError executes multiple times

Question: I have an Angular app with NgRx, inside one of my effects I have a non expected behavior that, turns out, is expected, but I don't know how to fix it.
My minified code is
@Effect()
detelete$ = this.actions$
  .pipe(
    ofType<fromActions.DeleteRequested>(fromActions.ActionTypes.DeleteRequested),
    map(action => action.payload.id),
    mergeMap(id =>
      combineLatest([
        of(id),
        this.rservice.deleteById(id)
          .pipe(
            catchError((err, caught$) => {
              this.store.dispatch(new fromActions.DeleteCancelled({id: id}));
              return caught$;
            })
          )
      ])
    ),
    map(([id, ]: [string, any]) => {
      return new fromActions.DeleteSuccess({id: id});
    }),
  );

The reason I don't have my catchError on the same level as my mergeMap is that I need my id as payload for my fromActions.DeleteCancelled action. Plus, my service only returns a boolean, so I use combineLatest to persist it to my onSuccess map.
What I'm experiencing is this catchError is executing multiple times. Thus, dispatching my error action multiple times.
I foun that

If you return this source, the observable will effectively restart all over again and retry

In this case the source is my caught$.
If, inside my cacthError I return
  return of(new fromActions.DeleteCancelled({id: id}));

It will still go to my onSuccess map. I could maybe check if my second param inside that map is os type Action or boolean, but I think there's a proper way to handle it and I don't know it.
StackBlitz (uncomment subscribe to see infinite loop)
Thanks.
Comment: Can you try `return [new fromActions.DeleteCancelled({id: id})];`?
Answer: You could consider this approach. Your code could looks like below:
import { EMPTY, of, Observable } from 'rxjs';
...

@Effect()
delete$ = this.actions$.pipe(
  ofType<fromActions.DeleteRequested>(fromActions.ActionTypes.DeleteRequested),
  map(action => action.payload.id),
  switchMap((id) => this.rservice.deleteById(id).pipe(
    switchMap(result => {
      return result ? of(new fromActions.DeleteSuccess({id: id})) : EMPTY
    }),
    catchError(error => {
      return of(new fromActions.DeleteCancelled({id: id}))
    })
  )
)

if your service is returning true, so DeleteSuccess action is dispatched, else an empty observable that completes immediately.
Because EMPTY returns an observable, you have to use switchMap, and also of to return an observable of action DeleteSuccess.
In case of error, DeleteCancelled is dispatched.
Another approach could be to use @Effect({ dispatch: false }), and manually dispatch all needed actions.
Hope it will help.
Comment: It worked like a charm. Marked as accepted, thank you.


Can the event of kick-off going directly into the kicker's own goal described in the Laws of the Game ever occur?

Question: The Laws of the Game state that, for a kick-off:

a goal may be scored directly against the opponents from the kick-off; if the
  ball directly enters the kicker's goal, a corner kick is awarded to the opponents

I don't understand how this is possible :/
In every football match that I've seen, the kicker's kick goes straight into the opponent's half of the football field, as he stands facing his opponents. How then can the ball directly enter the kicker's own goal instead? The ball can't surely swing a 180deg U-turn mid-air to begin with...
Answer: You are assuming that the ball has to do a 180deg U-turn mid-air, whereas the new rule makes it possible to hit the ball directly towards own post.
LAW 8 - THE START AND RESTART OF PLAY

1.KICK-OFF
For every kick-off:
all players, except the player taking the kick-off, must be in their
own half of the field of play

and FAQ of this rule mentions

the kick-off can now be kicked in any direction

I haven't found any goal happening as you mentioned per this rule, but it may happen by mistake, when the player taking the kick-off hits it towards his own post.

Source
Answer: No one will probably ever see such a thing happening, but the rules are good when they are complete and consider nearly every possible scenario. Besides that, there's no rule disallowing the players to kick-off into their own half.
If you look at the Details of all Law changes - Law 08 – The Start and Restart of Play - 1. Kick-off, the following part has been added recently:

...if the ball directly enters the kicker's goal, a corner kick is
  awarded to the opponents

I assume as the first part of the rule considers the scenario of scoring directly against the opponents goal, the additional part was somehow needed to make the rule complete.
Answer: Are you confusing american fotball and soccer i.e. "european football"?
The kick-off in soccer is usually played backwards, towards your teammates. You cannot score an own goal from the kickoff, however you can, if the opposing team keeper is lounging and not paying attention, score against the opponent.
Very rarely is a soccer kickoff played "forward" - since no player can be on the opposing field before the kickoff, that is a fault and can award the other team a free kick. In american football, it is always played directly forward...
Comment: @Stian: until last year, it was mandatory that the kick-off was a forward pass. Only last year a pass back was allowed.
Comment: @studro Yes now I cannot edit edit it but I wanted to say if it goes in the goal it will be corner to other team.
Comment: @RamChandraGiri - semantics, but no, you cannot score an own goal from the kickoff. If it goes in the goal, it is not a goal. Your explanation is a little contradictory.
Comment: @Stian - the other team cannot receive a free kick for having players in the wrong half; the kick-off is simply retaken.

Can the event of kick-off going directly into the kicker’s own goal described in the Laws of the Game ever occur?


weird behavior in tableview iphone

Question: This is kind of weird. I have a table view in my app which is showing fetched data from the database. If i scroll down and select a cell the text would change and a line of text from some previous cell will be placed above the current selected cell's text. I know this might be due to the reuseIdentifier, but i have no idea how to fix that. Here's the code i'm using:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UILabel* labelCourse;
    UILabel* labelPlace;

    static NSString *kCellID = @"cellID";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];

    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    }

    Course *course = nil;
    if (tableView == self.searchDisplayController.searchResultsTableView)
    {
        course = [self.filteredListContent objectAtIndex:indexPath.row];
    }
    else
    {
        course = [self.courses objectAtIndex:indexPath.row];
    }

    CGRect labelCourseFrame = CGRectMake(10, 10, 290, 25);
    labelCourse = [[UILabel alloc] initWithFrame:labelCourseFrame];
    labelCourse.font = [UIFont systemFontOfSize:14.0];
    labelCourse.font = [UIFont boldSystemFontOfSize:18];
    [cell.contentView addSubview:labelCourse];

    CGRect labelPlaceFrame = CGRectMake(10, 35, 290, 25);
    labelPlace = [[UILabel alloc] initWithFrame:labelPlaceFrame];
    labelPlace.font = [UIFont systemFontOfSize:12.0];
    labelPlace.textColor = [UIColor darkGrayColor];
    [cell.contentView addSubview:labelPlace];

    labelCourse.text = course.name;
    labelPlace.text = course.location;

    [labelCourse release];
    [labelPlace release];
//    cell.textLabel.textColor = [UIColor colorWithHexString:@""];

    return cell;
}

Any ideas?
Thanks in advance.
Answer: You can move the creation part to inside the if clause that creates a new cell.
if (cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    CGRect labelCourseFrame = CGRectMake(10, 10, 290, 25);
    labelCourse = [[UILabel alloc] initWithFrame:labelCourseFrame];
    labelCourse.font = [UIFont systemFontOfSize:14.0];
    labelCourse.font = [UIFont boldSystemFontOfSize:18];
    [cell.contentView addSubview:labelCourse];

    CGRect labelPlaceFrame = CGRectMake(10, 35, 290, 25);
    labelPlace = [[UILabel alloc] initWithFrame:labelPlaceFrame];
    labelPlace.font = [UIFont systemFontOfSize:12.0];
    labelPlace.textColor = [UIColor darkGrayColor];
    [cell.contentView addSubview:labelPlace];

    labelCourse.tag = 50;
    labelPlace.text = 51;

    [labelCourse release];
    [labelPlace release];
}

As you see I've attached tags to the views so that I can retrieve the labels when the cells are being reused. Now get the labels,
UILabel * labelCourse = [cell viewWithTag:50];
UILabel * labelPlace = [cell viewWithTag:51];

and set them,
labelCourse.text = course.name;
labelPlace.text = course.location;

Comment: You can cast it. `UILabel * labelCourse = (UILabel *)[cell viewWithTag:50];`
Comment: So in conclusion, the tags did the trick? Thanks, it's working now. You've saved my day.
Comment: Yes, for this case. You can also think of creating a custom cell so that you can directly use the properties (assuming labels are declared as properties in the custom cell) rather than having to use the tags.
Comment: This is actually not working as i expected. The cells are showing the wrong values. I don't know if it's because i'm reusing these tags. I get the same value like 5 times meaning that old values are replacing the new ones. What could be the cause?
Comment: @Ernesto Just to confirm, is your `cellForRowAtIndexPath:` method same as in [`this pastie`](http://pastie.org/2137294).
Comment: i didn't have it like that, i used your pastie and it's working, for now. I was setting the text inside the `if(cell == nil)` i guess that was the problem. Now in the ``UILabel * labelCourse = [cell viewWithTag:50]; i get a warning `Semantic Issue: Incompatible pointer types initializing 'UILabel *' with an expression of type 'UIView *' Thanks for the help.
`

weird behavior in tableview iphone


Em termos de desempenho, qual o melhor modo de declarar uma variável que será usada em várias Actions/Métodos em uma classe?

Question: Qual modo é melhor performaticamente falando?
Qual modo vocês recomendam e por que?
//Modo 1
MeuManager mm = new MeuManager();

JsonResponse MetodoDOIS(string urlImagem)
{
    var abc = mm.Lista();
}

JsonResponse MetodoUM(ImageUploadContent imageUpload)
{
    var abc = mm.Lista();
}

//Modo 2
JsonResponse MetodoDOIS(string urlImagem)
{
    MeuManager mm = new MeuManager();
    var abc = mm.Lista();
}

JsonResponse MetodoUM(ImageUploadContent imageUpload)
{
    MeuManager mm = new MeuManager();
    var abc = mm.Lista();
}

Answer: Em termos de desempenho provavelmente o modo 1 é mais rápido, porque terá que instanciar apenas uma vez contra a outra forma que possivelmente será instanciado mais vezes. Aí também há fatores não determinísticos. Pode até ocorrer uma pequena diferença por ajudar encher o cache, pressionar o garbage collector por mais tempo ou com mais objetos, ou algo assim, mas nada diretamente relacionado.
Mas não é tão simples, depende de como e quanto os métodos serão chamados, quantas classes desse tipo existirão e outras coisas que nem consigo pensar agora. Performance real é algo complicado a não ser em algo muito contido.
Variáveis de instância só deveriam existir se elas fazem parte do objeto. Isso normalmente indica que você precisa ter só uma instância nesse objeto. Claro que precisa ser pragmático, pode ser que o desempenho seja realmente muito importante, mas a semântica correta é mais importante. E olhe que nem estou falando de legibilidade ou facilidade de manutenção.
Se só deve ter um gerenciador por objeto, é estranho criar um em cada método. Se deve ter mais que um, então não deveria estar no objeto.
Pode ser que nem deveria estar no método, nem na instância, deveria estar na classe (estático). Não tem contexto para saber. Essa seria ainda mais rápida porque só existiria uma instância para toda aplicação. Tem desvantagens também.
De qualquer forma a diferença de velocidade será mínima. Provavelmente tem outros lugares que haverá mais benefício, talvez nem ter essa classe MeuManager se for pertinente.
Comment: Valeu a resposta, não da p/ ser estático (não é uma classe do sistema, é de uma .dll 3ª), seguindo o que você falou, vou usar o modo 1, além de ser PARTE do objeto, essa instancia declarada desse modo facilita a leitura (na minha opinião), muito obrigado.


How to find the most shared species between 3 groups with DPLYR

Question: I'm looking to find the most common species ("spid" variable, which is a code made with the 4 first letters of the genus name and then the 4 first letter of the species name) in a data frame where there is different habitats (variable "hab", modalities : TA,TB,TC).
I don't know how I can apply the "max n" ("slice(which.max(n))") on each habitat to select the species that are the most common for those habitats. As an exemple, if a species has been counted 50 times in 1 habitat and 0 time in the others, compared to a species that has 10 counts in each habitat, the last one would be the more common.
Here is the code I started with :
brk %>%
  dplyr::select(spid,hab)%>%
  dplyr::group_by(spid) %>%
  dplyr::mutate(n = length(unique(hab))) %>%
  filter(n == 3)

As first I thought to filter the species that are in the 3 habitats but I couldn't select those species. But then how can I apply my "max" function to select the most shared species ? Is a "apply" function a good approach ?
Here is a reproductible code :
library(dplyr)

brk%>%
  dplyr::select(spid,hab)%>%
  dplyr::sample_n(20)%>%
  dput()

structure(list(spid = structure(c(157L, 21L, 181L, 128L, 191L,
197L, 202L, 122L, 179L, 150L, 15L, 162L, 43L, 202L, 154L, 179L,
57L, 229L, 231L, 183L), .Label = c("ACROEMER", "ACROMEGA", "AEROSUBPM",
"AMAZDIPL", "ANASAURI", "ANASPILI", "ANDRABER", "ANDRBILO", "ANEULATI",
"BAZZDECR", "BAZZDECRM", "BAZZMASC", "BAZZNITI", "BAZZPRAE",
"BAZZROCA", "BRACEURY", "BUCKMEMB", "CALYARGU", "CALYFISS", "CALYMASC",
"CALYPALI", "CALYPERU", "CAMPARCTM", "CAMPAURE", "CAMPCRAT",
"CAMPFLEX", "CAMPJAME", "CAMPROBI", "CAMPTHWA", "CEPHVAGI", "CERABELA",
"CERACORN", "CERAZENK", "CHEICAME", "CHEICORDI", "CHEIDECU",
"CHEIMONT", "CHEISERP", "CHEISURR", "CHEITRIF", "CHEIUSAM", "CHEIXANT",
"COLOCEAT", "COLOHASK", "COLOHILD", "COLOOBLI", "COLOPEPO", "COLOTANZ",
"COLOZENK", "COLUBENO", "COLUCALY", "COLUDIGI", "COLUHUMB", "COLUOBES",
"COLUTENU", "CONOTRAP", "CRYPMART", "CUSPCONT", "CYCLBORB", "CYCLBREV",
"CYLIKIAE", "DALTANGU", "DALTLATI", "DENDBORB", "DICRBILLB",
"DIPLCAVI", "DIPLCOGO", "DIPLCORN", "DREPCULT", "DREPHELE", "DREPMADA",
"DREPPHYS", "ECTRREGU", "ECTRVALE", "FISSASPL", "FISSMEGAH",
"FISSSCIO", "FRULAPIC", "FRULAPICU", "FRULBORB", "FRULCAPE",
"FRULGROS", "FRULHUMB", "FRULLIND", "FRULREPA", "FRULSCHI", "FRULSERR",
"FRULUSAMR", "FRULVARI", "FUSCCONN", "GOTTNEES", "GOTTSCHI",
"GOTTSPHA", "GROULAXO", "HAPLSTIC", "HERBDICR", "HERBJUNI", "HERBMAUR",
"HETEDUBI", "HETESPLE", "HETESPN", "HOLOBORB", "HOLOCYLI", "HYPNCUPR",
"ISOPCHRY", "ISOPCITR", "ISOPINTO", "ISOTAUBE", "JAEGSOLI", "JAEGSOLIR",
"KURZCAPI", "KURZCAPIS", "LEJEALAT", "LEJEANIS", "LEJECONF",
"LEJEECKL", "LEJEFLAV", "LEJELOMA", "LEJEOBTU", "LEJERAMO", "LEJETABU",
"LEJETUBE", "LEJEVILL", "LEPIAFRI", "LEPICESP", "LEPIDELE", "LEPIHIRS",
"LEPISTUH", "LEPISTUHP", "LEPTFLEX", "LEPTINFU", "LEPTMACU",
"LEUCANGU", "LEUCBIFI", "LEUCBORY", "LEUCCANDI", "LEUCCAPI",
"LEUCCINC", "LEUCDELI", "LEUCGRAN", "LEUCHILD", "LEUCISLE", "LEUCLEPE",
"LEUCMAYO", "LEUCSEYC", "LOPHBORB", "LOPHCOAD", "LOPHCONC", "LOPHDIFF",
"LOPHEULO", "LOPHMULT", "LOPHMURI", "LOPHNIGR", "LOPHSUBF", "MACRACID",
"MACRMAUR", "MACRMICR", "MACRPALL", "MACRSERP", "MACRSULC", "MACRTENU",
"MASTDICL", "METZCONS", "METZFURC", "METZLEPT", "METZMADA", "MICRAFRI",
"MICRANKA", "MICRDISP", "MICRINFL", "MICRKAME", "MICROBLO", "MICRSTRA",
"MITTLIMO", "MNIOFUSC", "PAPICOMP", "PLAGANGU", "PLAGDREP", "PLAGPECT",
"PLAGRENA", "PLAGREPA", "PLAGRODR", "PLAGTERE", "PLEUGIGA", "PLICHIRT",
"POLYCOMM", "POROELON", "POROMADA", "POROUSAG", "PRIOGRAT", "PSEUDECI",
"PTYCSTRI", "PYRRSPIN", "RACOAFRI", "RADUANKE", "RADUAPPR", "RADUBORB",
"RADUBORY", "RADUCOMO", "RADUEVEL", "RADUFULV", "RADUMADA", "RADUSTEN",
"RADUTABU", "RADUVOLU", "RHAPCRIS", "RHAPGRAC", "RHAPRUBR", "RICCAMAZ",
"RICCEROS", "RICCFAST", "RICCLIMB", "RICCLONG", "SCHLBADI", "SCHLMICRO",
"SCHLOANGU", "SCHLSQUA", "SEMACRAS", "SEMASCHI", "SEMASUBP",
"SERPCYRT", "SOLEBORG", "SOLEONRA", "SOLESPHA", "SPHATUMI", "SPHEMINU",
"SYRRAFRI", "SYRRAPER", "SYRRDIMO", "SYRRGAUD", "SYRRHISP", "SYRRPOTT",
"SYRRPROL", "SYRRPROLA", "SYZYPURP", "TAXICONFO", "TELACOAC",
"TELADIAC", "TELANEMA", "TRICADHA", "TRICDEBE", "TRICPERV", "ULOTFULV",
"WARBLEPT", "ZYGOINTE", "ZYGOREIN"), class = "factor"), hab = structure(c(3L,
2L, 2L, 1L, 1L, 2L, 3L, 2L, 3L, 1L, 2L, 3L, 3L, 2L, 1L, 2L, 2L,
1L, 1L, 2L), .Label = c("TA", "TB", "TC"), class = "factor")), row.names = c(NA,
-20L), class = "data.frame")

Thank you for your help,
Germain V
Answer: We can try
library(dplyr)
brk %>%
   group_by(spid) %>%
   summarise(n = n_distinct(hab)) %>%
   slice(which.max(n))

Answer: Thank you for your answer
I would like to have a list with the species (the code spid) that are the most common between those 3 habitats, based on the effectif of those species in each habitat.
spid        n_TA    n_TB    n_TC
DREPPHYS    6        1       1
BUCKMEMB    4        4       4
LEIJCOLE    0        0       0

In this random exemple (I've a total of 246 species) I would like to make a compute on this array to select the "most common" or "most sharred species" - in this case that should be BUCKMEMB, then DREPPHYS   and finaly LEIJCOLE.
Maybe "max" function isn't a good approach ?


How to add sources from qml modules to qt_add_translations in Qt6 CMake?

Question: I am having trouble with setting up translation files in my Qt6 application using CMake.
I think my issue is not restricted to qml files, but I will use here only qml files to keep my case simple.
I'm working on a project with submodules to organize my cpp and qml files.
As an example, lets say I have a root project called appTestLocalization containing a Main.qml and a module MyModule in a directory MyModule containing a MyText.qml.
Each of the qml files contains one qsTr() in them.
I want to add localizations to my app, and following the qt doc I add a qt_add_translations() like that in the CMakeLists.txt of the root project:
qt_add_translations(appTestLocalization TS_FILES i18n/lang_fr_FR.ts)

Then in Qt Creator I do Ctrl+K and I run cm update_translations (or cm appTestLocalization_lupdate but the result is the same)
However, the resulting ts files contain only the qsTr from the Main.qml.
So I've tried to add the module directory manually like that but the result is the same:
qt_add_translations(appTestLocalization
INCLUDE_DIRECTORIES
    MyModule
TS_FILES
    i18n/lang_fr_FR.ts)

I also tried to add a translation in the module's CMakeLists.txt too:
qt_add_translations(mymodule TS_FILES ${CMAKE_SOURCE_DIR}/i18n/lang_fr_FR.ts)

But it overwrites the translations from the the root project...
How could I add module files to the Qt translation process?
EDIT:
I know I can add the files I want using the SOURCE argument like that:
qt_add_translations(appTestLocalization
    #SOURCES
        Main.qml
        MyModule/MyLabel.qml
    TS_FILES
        i18n/lang_fr_FR.ts
)

But it seems a "wrong" way as we could have a lot of files in several modules. This would be a nightmare to maintain and I would like to avoid that.
I have also tried passing -recursive to lupdate despite it should be the default, but it didn't work either:
qt_add_translations(appTestLocalization
    LUPDATE_OPTIONS -recursive
    TS_FILES
        i18n/lang_fr_FR.ts
)

Comment: You could try explicitly using the SOURCES field to add all of your source files.
Comment: @JarMan
Yeah it works, but I would rather avoid writing dozens of files in several modules. Besides it seems "wrong" to do that, it would be a nightmare to maintain and track down missing files. I will update my question to add that in it.
Comment: So why don't you use [`file(GLOB_RECURSE`](https://cmake.org/cmake/help/latest/command/file.html#glob-recurse)?
Comment: I just did some research, and it seems that using multiple targets is added in future versions. https://codereview.qt-project.org/c/qt/qttools/+/495546
Answer: As mentioned by @smr you can scan the files to translate recursive. This is how we add translations to our application also build up of a bunch of modules:
file(GLOB_RECURSE QML_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} *.qml)

qt_add_translations(${EXECUTABLE_NAME} TS_FILES
    ${EXECUTABLE_NAME}_de_DE.ts
    ${EXECUTABLE_NAME}_en_EN.ts
    SOURCES ${QML_SOURCES}
    RESOURCE_PREFIX "/translations"
    LUPDATE_OPTIONS -no-obsolete
)

Comment: Does the `GLOB_RECURSE` will be properly updated? The [doc]() says `We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate`
Comment: Indeed you have to run CMake by hand after adding a new file if you are using any GLOB function.
Comment: @BenPyton Running lupdate doesn't need to happen very often, so it shouldn't cause many problems. You can manually run CMake after you have finished making changes.
Comment: yeah okay, I have no other choice at this moment but this solution. As @smr said in a comment, `qt_add_translations` will support multiple targets in Qt 6.7. Would be great to update this answer when it will be out.


Permutations with repeated measures

Question: Let's say I have data from several mice with id id. Each mouse wandered around two mazes (A and B) and I gave a score at the end of the run (score).

dat <- data.frame(id=c(1, 1, 2, 2, 3, 3, 4, 4), maze=c("A", "B", "A",
        "B", "A", "B", "A", "B"), score=c(10, 21, 13, 9, 12, 16, 3,
        18))

      id maze score
    1  1    A    10
    2  1    B    21
    3  2    A    13
    4  2    B     9
    5  3    A    12
    6  3    B    16
    7  4    A     3
    8  4    B    18

I'd like to do a permutation test to test the difference between maze A and maze B.
Am I allowed to completely shuffle the scores:
    id  maze  score
    1    A     21
    1    B     3
    2    A     18
    2    B     10
    3    A     13
    3    B     9
    4    A     16
    4    B     12

or do I need to shuffle within maze (shuffle the A scores with A scores, and B scores with B scores):
    id  maze  score
    1    A     3
    1    B     9
    2    A     10
    2    B     16
    3    A     12
    3    B     21
    4    A     13
    4    B     18

Comment: Some mice will tend towards high scores, some mice will tend towards low scores independent of the Null you are investigating. So you should not shuffle  destroying the absolute within-mouse difference but only permute the assignment of each pair of measurements to a maze. Basically you compute the A - B value and take either that or it's negative B - A for each mouse.
Answer: Some mice will tend towards high scores, some mice will tend towards low scores independent of the Null you are investigating. As this is independend of our Null, we do not want to permute that. Mice with generally large scores can stay mice with large scores. Mice with two simlar scores in both mazes can stay mice with similar scores.
In the end you want to compute a difference of maze A and maze B scores per mouse and compare that to the permutation distribution. To investigate the relevance of maze, the assignment of any score to the maze is what needs to be permuted whilst keeping everything else the same.
For each mouse, we need to either relabel the maze B score as maze A score AND the maze A score as maze B score or not relabel anything. If the Null holds, that should be no problem.
This should insure not to destroy the absolute within-mouse differences but only permute the assignment of each pair of measurements to a maze.
In the end, we are interested in computing the $A - B$ value. When the assignment of the values to A and B are switched, that will be the same as multiplying the value to -1.
$A - B = -B + A = -1\times(B - A)$
So the easiest way computationally will be to once compute the difference A minus B and then randomly either multiply that by -1 or not.
dat <- data.frame(id=c(1, 1, 2, 2, 3, 3, 4, 4),
                  maze=c("A", "B", "A", "B", "A", "B", "A", "B"),
                  score=c(10, 21, 13, 9, 12, 16, 3, 18))

# convert that to a wide format

dat.wide <- merge(x = subset(dat, maze == "A"), y = subset(dat, maze == "B"),
                  by = "id")
print(dat.wide)

# compute differences

diff <- dat.wide$score.x - dat.wide$score.y  # these are the differences without permuting

# multiply any difference by -1 or 1 a large number of times

diffs <- replicate(1e5, {sample(c(-1, 1), length(diff), TRUE) * diff})

#plot cumulative density function of diffs to compare to the truely observed difference
plot(ecdf(colSums(diffs)),
     xlab = "sums of (permuted) differences in maze scores",
     ylab = "cummulative share",
     main = "")
abline(v = sum(diff), col = "red")
text(x = sum(diff), y = .8, labels = "true observation", col ="red")
axis(3, sum(diff), col.ticks = "red", col = "red")
axis(4, c(.025, .975), col = "red", labels = c("2.5%", "97.5%") )

(with 4 values we expect 16 possible permutations so there should be 15 change points  in this graph. However, in the given example, one true difference is 4 and one is -4, therefore there are less points in the graph)
Comment: @locus That sounds reasonable **IF** you intend to do a one tailed test.
Comment: Thank you @Bernhard, very useful! How would you compute a p-value out of this? Would this be correct?: `thresh <- colMeans(diffs) <= mean(diff)` `p.value <- sum(thresh)/1e5`
Comment: @Berhard, thanks! Just one last question, for publishing the results I would like to have a statistic along with p-value. For example, the `coin` package has a function `independence_test(outcome~treatment)` that [outputs a `Z`](https://towardsdatascience.com/permutation-test-in-r-77d551a9f891) as well as p-value. Can I also get a Z statistic using your example?
Comment: @locus I honestly do not know. Sorry.

Permutations with repeated measures


Different response using Python requests

Question: I'm trying to download an image from a URL using requests. Using browser or a REST client, like restlet chrome extension I can retrieve the normal content, a json, and a binary image that I can save to disk.
Using requests as response result I got almost same response headers, only Content-Length has a different value - 15 bytes instead of 35 kilobytes - and I can't found the binary image.
Trying to simulate the request made by the browser I configure the same request header, like this:
headers = {"Host": "cpom.prefeitura.sp.gov.br",
           "Pragma": "no-cache",
           "Cache-Control": "no-cache",
           "DNT": "1",
           "Accept": "*/*",
           "Accept-Encoding": "gzip, deflate, br",
           "Accept-Language": "en-US,en;q=0.9,pt;q=0.8",
           "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
                         "AppleWebKit/537.36 (KHTML, like Gecko) "
                         "Chrome/65.0.3325.181 Safari/537.36"
           }

r = requests.get(url, stream=True, headers=headers)

There's no redirects, I also debug and look the content of requests.model.Response but no success.
What I'm missing? I think that is a detail about the request, but I can't get it.
This my test:
url = "https://cpom.prefeitura.sp.gov.br/prestador/SituacaoCadastral/ImagemCaptcha?u=8762520"
r = requests.get(url, stream=True)

if r.status_code == 200:
    print(r.raw.headers)
    with open("/home/bruno/captcha/8762520.txt", "wb") as f:  # saving as text, since is not the png image
        for chunk in r:
            f.write(chunk)

This is the URL to download the image: https://cpom.prefeitura.sp.gov.br/prestador/SituacaoCadastral/ImagemCaptcha?u=4067913
And this the site with the captcha image: https://cpom.prefeitura.sp.gov.br/prestador/SituacaoCadastral
With a simple GET will get only a json response body, but inspecting the response you'll see the binary response, which is the image - ~36kb size.
EDIT: include images from restlet client
Request:

Response:
Comment: I can only get the 15 byte response with the small JSON, either with Chrome or Postman. Where/how are you getting the response with the image?
Comment: @jdehesa I included a sample request using restlet. Thanks
Answer: The difference is in the Cookie header. Restlet makes use of existing Chrome's cookies by default (see docs), but if you set the Cookie header to an empty string you will see you do not get the image. I you want to be able to retrieve the image from a Python script, you will need to obtain first a valid cookie making a request to another valid URL in the web app (for example the link with the form that you posted) and look into the Set-Cookie (see MDN docs for more information).
Comment: Hum, I see, restlet sets a `Cookie`. I will test this approach.
Comment: Is that, I'm making an another request, getting the `Set-Cookie` header and now I can get the image. Thanks


SQLite iPhone error,

Question: I am following through this tutorial and after completing it I am getting an error on build.
The error isn't associated with any line of source code though.
This is the error I get:
<code>Line Location Tool:0: collect2: ld returned 1 exit status
Line Location Tool:0: symbol(s) not found
Line Location Tool:0: -[todo initWithPrimaryKey:database:] in todo.o
Line Location Tool:0: "_sqlite3_bind_init", referenced from:
</code>
I'm not sure what the error is.
The tutorial is building for the iPhone 2.0 framework but I am building for 3.0.
Their libsqlite3.0.dylib is from the iPhone 2.0 SDK whereas mine is from the 2.2.1 SDK (that's the newest version that is over 1mb)
I've tried the 2.0, 2.2.1 and 3.0 framework libsqlite3.0.dylib files, they all provide this same error.
Could anyone give me some advice on what to do here?  I've tried googling the error and I get nothing at all.
I was getting more errors similar to this one until I realized that I was using the libsqlite3.0.dylib from the OS X SDK not the iPhone SDK.  Once I switched that I only had this error left.
Comment: It's a typo. http://meta.stackexchange.com/q/196985/232821
Answer: Was a typo.
sqlite3_bind_init was supposed to say:
sqlite3_bind_int
init vs int.
Oops!
Bye!

SQLite iPhone error,


How to manage raw data (bitstream or bytestream) in .NET 4.0?

Question: My C# .NET 4.0 application needs to access data in the filesystem and access them as a bitstream or bytestream. What I need is the following:

Splitting a data block into two sequential data blocks.
Merging two datablocks by attaching one to the other.
Access bytes or bits.
Storing the data block in the filesystem.
Loading a data block from the filesystem.

That's it. What is the best practice to do this in .NET 4.0?
Thankyou
Comment: Have you tried the Stream API, in particular FileStream?
Answer: Start reading this: C# Input/Output Classes Simplified


How to schedule API calls in a "for" loop with a counter?

Question: I have a function with a for loop and inside the for loop, it pulls API data.
I would like to pause for an hour once the API calls reaches 450.
I have set up a counter and made another if statement but I'm not sure if this is right.
def master_function():
   test_data = sev_one_api_calls.get_all_catchpoint_tests()
   flat_getAll = pd.DataFrame([flatten_json(test_data[key]) for key in test_data])

   count = 0
   concat_data = pd.DataFrame()
   for test_name, test_details in test_data.items():
       id = test_details.get('id') # pull id out of get_all_tests
       print(test_name, id)
       # feed in id to get_test_detail function.
       test_detailed_data = sev_one_api_calls.get_catchpoint_test_detail(id)

       # if id is in get_test_detail, flatten all id details and add it up.
       if test_detailed_data is not None:
           flat_detailed_data = json_to_dataframe(test_detailed_data)  # flatten id details into df
           # add up all results from test_detailed_data
           concat_data = pd.concat([concat_data, flat_detailed_data], ignore_index=True)
           # else if get_test_detail returns None, move on to the next id.
       else:
           continue

       count += 1
       if count >= 450:
           schedule.every().hour.do(master_function()) # wait for an hour and call again.
           while True:
               # Checks whether a scheduled task
               # is pending to run or not
               schedule.run_pending()
               time.sleep(1)

   combined = pd.merge(flat_getAll, concat_data, on='id', how='outer', left_index=True,
                     right_index=True, suffixes=('', '_remove'))

   # remove the duplicate columns
   combined.drop([i for i in combined.columns if 'remove' in i],
               axis=1, inplace=True)

   df = combined.groupby('id', as_index=False).first()
   df.to_csv('../../data/COMBO.csv', index=False)

Comment: no i imported schedule
Comment: How would you fix this?
Answer: I have no way of testing this so there might be bugs.  But here is an example of one way you could alter your code to make it work.  This should at least give you an example of how the scheduler works and should point you in the right direction.
def master_function():
    test_data = sev_one_api_calls.get_all_catchpoint_tests()
    flat_getAll = pd.DataFrame([flatten_json(test_data[key]) for key in test_data])
    concat_data = pd.DataFrame()
    schedule.every().hour.do(runloop,(test_data, concat_data))
    while True:
        schedule.run_pending()
        time.sleep(0.1)

def runloop(test_data, concat_data):
    count = 0
    for test_name, test_details in test_data.items():
        id = test_details.get('id') # pull id out of get_all_tests
        print(test_name, id)
        test_detailed_data = sev_one_api_calls.get_catchpoint_test_detail(id)
        if test_detailed_data is not None:
            flat_detailed_data = json_to_dataframe(test_detailed_data)
            concat_data = pd.concat(
                [concat_data, flat_detailed_data], ignore_index=True
            )
            count += 1
        if count == 450:
            break
    combined = pd.merge(flat_getAll, concat_data,
                        on='id', how='outer', left_index=True,
                        right_index=True, suffixes=('', '_remove'))
    combined.drop([i for i in combined.columns if 'remove' in i],
                   axis=1, inplace=True)
    df = combined.groupby('id', as_index=False).first()
    df.to_csv('../../data/COMBO.csv', index=False)

master_function()


Blockwise RSA encryption using Bouncy Castle in java

Question: In C#, I am encrypting the text data by doing something like below (please notice that I am encrypting the data in chunks (blocks):
        public string EncryptData(string publicKey, string data)
        {
            try
            {
                var bytesToEncrypt = Encoding.UTF8.GetBytes(data);
                int srclen = bytesToEncrypt.Length;

                //Prepare encryption engine
                var encryptEngine = new Pkcs1Encoding(new RsaEngine());

                //Initialize Key
                using (var txtreader = new StringReader(publicKey))
                {
                    var keyParameter = (AsymmetricKeyParameter)new PemReader(txtreader).ReadObject();
                    encryptEngine.Init(true, keyParameter);
                }

                //Encrypt in loop
                byte[] complete = new byte[0];
                int src_block_size = encryptEngine.GetInputBlockSize();
                for (int idx = 0; idx < srclen; idx += src_block_size)
                {
                    int data_len = srclen - idx;
                    if (data_len > src_block_size)
                    {
                        data_len = src_block_size;
                    }

                    var encryptedChunk = encryptEngine.ProcessBlock(bytesToEncrypt, idx, data_len);
                    complete = CombineByteArrays(complete, encryptedChunk);
                }

                var finalString = Convert.ToBase64String(complete);
                return finalString;
            }
            catch (InvalidCipherTextException)
            {
                //catch exception
            }
        }

Now, I need to do provide the same encryption logic to some java guy (I am not at all familiar with java). Right now this is how they are doing it:
public static byte[] encrypt(byte[] text, PublicKey key) throws Exception
    {
        byte[] cipherText = null;
        //
        // get an RSA cipher object and print the provider
        Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");

        // encrypt the plain text using the public key
        cipher.init(Cipher.ENCRYPT_MODE, key);
        cipherText = cipher.doFinal(text);
        return cipherText;
    }

So, sometimes decryption (which is happening on .Net based server) fails with error "input too large for RSA cipher." So I am suspecting that it could be because of the difference in logic of encrypting and decrypting the data (encryption is happening on java based client with the logic posted above and decryption is happening on .Net based client with below logic):
public string DecryptData(string privateKey, string base64Data)
        {
            try
            {
                var bytesToDecrypt = Convert.FromBase64String(base64Data);
                AsymmetricCipherKeyPair keyPair;
                //var internalEngine = new RsaEngine();
                var decryptEngine = new RsaEngine(); //No paddind. We'll hunt the data inside packets
                using (var txtreader = new StringReader(privateKey))
                {
                    keyPair = (AsymmetricCipherKeyPair)new PemReader(txtreader).ReadObject();
                    decryptEngine.Init(false, keyPair.Private);
                }

                //Loop por todo el bloque y saca data
                byte[] complete = new byte[0];
                int blockSize = decryptEngine.GetInputBlockSize();
                for (int chunkPosition = 0; chunkPosition < bytesToDecrypt.Length; chunkPosition += blockSize)
                {
                    //int chunkSize = Math.Min(blockSize, bytesToDecrypt.Length - ((chunkPosition / blockSize) * blockSize));
                    int chunkSize = bytesToDecrypt.Length - chunkPosition;
                    if (chunkSize > blockSize)
                    {
                        chunkSize = blockSize;
                    }

                    var decryptedChunk = decryptEngine.ProcessBlock(bytesToDecrypt, chunkPosition, chunkSize);

                    //the actual decrypted data is in the middle, locate it!
                    int idxFirstZero = -1;
                    int outlen = decryptedChunk.Length;
                    int idxNextZero = (int)outlen;
                    for (int i = 0; i < outlen; i++)
                    {
                        if (decryptedChunk[i] == 0)
                        {
                            if (idxFirstZero < 0)
                            {
                                idxFirstZero = i;
                            }
                            else
                            {
                                idxNextZero = i;
                                break;
                            }
                        }
                    }

                    var totalSizeToCopy = idxNextZero - idxFirstZero - 1;
                    Array.Resize(ref complete, complete.Length + totalSizeToCopy);
                    int dstOffset = complete.Length - totalSizeToCopy > 0 ? complete.Length - totalSizeToCopy : 0;
                    Buffer.BlockCopy(decryptedChunk, idxFirstZero + 1, complete, dstOffset, totalSizeToCopy);
                }

                var finalString = Encoding.UTF8.GetString(complete).Trim('\0');
                return finalString;
            }
            catch (InvalidCipherTextException)
            {

            }
        }

So as you can see I am decrypting the data in blocks. So my question is how can we do the encryption in java (using bouncy castle) blockwise (the way I am doing in .Net in the very first code snippet in the post)?
Comment: Is this supposed to be a learning exercise? If not, please throw away your code and implement proper [hybrid encryption](https://en.wikipedia.org/wiki/Hybrid_cryptosystem). RSA should not be used as a block cipher. You should encrypt your message with AES and encrypt the random AES key with RSA.
Comment: *"... I am encrypting the data [with RSA] in chunks (blocks) ..."* - ***IF*** you are applying RSA to each block, then that's called operating RSA in ECB mode. The [Handbook of Applied Cryptography](http://cacr.uwaterloo.ca/hac/) specifically warns against the practice.
Answer: This is not a common operation as for large data (and even smaller data) usually hybrid encryption is used, where a mode of operation (such as CBC) of a symmetric cipher is used to encrypt larger data object.
As far as I know there is no direct way to request the maximum input size of RSA / PKCS#1 from the Cipher instance.
However, that's not much of an issue as you can calculate this yourself given the RSA key size. And this key size is the same as the size of the modulus (in bytes):

calculate the modulus size in bytes: (keysize - 1) / Byte.SIZE + 1 or, if the keysize is a multiple of 8 (as usual), just keysize / Byte.SIZE of course;
subtract 11 bytes from the result (for PKCS#1 v1.5 padding);

to get to the keysize, just cast your key to an RSAPublicKey and then call getModulus() followed by bitLength() on the resulting BigInteger.

Note that sending ciphertext without integrity protection (e.g. a signature) is not considered very secure. PKCS#1 may also fall victim to padding oracle attacks, especially when use in transport mode security. RSA / OAEP would be a better choice, used for hybrid encryption (as RSA /OAEP will store even less).


want to ask if there is a way that I can display a field from another content type to a field of another content type

Question: Im quite new to drupal (7) and want to ask if there is a way that I can display a field from another content type to a field of another content type and applying condition at the same time?
Here is the scenario:
I have created content types: Courses and Course schedules
I will be creating more than 50 contents for courses (containing their description, objectives etc as fields).
I will create different course schedule contents (data in here changes regularly including fields like time, date, venue, etc).
What i want to accomplish is to display the course article with a field that is linked to the courses schedule content, thus showing the available class sched data for each course.
I dont want to do it with views because im thinking it would be tedious to create a view for each course.
Is there a best way you can recommended to accomplish this? or is there a module that does this?
Thanks so much for your time.
Answer: You can use the entity reference module for accomplishing your requirements.
On the "Courses" content type you will add a field type entity reference which refer to the "Course Schedules" content type.
Then in the "Courses" content type Manage Display, You can choose that the referred node link to appear, I think you can also choose that the rendered node to appear.
Comment: Additionally, using Inline Entity Form (https://www.drupal.org/project/inline_entity_form), you can create and manage the Schedule from the Course or vice verse.


How to continue to statement2 while processing errors from statement1 with window.onerror

Question: I use window.onerror(message,url,line) to log my error messages because it gives me more debug information than try{}catch(e){}.
However, consider the following:
function1(); // Generates error
function2(); // Will not be executed

How can I ensure that function2 will fire while still using window.onerror?
Comment: Hi, just updated my js fiddle, so that you get the url and line numbers like you wanted when using a try-catch block, let me know if it works
Answer: You cannot. If you need error handling that allows later code to execute anyway you must use try..catch.
Luckily JavaScript does not have anything equivalent to VB6's On Error Resume Next; it would make lots of the bad JavaScript code out there much worse.
Comment: So is there a way to use try...catch in combination with window.onerror? I have two pieces of javascript example code on my site which I want to run. Both contain an error, which I catch and show alongside the code. How can I run both pieces of code?
Comment: When catching an error it will not trigger the global onerror handler. So nope, you cannot combine these. Why do you expect your code to fail in a way where the exception itself is not sufficient though?
Comment: I want to know the lineNumber where the code fails. The Error object does not give that away easily.
Answer: made a fork of your fiddle here, all I did was trigger the window.onerror event explicitly with the caught error.
Seems almost to good to be true :)
try
{
    function2();
}
catch(error)
{
    window.onerror(error);
}

UPDATE
Found a way to get the line number and url all the same. The code is a bit messy at the moment, but working, so it should get you started...
try
{
    function1();
}
catch(error)
{
    var url = error.stack.split('\n')[1].match(/\(.+\)/g)[0];
    var line = url.match(/\/\:[0-9]+.+$/g)[0];
    url = url.replace('(','').replace(line,'');
    line = line.replace(')','').replace('/:','')
    window.onerror(error,url,line);
}

and Here is the working jsfiddle
Comment: It *is* to good to be true ;) This way, you fill 'message' of window.onerror, but leave url and line undefined. See http://jsfiddle.net/sBw6u/2/. It is both 'message' and 'line' that I want to be filled. Still upvote for thinking along :)
Comment: I knew there had to be a catch :)
Comment: error.stack is not defined in IE, so this will not work cross-browser... Other than that: works well in Chrome! In Firefox, only the first function is executed...
Comment: I thougt there might be some issues with IE... [check this](http://eriwen.com/javascript/js-stack-trace/) article out, it's a very good cross browser stack tracer
Comment: I know that one. It checks the caller recursively to get the Stack Trace. The only thing that misses in IE... is the linenumber :-)
Comment: yup, I'm afraid MS doesn't like people writing code that actually provides useful information to users :-)
Answer: In the meantime, I've found a way using setTimeout, but I hope there might be a better way:
setTimeout(function1);
setTimeout(function2);

See http://jsfiddle.net/7y2Ej/1/


How Can make Toast.makeText in Google map?

Question: I want to know how can make 'Toast.makeText`to tell me the order of the cities  in the path
code :
<code>        shortest = TSP.tsp(Matrix);

        for(int i=0; i < 20 ; i++)
        {

            googleMap.addPolyline(new PolylineOptions().geodesic(true)
                            .add(new                   LatLng(placeLatitude[shortest[i]],placeLongitude[shortest[i]]))
                            .add(new LatLng(placeLatitude[shortest[i+1]],placeLongitude[shortest[i+1]]))
            );
        }

    }
</code>
Comment: Please consider putting a minimal code example for your problem, and refocussing your question on your problem, people don't need to know what is the purpose of your application for answering, only that you need to display a `toast` over a google map overlay, the code you provided to assist you is way too long !
Comment: Do you have  experience in the  google map in  Android @dvhh
Answer: Here is full description on toast. And I'm guessing you can record the cities being added in order in a String array and run a for loop to append it to your text to be displayed on toast message.


Dividing datasets into fully-correlating subsets

Question: I have a dataset of $N$ variables of which I know that (at least) one combination of their disjoint subsets results in non-negative correlation coefficients for all variables in these subsets. The subsets might have a different number of elements.
For example: The variables $A,B,C,D,E,F$ have the following correlation coefficient matrix (only showing the upper triangle)
<code>    A     B     C     D     E     F
A   1     0.32  0.3   0.04 -0.03 -0.02
B   0     1     0.3   0.08 -0.03  0.01
C   0     0     1     0.01  0.02  0.02
D   0     0     0     1     0.28  0.3
E   0     0     0     0     1     0.3
F   0     0     0     0     0     1
</code>
In this case, a complete description of this data in positive-only correlations would be $\{A,B,C\}$ and $\{D,E,F\}$ (The sub-matrices of these two sets only contain positive correlation coefficients). Another possible combination is $\{A,B,C,D\}$ and $\{E,F\}$ (as is $\{A,B\}, \{C,D\}, \{E,F\}$).
In the example above, $\{A,B,C\}$ and $\{D,E,F\}$ was indeed the looked-for combination, but I cannot find a way to favor this possibility of decomposition without prior knowledge. Since $D$ has a correlation coefficient close to $0$ (and has a higher absolute value with $\{A,B\}$ than with $\{E,F\}$), I don't see using the absolute value of the correlation coefficients as the way to go.
As said, I know that there are such relations in my data, so I'm not trying to find something in the data that isn't there, I'm just trying to retrieve the inherent structure of the data.
Is there a clever way to find such a combination of subsets? If so, is there a generalization if such a decomposition of the data set exists, but does not use all $N$ variables (let's say in the example above, another variabe $G$ would be added which is just noise and thus might -- by chance -- be anti-correlating to any other number of variables)?
I have been looking into ways to do this by constructing a graph where the variables are the nodes and the edges describe only positive correlations. The cliques in this graph then represent all possible decompositions, but not only a complete one.
Answer: In general, this problem fits into the scope of community detection in networks, which is difficult to generalize and rather ill-defined.  However, there has been some progress focusing on the structure of correlation matrices: Community Detection for Correlation Matrices.  Unfortunately, very few methods will give you structure over only a subset of the graph, and I don't know any such methods designed for correlation matrices.  Perhaps an extension of link communities or OSLOM would be able to determine those subsets that are statistical significant.


How to get a mean from multiple categorical fields

Question: I have some census data on income I would love to analyze. But income, in the data, is split into different income groups, each group is a column containing the number of people in an area that earns A to B. If my explanation doesn't make any sense please look at the table below.
So basically I want to get the average income for an area. Can this even be done with data like this?
Comment: Back in the old days, when people summarized data to save space and computational effort, there were many well-known methods to cope with this problem. *Kendall's Advanced Theory of Statistics* describes Sheppard's Corrections, which I have explained in the thread at http://stats.stackexchange.com/questions/60256 .
Comment: O My Word!! whuber that is awesome. With my limited knowledge of stats it is taking me some time to understand Sheppard's Corrections. But it is absolutely wonderful. Thanks
Answer: You will probably not be able to get a good average income for an area without getting more specific data, but you might be able to attack this problem by making some approximations and checking them/following up.
Some assumptions you could make that come to my mind would be:

Assume that on average most people in any given bin is at the average for that bin.
If you want to be more slick you might have a better distribution within each bin. You could use this calculate the average in each bin and then you would be done. (eg maybe the distribution of data is log-normal)

The trick is if you can get the mean within a bin for an area you can then perform a weighted average. Most of the methods I listed would assume independence of the bin average as a function of area, but you might find that unacceptable. In that case you would need to try to reconstruct a function that calculates the average bin income as a function of area, which seems more ambitious than your original project.
Comment: Thanks, I agree this seems to become allot bigger than I thought. But there is nothing as exiting as a good challenge. Any way thanks for the great advice, your helping me allot to understand these type of thins better. I'm also going to look at Sheppard's Corrections as pointed out by whuber


Which of these are the best Data Science courses for an recent graduate economist?

Question: I have recently graduated from college in my country with a bachelor's degree in economics. In my country (Paraguay, a Latin American country) there is a big lack of data scientists/statiscians. I have now the temptation to enroll at the National University of Asunción (the best public university of my country) in order to pursue a bachelor's degree in statistics coursed fully online.
However, with all the problems that education at every levels here in my country, I feel that studying a new bachelor's degree won't be worth it. I think that it would be nicer to move at the same pace as the world moves right now.
I'm looking toward to two data science certificates/degrees online that are offered through udacity.com and statistics.com
The first one which I saw (Udacity.com Nanodegree in Data Science) made me an impression that it was designed in order to be prepared to land a job in Silicon Valley or Wall Street.
The second one (Statistics.com Certificate in Analytics for Data Science) made me an impression that it had more theoretical content in it's program, but it looked very well designed too.
But I have a very big doubt in choosing some of this kind of programs. The Statistics.com certificate is far expensive than the Udacity.com nanodegree (5 times more expensive). And I do not want to be frustrated for paying too much money and time for something that cannot be really worth it.
So, what do you recommend me to do? I trust in the expertise of the people here.
Comment: Well, I have a background in Linear Algebra, Probability and Statistics and Econometrics. However, I should take programming classes too, beyond the Python classes that I took. Thanks for your answers.
Comment: Are there any reputable code academies (code bootcamps) in your area? Specifically, for data science? As long as they have a track record of placing candidates at decent companies, it might be worth the investment.
Comment: Unfortunately reality here in my country is far different from the US reality. There isn't code bootcamps publicly known in my country, and if they exist, they may be opened only for the systems engineering students or related careers.
Comment: Does your university offer a career services department? Specifically, perhaps either the statistics or CS department could offer you advice on tracks for data science.
Comment: What are your current skills in terms of programming? Math? Linear algebra? Probability & statistics? Econometrics? How much regression and statistics did you have to do as part of your economics degree?
Comment: If you were in the U.S. university system, it sounds like what you might want to do is a 1 year masters degree in statistics or something similar. How long is the program you were considering at National University of Asunción?
Comment: If there's a huge demand to data scientists, then get a job.
Answer: At least in the US, online certificates and online degrees have little to no actual value (other than the knowledge you gained from the coursework). If you need an advanced degree in statistics or data analysis for a certain job, you should aim for a master's degree or a PhD in a brick-and-mortar institution. Otherwise, if you just want to learn, try textbooks or free Internet resources.
Answer: Disclosure of possible conflict of interest: I teach (on-line) at UOC
I agree with Kodiologist that there are on-line certificates with little value. However, there also exist on-line universities within the same system of public universities than the brick-and-mortar universities of the same country, subjected to the same quality controls and with a comparable prestige - at least, within the same range of prestige of off-line universities in the same country. The most known example worldwide is The Open University in the UK, and in Spain there are UNED and Universitat Oberta de Catalunya. I teach at UOC and at off-line universities and the level of knowledge that students reach is equivalent - for example, in basic statistics courses that I've taught in both places. Furthermore, I know people getting jobs and working with their UOC degrees just as they would with a degree from an off-line university.
I suggest to search in prestigious on-line universities for courses in your topic. In UOC there are some masters and courses related to economy and data science that might interest you, although I do not have direct knowledge of those courses because I'm teaching in other studies and can't give an informed opinion on them.
And as a final comment: Brick-and-mortar universities have some advantages, but on-line universities might ease a lot the logistics of studying. I suggest giving a try to the prestigious ones. Anyway, I must agree with Kodologist that books and Internet free resources are a great way to learn nearly anything, too.


Only one row user defined table can be passed to stored procedure

Question: SELECT
    @MaxSeq = (CASE
                  WHEN (SELECT COUNT(*) FROM app_Attachments
                        WHERE app_Attachments.AppId = @appID) <= 0
                     THEN 1
                     ELSE (SELECT (MAX(seq)+1)
                           FROM app_Attachments
                           WHERE app_Attachments.AppId = @appID)
               END)

DECLARE @Id INT;

SELECT @Id = (COALESCE((SELECT MAX(Id)+1 FROM app_Attachments), 1))

INSERT INTO app_Attachments (Id, AppID, AttName, AttContentType, AttData, AddedBy, AddedDate, Seq)
    SELECT
        @Id, AppId, ImgNames, ImgType, Bytes, @AddedBy, @AddedDate, @MaxSeq
    FROM
        @Attachments --user defined table

CREATE TYPE [dbo].[AppsAttachments] AS TABLE
       (
            [AppId] [INT] NULL,
            [Bytes] [VARBINARY](MAX) NULL,
            [ImgNames] [NVARCHAR](MAX) NULL,
            [ImgType] [NVARCHAR](200) NULL
       )

Insert into table using stored procedure that has user defined table as parameter only success if table passed has one row, it was working well when the primary key is set as identity, after I changed the primary key into manual integer to be entered the problem occurred
Comment: What is your question? Did you get an error msg?
Comment: i put a try catch and cannt handle the error its just not inserting if the table i pass contains more than one raw , i guess its the primary key coz i havenot defined it in the table
Comment: please show the schema for `app_Attachments` and `@Attachments`. And what does `AppsAttachments` related to your query ?
Comment: put i tried it when the primary key was identity , it was working even if seq is presented
Answer: if Id is not identity, then you need to ensure the Id is not duplicates. Use Row_number() to generate a running sequence of number
insert into app_Attachments (Id,AppID,AttName,AttContentType,AttData,AddedBy,AddedDate,Seq)
select  @Id + ROW_NUMBER() OVER (ORDER BY AppId) - 1,
        AppId,
        ImgNames,
        ImgType,
        Bytes,
        @AddedBy,
        @AddedDate,
        @MaxSeq
from    @Attachments --user defined table

if you also need to increase the Seq as well, add a row_number() to the query
Comment: Nice catch, `MAX()` won't  work cause the defined table has more than 1 row. +1 :)


Diferença entre dicionários e listas/arrays?

Question: Estou tentando entender o conceito de cada e suas diferenças. Quero entender em quais situações utilizar um ou outro.
Answer: Em geral os 3 são usados para conter elementos (objetos) diversos (pode ser do mesmo tipo ou não, depende da linguagem e forma de uso deles) e o acesso aos elementos são feitos através de um índice. Podemos dizer que ele é um objeto que tem outros objetos dentro dele. Então se uma variável é um desses objetos você acessa o que quer de verdade através de duas partes:

a variável que tem o container;
a variável que tem o objeto que realmente quer, e essa parte é acessada pelo índice.

A lista é um pouco mais difícil responder porque depende de como ela é implementada, não existe uma única forma de lista. É comum que uma lista seja só um array um pouco mais flexível, mas pode ser uma lista ligada, que muda bastante a forma de acessar cada elemento. Vou pegar a forma mais simples e próxima dos outros.
Array e lista já foram respondidos em O que é na verdade o array?. Em resumo a lista é o array que pode aumentar de tamanho.
O dicionário tem por diferença principal e visível que o índice pode não ser um número e pode não ser sequencial, então até costumamos falar que ele é uma chave em vez de índice. A chave mais comum que é usada é a string.
variavel["chave"]

Algumas linguagem pode ter syntax sugar mas ainda é um dicionário com um índice sendo uma string:
varivavel.chave

Coloquei no GitHub para referência futura.
Mas dependendo de como a linguagem implementou isso pode não ser exatamente um dicionário.
Uma das consequências mais óbvias é que os dados não são armazenados na ordem que eles são colocados e sim na ordem da chave, então a estrutura interna é bem diferente. Já vi implementação que na verdade não há ordem alguma (não sei se isso realmente pode ser chamado de dicionário, tem resposta que ajuda concluir (ou não :D), há quem prefira usar mapa ou outro termo).
Sem considerar outros tipos de lista, os 3 tem complexidade de espaço e tempo de acesso aos elementos constante (O(1)) ou pelo menos logarítmico (O(log n)).
Em geral o array deve ser usado em primeiro lugar, mas depende da linguagem. Em algumas linguagens a lista é tão simples e eficiente, e mais abstrata que ela é preferida e só se tiver um motivo muito forte deve escolher um array. Algumas linguagens quase obriga o uso de array em muitos casos (em geral por erro da linguagem/biblioteca). Mas no geral se você não precisa crescer o tamanho do array não deveria usar a lista. Reforço que isso não serve para muita coisa sem considerar a filosofia da linguagem.
O dicionário sempre é um pouco pior, então só deve ser usado se for muito importante, e geralmente quando você não pode usar um índice numérico sequencial, precisa de outra forma, precisa da organização das chaves.
Tem linguagem que mistura implementações.


Can I use vector in a map in STL?

Question: Can I declare a map like this
map<string, vector<string>> mymap;

I thought it is applicable.
However, it shows not.
I tried
map<string, vector<string>*> mymap;

and then it is OK
What's the rule of this?
Answer: You need an extra space:
map<string, vector<string> > mymap;
                          ^ see the extra space

Without the extra space, the >> gets parsed as the right shift operator.
The rules have been modified in C++0x, making the extra space unnecessary.  Some compilers (e.g., Visual C++ 2008 and above) already do not require the extra space.
Comment: g++ gives this nice error: `'>>' should be '> >' within a nested template argument list`
Comment: Actually, it's `std::map >`, but I realize I'm on a lost crusade here.
Comment: @Stephen: Someone who fails at the famous (and, admittedly, embarrassing) `>>` of nested templates will not have written their own C++ container matching those of the std lib. (And God help us if they had.) As for `using namespace std`, see [this answer](http://stackoverflow.com/questions/2879555/2880136#2880136).
Comment: @sbi : while we're being pedantic, how do you know it's `std::`?  Maybe he wrote his own.  Or maybe he has `using namespace std;` or even `using std::string;` and `using std::map;` ;)  Out of curiosity, why 'crusade' for the qualification?
Comment: @sbi : Yes, I was just giving you a hard time ;)  Thanks for the link, the arguments are good.
Answer: You can, as James mentioned.  Stupid c++ parsing :)
However, map<string, vector<string> > is effectively a
multimap<string, string>.  A multimap maps a key to multiple values.  It might be more convenient or more efficient, depending on your use case.

Can I use vector in a map in STL?