How to understand the notation $\frac{\partial}{\partial z}$ and $\frac{\partial}{\partial \bar{z}}$ (Wirtinger derivatives)?

Question: The Wirtinger derivatives are defined as $$\frac{\partial}{\partial z}:=\frac{1}{2}\left(\frac{\partial}{\partial x} - i\frac{\partial}{\partial y}\right)\quad \quad\frac{\partial}{\partial \bar{z}}:=\frac{1}{2}\left(\frac{\partial}{\partial x} + i\frac{\partial}{\partial y}\right)$$
I wonder why we use the notation partial derivative $\frac{\partial}{\partial z}$ and $\frac{\partial}{\partial \bar{z}}$ to represent Wirtinger derivatives. Does this suggest Wirtinger derivatives are a kind of partial derivative with respect to $z$ or $\bar{z}$ ?
I am confused by this fact: $z$ and $\bar{z}$ are not independent. Here by not independent I mean $\bar{z}$ is a function of $z$. This leads to several following problems.

Let $f$ be the function $f(z)=\bar{z}$. As a function of $z$, the partial derivative of $f$ with respect to $z$ should not equal to 0. However, according the definition of Wirtinger derivatives, $\frac{\partial f}{\partial z} = 0$.
Let $f:\mathbb{C} \to \mathbb{C}$ be a function. Can we write $f(z) = g(z,\bar{z})$ for some function $g:\mathbb{C}^2 \to \mathbb{C}$ and regard $\frac{\partial f}{\partial z}$ as $\frac{\partial g}{\partial z}$, where $\frac{\partial g}{\partial z}$ means partial derivative instead of Wirtinger derivative ? If so, when we compute partial derivative of $g$ respect to $z$, we should fix the second variable $\bar{z}$. But fixing $\bar{z}$ also means fixing $z$, then how does partial derivative make sence?
By the definition of Wirtinger derivatives, it's easy to get $\frac{\partial \bar{z}^n}{\partial \bar{z}} = n\bar{z}^{n-1}$, similar to partial derivative. For arbitrary $f:\mathbb{C} \to \mathbb{C}$, can we get a right answer like this, computing Wirtinger derivative as partial derivative ? If so, how to prove it?

I believe the notation $\frac{\partial}{\partial z}$ and $\frac{\partial}{\partial \bar{z}}$ suggest Wirtinger derivatives are a kind of partial derivative, but I can't solve the problems above. Could you please give me a rigorous answer? Thanks for your help.
Comment: @InsideOut Sorry I am not a native English speaker. What's the suitable expression?
Comment: Ask on Math Stack Exchange for "Wirtinger derivatives". You will get approximately 200 results like this one : https://math.stackexchange.com/q/2691190/305862
Comment: See https://math.stackexchange.com/questions/314863/what-is-the-intuition-behind-the-wirtinger-derivatives  They are just *notation* and the intuitive idea is that their computational rules make $z$ and $\overline{z}$ look "independent".
Comment: Does this answer your question? [What is the intuition behind the Wirtinger derivatives?](https://math.stackexchange.com/questions/314863/what-is-the-intuition-behind-the-wirtinger-derivatives)
Comment: @Jean Marie This didn't answer my questions listing above.
Comment: "I want a rigorous answer" sounds a bit impolite to me
Answer: You and I both know that the tooth fairy does not exist buttttttt let's suppose that it did and let's see if we can deduce anything useful about the world from that.
This, essentially, summarizes the way in which we justify creating these so-called Wirtinger derivatives and giving them the symbols that we do. It's one of those things that you come up with when you're randomly messing around with a bunch of formulas without justifying what you're doing but you're also born with the intellect of Riemann so you can kind of create something useful out of it.
The idea here is to take a holomorphic function $f:U \to \mathbb{C}$ defined on an open subset of $\mathbb{C}$. This is actually a two-variable function $(x,y) \mapsto f(x,y)$. Now, $x = \frac{1}{2}(z+\overline{z})$ and $y = \frac{1}{2i}(z-\overline{z})$, whenever $z = x+iy$. Now, here's the main idea that is being made use of in the following (heuristic) derivation:
Idea: $z$ and $\overline{z}$ should be regarded as independent variables.
So, they're not independent, as you correctly pointed out. There is no tooth fairy. Buttttttt, let's assume that they were independent. Then, $x$ and $y$ could also be written individually as functions of $z$ and $\overline{z}$. So, essentially, we have the following situation:
$$(z,\overline{z}) \mapsto (x(z,\overline{z}),y(z,\overline{z})) \mapsto f(x,y)$$
and this means that $f$ can be written as a function of $z$ and $\overline{z}$, as you have also asked about in your second question, and we can now differentiate with respect to each of these variables using the chain rule. So:
$$\partial_z f = \partial_x f \cdot \partial_z x + \partial_y f \cdot \partial_{z} y = \frac{1}{2} \partial_x f - \frac{1}{2}i \partial_y f = \frac{1}{2} (\partial_x f -i\partial_y f)$$
All I've done is to treat $z$ and $\overline{z}$ as independent variables (that is the entire thesis of the calculus of Wirtinger  derivatives). Similarly:
$$\partial_{\overline{z}} f = \partial_x f \cdot \partial_{\overline{z}} x + \partial_y f \cdot \partial_{\overline{z}}y = \frac{1}{2} \partial_x f + \frac{1}{2} i \partial_y f = \frac{1}{2}(\partial_x f + i\partial_y f) $$
Can you see how the Wirtinger derivatives arise naturally in the context above? But now, the main question that you asked is still floating in the air:
Does this suggest Wirtinger derivatives are a kind of partial derivative with respect to $z$ and $\overline{z}$?
If we can address this, then all your other questions can be addressed easily. Judging by all of the information above and the heuristics of the derivation above, the answer is a resounding No. You see, the Wirtinger derivatives don't represent partial differentiation with respect to $z$ or $\overline{z}$. As you've pointed out repeatedly, they are not independent.
The derivation above, done in the most naive manner, just suggests that the operators $\frac{1}{2}(\partial_x+i\partial_y)$ and $\frac{1}{2}(\partial_x -i\partial_y)$ are important. That's what's being suggested over here (and in fact, the Cauchy-Riemann Equations also do suggest this, let me know if you want further explanation on that). But now, when you have operators of interest, then you want to give them names.
But what names should we pick? How should we encode the fact that these operators are "somewhat" behaving like some sort of "partial differentiation with respect to $z$ or $\overline{z}$"? Well, that's where you use the symbols $\partial_z$ and $\partial_{\overline{z}}$ as homage to the intuitive derivation above.
So, you see, the Wirtinger derivatives don't represent partial differentiation. They represent homage to the heuristic above that aims to treat the idea of partial differentiation with respect to $z$ or $\overline{z}$ seriously. Now, what does this actually mean for your questions?

Your first two questions are certainly addressed by the considerations above. This isn't partial differentiation. So, if I give you a function $f(x,y)$ and ask you to compute $\partial_z f$, what you'll do is to use the definition of the Wirtinger derivative to compute this derivative.

But, in fact, that is tantamount to using the heuristic that $z$ and $\overline{z}$ are to be treated as independent variables. Indeed, in your first question, you showed that $\partial_z(\overline{z}) = 0$ and it's also not too hard to show that $\partial_{\overline{z}}(z) = 0$ as well. If we "think of" these as referring to some kind of differentiation, this just shows that $z$ and $\overline{z}$ are "independent".

Now, your third question is much more interesting. But the way to summarize this is the following; what you really want is a theorem that shows you that these two operators actually do behave like some kind of differentiation. Indeed, such a theorem does exist.

Theorem:
$\partial_z, \partial_{\overline{z}}$ are $\mathbb{C}$-linear mappings for which the product and quotient rule hold.
Of course, you should define these operators on the appropriate vector spaces. This is actually very easy to prove and I'll leave the proof of it to you. You can certainly find results of this form online in multiple documents and these are the results that you typically use to find Wirtinger derivatives for functions. They turn out to correspond very well with the usual rules for partial differentiation.
Comment: @JeanMarie: We don't believe in the Easter Bunny or Santa Claus, either. :-) (On the off chance that made no sense, I suspect Mordeus just means that the notation is predicated on a fiction of independence.)
Comment: [+1] ... But I don't understand the connection with the tooth fairy...
Comment: Also, they said "butttttt..." Yeah, I'm twelve years old.
Comment: You know what they say; sometimes, we have to believe in tooth fairies to derive results that help us make sense of the world ;) Yep, that was exactly what I meant with the tooth fairy analogy.
Comment: Thank you very much. I still have a question, could you please help me? I know that $\partial_z, \partial_{\overline{z}}$ are $\mathbb{C}$-linear mappings for which the product and quotient rule hold. In fact, I just use this to compute $\frac{\partial \bar{z}^n}{\partial \bar{z}} = n\bar{z}^{n-1}$. And any polynomial function about $z$ and $\bar{z}$ can be easily computed using product rule. But how about arbitrary function, which even may be not analytic but still have partial derivative with respect to $x$ and $y$?
Comment: Ye so you can still certainly compute the Wirtinger derivatives for any function which does have partial derivatives in $x$ and $y$. After all, being Wirtinger differentiable, so to speak, is just tantamount to being partially differentiable in $x$ and $y$. In fact, there is a way in which you can characterize the Cauchy-Riemann equations using Wirtinger differentiation and it actually gives an easy way to check if a function is holomorphic or not.


Strange diagnostics errors, prefedined type System... is not defined or imported

Question: I am getting Roslyn diagnostics errors when parsing a very basic .NET 4.6 application. The solution files can be downloaded from there
https://github.com/dotnet/roslyn/files/2393288/DemoSolution.zip
The dependency tree looks like this:
BLL -> DB
I am getting the following diagnostics errors in the BLL project:

The solution and projects build fine, still Roslyn gives these errors. Maybe the errors are misleading and I need to configure the projects in someway? Any idea how I can resolve these errors?
Here is the code used for parsing the files:
<code>var properties = new Dictionary<string, string>
                {
                    ["DesignTimeBuild"] = "true",
                    ["CheckForSystemRuntimeDependency"] = "true"
                };
                var workspace = MSBuildWorkspace.Create(properties);

                workspace.WorkspaceFailed += (sender, args) =>
                {

                };
                workspace.LoadMetadataForReferencedProjects = true;

Solution solution = workspace.OpenSolutionAsync(SolutionFilePath).Result;
                    foreach (var p in solution.Projects)
                    {
                        foreach (var file in p.Documents)
                        {
      var semanticModel = file.GetSemanticModelAsync().Result;

                        var mscorlib = MetadataReference.CreateFromFile(file.FilePath);
                    var compilation = CSharpCompilation.Create("MyCompilation",
                        new[] { semanticModel.SyntaxTree }, new[] { mscorlib });

                    var model = compilation.GetSemanticModel(semanticModel.SyntaxTree);
                    var declarationDiagnistics = model.Compilation.GetDeclarationDiagnostics(CancellationToken.None);
                    var parseDiagnostics = model.Compilation.GetParseDiagnostics(CancellationToken.None);
                    var allDiagnostics = model.Compilation.GetDiagnostics(CancellationToken.None);
                    var methodBodyDiagnostics = model.Compilation.GetMethodBodyDiagnostics(CancellationToken.None);

                                  }
                }
</code>
Subscriping to the workspace.workspaceFailed event results in the following error:

Msbuild failed when processing the file 'MYPATH\BLL.csproj' with
  message: C:\Program Files (x86)\Microsoft Visual
  Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets:
  (1656, 5): The "GetReferenceNearestTargetFrameworkTask" task could not
  be instantiated from the assembly "C:\Program Files (x86)\Microsoft
  Visual
  Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.Build.Tasks.dll".
  Please verify the task assembly has been built using the same version
  of the Microsoft.Build.Framework assembly as the one installed on your
  computer and that your host application is not missing a binding
  redirect for Microsoft.Build.Framework. Unable to cast object of type
  'NuGet.Build.Tasks.GetReferenceNearestTargetFrameworkTask' to type
  'Microsoft.Build.Framework.ITask'. C:\Program Files (x86)\Microsoft
  Visual
  Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets:
  (1656, 5): The "GetReferenceNearestTargetFrameworkTask" task has been
  declared or used incorrectly, or failed during construction. Check the
  spelling of the task name and the assembly name.
Comment: please check - Remove bin and obj and rebuild. - https://stackoverflow.com/questions/31224206/predefined-type-system-object-is-not-defined-or-imported-net-4-6
Comment: Hi @Ajay2707 thanks for your suggestion. But even if I removed the bin and obj folder from the solution I still get the same errors. Any other suggestions I could try?
Comment: can you check other option suggested on that link?
Comment: @Ajay2707 so when I remove the DB reference from the BLL I don´t get the errors anymore. So I tried creating a new DB project with nothing but the empty class1.cs file in it. Readding the reference to the BLL still gives the same errors.
Comment: Hi @Ajay2707 I attached the solution files and the code used for parsing the files. Could you test it as well? The code is very basic just for testing. Thanks!
Comment: You get these kind of errors when Roslyn doesn't have a reference to mscorlib.dll
Comment: Hi @HansPassant do you mean I should a add a reference to mscorlib.dll in the roslyn solution. If I try to do this I get the error The ActiveX type library 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.tlb' was exported from a .NET assembly and cannot be added as a reference.
Comment: Wrong file, mscorlib.dll, not .tlb.  Roslyn needs reference assemblies to compile/analyze code, just like you need them in the References node of a project.  mscorlib.dll is fairly special, it doesn't show up in a project's Reference node because it is always needed.  Your demo project is not helpful to repro this problem, it is missing the Roslyn code.
Comment: Hi @HansPassant, thanks for your help. So should I browse to the dll file under references or simply copy the file to the output folder? If I try to browse I get the error dialog ---------------------------
Microsoft Visual Studio
---------------------------
A reference to 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll' could not be added. This component is already automatically referenced by the build system. It's a bit strange to me why this doesn't simply work out of the box without having to references dll's other than in the Roslyn nuget package
Comment: No.  Google "site:stackoverflow.com roslyn mscorlib reference" for similar questions.
Comment: Thanks, I found an example code where the mscorlib is included in the creation of the semantic model and I updated the example code above accordingly. Nonetheless I continue to get the same errors :s
Comment: `var mscorlib = MetadataReference.CreateFromFile(file.FilePath);` it would not be a references to the `mscorlib` and `object` may contains in the different assemblies for different target platform. As you target `net46` you can try: `var mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);`
Comment: Hi @GeorgeAlexandria thanks yes thats probably the right way to do it and this is what I initially did but it did not work either.
Comment: Did you try to subscribe on `workspace.WorkspaceFailed` event before try to open solution?
Comment: Hi @GeorgeAlexandria you where right the workspaceFailed resulted in the error above. Do you think this has something to do with VS2017 maybe I should try to run this in VS2015?
Comment: 1) You should post what is the `workspace` and how did you get him 2) You can post failed error to)
Comment: hi I posted the error as part of the issue. what do you mean what is the workdpace?
Comment: hi @GeorgeAlexandria I added the workspace initialization to the code sample above. Do you see anything I am missing from there?
Comment: 1) I were surprised. Why do you try to create `Compilation` `var compilation = CSharpCompilation.Create...` when you can just receive it from `semanticModel.Compilation`? 2) About workspace, it can not correct determine the version of msbuild that should use.To fix it you can try to add the correct binding redirects in app.config or try to [un]install msbuild from GAC
Comment: Hi @GeorgeAlexandria and thanks for your help. Do you have an example for a binding redirect for msbuild? Regarding 1. I used to do it this way but then I changed it so I could specify the properties.
Comment: https://github.com/Microsoft/msbuild/issues/2369#issuecomment-353674937
Answer: So this finally solved it:

Added the microsoft.build redirects as suggested by @GeorgeAlexandria
http://github.com/Microsoft/msbuild/issues/2369#issuecomment-353674937
Cleared the Microsoft.Build.* from the output bin folder
Added the Microsoft.Build.Locator as a reference
Added the line MSBuildLocator.RegisterDefaults() above the workspace code.

Source:
https://github.com/dotnet/roslyn/issues/26029#issuecomment-380164421


Boundedness of solution for differential equation $ y^{\prime}(t)+y(t)=f(t) $ relative to the boundedness of $f$

Question: Let $f: \mathbb{R} \rightarrow \mathbb{R}$ be a continuous function. Consider the differential equation
$$
y^{\prime}(t)+y(t)=f(t)~~~~~~~~~~~~~~~~~~~~~~~~~~~~(*)
$$
on $\mathbb{R}$.
a) Show that $(*)$ can have at most one bounded solution.
b) If $f$ is bounded, show that $(*)$ has a bounded solution.
Actually, we have $y_h(t)=e^{-t}$ as a solution for corresponding homogeneous part $y'(t)+y(t)=0$, which is not a bounded function on $\Bbb R$. Further, a particular solution $y_p(t)=(D+I)^{-1}(f)(t),$ where $D=\frac{d}{dt}$, should be obtained to get the general solution $y=y_h+y_p$. How can I connect the boundedness of $f$ to the boundedness of general solution?
How can I say $(*)$ can have at most one bounded solution?
Comment: You have a closed formula for the solution which would be a good place to start.
Comment: Alternatively, if you subtract any two particular solution, you get a solution to the homogeneous equation which as you say is unbounded. Does that ring a bell?
Comment: By the way, the general solutions will be $y = \lambda y_h + y_p$, $\lambda \in \mathbb{R}$, there is not just $y_h + y_p$.
Answer: You already figured out that the homogeneous equation is unbounded. Suppose that there are two bounded solutions $y_1, y_2$. Thus $\tilde y:=y_1 - y_2$ is bounded and satisfies the associated homogeneous equation. But if $\tilde y\not \equiv 0$, then it is unbounded by your remark (every solution of the homogeneous equation is $c e^{-t}$ for some $c$). Thus $\tilde y \equiv 0 \implies y_1 \equiv y_2$, proving uniqueness.
To show that there is a bounded solution, use the usual, explicit method to find a solution and try to choose an initial value good enough such that $|f(t)| \le M$ actually gives you boundness. You can multiply by an integrating factor $\mu = e^t$, so $e^t y' + e^t y = e^t f \iff (e^t y)' = e^t f \iff y(t) = (c + \int_{-\infty}^te^\tau f(\tau) d\tau)e^{-t}$. In particular, $|y(t)| \le ce^{-t} + e^{-t}\int_{-\infty}^t e^\tau |f(\tau)| d\tau \le ce^{-t} + Me^{-t}\int_{-\infty}^t e^\tau d\tau = ce^{-t} + M$. so $c = 0$ in fact gives boundness for both positive and negative $t$; i.e.,
$$y(t) = \int_{-\infty}^t e^\tau f(\tau)d\tau$$ is our bounded solution.
Comment: I think you missed the factor $e^{-t}$ in the last bounded solution.
Answer: If $f$ is bounded ($|f(t)| \le b$) then
$$
y(t)=e^{-t} \int_{-\infty}^t e^\tau f(\tau)d\tau
$$
is a bounded solution. Note that the integral is convergent since $f$ is bounded.
We have
$$
|y(t)| \le b e^{-t} \int_{-\infty}^t e^\tau d\tau = b \quad (t \in \mathbb{R}).
$$
The proper initial value is therefore $\int_{-\infty}^0 e^\tau f(\tau)d\tau$.


How can I append IPs (a whole class C range) to a file using shell scripting?

Question: How can I use shell scripting to append a range of IPs to a file?
Comment: Please, [classes don't exist from eons](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing). You are referring to a /24.
Comment: Yes you can. `echo "192.168.0.1/24" >> /path/to/file`.
Comment: Oh, or do you need it that way? `echo 192.168.0.{0..255} >> /path/to/file`
Answer: Try something like:
<code>#!/bin/bash

for i in {0..255}
do
    echo 192.168.0.$i >>outfile.txt
done
</code>
The <code>>></code> operator is used to append to a file.
Comment: Thank you so much!!

ps.: I know I should have found it out by myself, but I know next to nothing about shell scripting, and was (am) dead tired after adding the whole /24 range by hand in a web console (Apache/Tomcat).

I'll try not to ask stupid questions next time!


Existence of a function with a changing period

Question:
$f,\alpha$ are continuous $\mathbb{R}\to\mathbb{R}$ functions satisfying:
$$f\big(x+\alpha(x)\big)=f(x)$$
If $f$ is non-constant, must $\alpha$ be constant?

My idea was to use the fact that no real function can have a double period, but I don't know how to apply it, or whether this is the right way to go.
Answer: Here's the first example that comes to mind:
$$
f(x) = \sin(x^2)
$$
In this case, we can take
$$
\alpha(x) = \sqrt{x^2+2\pi}-x
$$
which is continuous but not constant.

For a somewhat more remarkable example, the function
$$
f(x) = \cos(x+\frac{1}{100}\sin(x))
$$
Is periodic in both your sense and in the sense of a constant period, since we may select an $\alpha(x)$ that is itself periodic.  The analysis of such functions is important for applications such as FM radio.


Find an $f:\Bbb{R}\rightarrow \Bbb{R}$ such that $f(x+2)-f(x)=x^2+2x+4$ holds for all $x\in\Bbb{R}$ and $f(x)=x^2$ for all $x\in [0,2)$

Question: Find a function $f:\Bbb{R}\rightarrow \Bbb{R}$ such that

$f(x+2)-f(x)=x^2+2x+4$ for all $x\in\Bbb{R}$.

$f(x)=x^2$ for all $x\in [0,2)$.

Please give a hint for the problem. I have not getting the way to proceed.
Comment: Hint : what can you say about $f$ on $[2,4)$ ?
Comment: $f(2)=4$, correct?
Comment: Yes! But you can actually find the entire interval $[2,4)$ at once, in terms of $x$.
Comment: If $x \in [0,2)$ then $x+2 \in [2,4)$ and $f(x+2)-f(x) = f(x+2)-x^2$.
Answer: This is a linear inhomogeneous problem. The general solution of
$$f(x+2)-f(x)=x^2+2x+4\tag{1}$$
can be found by the hom+part procedure: Find the general solution $f_{\rm hom}$ of the homogenized equation
$$f(x+2)-f(x)=0\ ,\tag{2}$$
and add to it a "particular" solution of $(1)$ that you have found "somehow".
The general solution of $(2)$ is obvious: $f_{\rm hom}$ can be any periodic function of period $2$. For $(1)$ we guess a solution of the form
$$f_{\rm part}(x):=ax^3+bx^2+ cx+ d\ ,$$
and try to adjust the coefficients such that $(1)$ is fulfilled. It turns out that
$$f_{\rm part}(x):={x^3\over6}+{4x\over3}$$
does the trick. The general solution of $(1)$ then is
$$f(x)=f_{\rm hom}(x)+{x^3\over6}+{4x\over3}\qquad(-\infty<x<\infty)\ .\tag{3}$$
Any $f$ of the form $(3)$ with an arbitrary $2$-periodic $f_{\rm hom}$ fulfills condition 1. of your question. But there is also condition 2., and this condition will determine $f_{\rm hom}$. We  have to make sure that
$$f(x)=f_{\rm hom}(x)+{x^3\over6}+{4x\over3}=x^2\qquad(0\leq x<2)\ .$$
This leads to the condition
$$f_{\rm hom}(x)=x^2-{x^3\over6}-{4x\over3}=-{1\over6}x(x-2)(x-4)\qquad(0\leq x<2)\ .\tag{4}$$
This refers only to the $x$-interval $[0,2[\>$. But $(4)$
automatically fixes $f_{\rm hom}$ as a  function on all of ${\mathbb R}$, since $f_{\rm hom}$ has to be periodic with period $2$.
We can now consider $(3)$ as final solution of the problem, whereby $f_{\rm hom}:\>{\mathbb R}\to{\mathbb R}$ is the periodized function given on the RHS of $(4)$ for $0\leq x<2$. You could write
$$f_{\rm hom}(x):=-{1\over6}t(t-2)(t-4)\biggr|_{t:=x-2\lfloor x/2\rfloor}\qquad(-\infty<x<\infty)\ .$$
Comment: Ok. Would you please explain how $f_{\rm hom}$ is periodic???
Comment: would you please explain the line "   But $(4)$
fixes $f_{\rm hom}$ as a (by coincidence) continuous function on all of ${\mathbb R}$, since $f_{\rm hom}$ has to be periodic with period $2$. "


MIDI Keyboard controller and Windows Tablet

Question: I installed Mixcraft 7 on my iBall slide i701 and assigned all the VSTs I required for a particular song to different instrument tracks and pre-set the volume/pan of each. The plan was to select/touch any track to get the instrument set there activated. Next step was to connect my m-audio keystation 49 to the tab and there I failed since the tab seemed no way interested in recognizing the MIDI keyboard. What do I need to do in order to use that tab as my VST host?
I do not own an iPad as many suggested to use Garageband; nor do I get to buy a Surface tab as many video-people showed on YouTube. I don't think my Mi4i would be able to produce anything close to real-time (though I have not tested ALL the apps from the Google Play Store).
Suggestions?
Thanks in advance.
Comment: [M-Audio claims it doesn't require drivers](http://m-audio.com/kb/article/1670#drivers).  I'd double-check that the USB ports and cable are working.
Answer: USB devices on tablets are a tricky matter.
First make sure you're using the right cable adapter from the microUSB/OTG port in your tablet, to the standard USB host (female) connector. Have your tried the conection with other devices (e.g. a simple memory pen drive)? Does the MIDI controller give any sign of life when connected (e.g. LEDs lightinh or flashing)?
If the connection works with other USB devices but not the MIDI controller, or you see the controller respond in some way but not be properly recognized by the host, then you may have a power problem. The tablet may not be able to supply enough power to the controller. This is a common enough problem for example with external USB hard drives, which required more current debit than the USB port of a tablet normally supplies. I have seen devices start (LEDs light, etc.) but not work properly untill an external USB power supply with sufficent current yeld is provided.
If that's the case then it may be able to be solved by an OTG cable adapter with a Y connection to allow the simultaneous connection of the power supply.
On another line of inquiry, can you see the controller in Windows's Device Manager? Check the article indicated above by Mathew, and specially this link here http://m-audio.com/kb/article/1619, for some clues by the manufacturer.


Cant figure out how to solve this probabilty problem?

Question: So this is the problem:
                       Brittney was packing bags for shipping. As she had reached  bag number 42, she realized that she had an earing missing. What would be the probability that she would find the ring by opening only seven bags?
I can figure that the sample space would have 42 elements, but i cant figure out what number of elements the events set would have.
Thanks.
Comment: **"Reached"** bag 42 is ambiguous. Has she **packed** bag 42 or not ? If not, it is open at this point ....
Comment: well i think i did not check the problem statement again while posting here, and English isnt my first language. So, that might me a mistake by me. And yes she has completed packing bag 42.
Comment: Ok, anyway you have got the desired  response !
Answer: Although mathbeing's answer is correct, you wanted to identify the sample space so I'll help you with that.
There are probably different ways of setting this up, but for me the most logical way (most connected to reality) is the following. Note that the experiment is taking 7 bags from the collection of 42, and the sample space consists of all those possible outcomes.
If we call the bag with the earring $E$, and enumerate the rest as $N_1, N_2, \ldots, N_{41}$, then the set of bags is
$\mathcal B = \{ E, N_1, N_2, \cdots, N_{41} \}.$
Since the order does not matter and bags are drawn without replacement (and I assume we draw all seven of them before looking at them, instead of drawing them one by one and stopping once we find the earring), an event would be a subset of $\mathcal B$ consisting of seven elements. There are $\binom{42}{7}$ of them in total, all of them either of the form $\{N_{i_1}, N_{i_2}, \ldots, N_{i_7}\}$ or $\{E, N_{i_1}, N_{i_2}, \ldots, L_{i_6}\}$.
How many of the latter type are there, i.e. how many 7-element subsets of the $\binom{42}{7}$ actually contain $E$?
Answer: If we have no further information we must assume that the probability that the earing is in each bag is $1/42$. If she opens $7$ bags then the probability of her finding her earing is $$1/42+1/42+1/42+1/42+1/42+1/42+1/42=7/42=1/6\approx 0.167$$


How do I get the AIC value out from a forecast object in R?

Question: I am trying to get the raw value of AIC that I can see as a result of the summary function.
x = forecast(ets(ts(data, start=2000, frequency=12)),h=6)
summary(x)

This shows me an AIC value:
AIC      AICc       BIC
7.995437 27.995437  7.779078

When I use AIC I get this error
> aic <- AIC(x)
Error in UseMethod("logLik") :
no applicable method for 'logLik' applied to an object of class "forecast"

any suggestion? thanks
Answer: AIC is the property of the model, not of its forecast. So natural solution is to use the following code:
AIC(x$model)

You can always get more information looking at the innards of the object:
names(x)

is usually sufficiently revealing.
Answer: fit<-ets(ts(data, start=2000, frequency=12))

AIC(fit)


Edit a function into 0xdbe

Question: Recently I started to use 0xdbe. I appreciate so much, but I don't know how to edit a function. I can't see a DDL function into 0xdbe.
Anybody can help me?
Comment: So? Did you solve it?
Comment: Yeap. Dawid answered.
Comment: Tags for this question should be updated. 0xdbe is now Datagrip and should be marked as such to improve searching.
Answer: In a database tree expand "routines" and double click function you want to change. It opens function editor, where you can change it and then click green "play" button in top right corner, which executes it. That's all.
Comment: I'm not sure what you mean by printing logs. Logs of what? Also PL/pgSQL is just a language similar to SQL, but for creating a stored procedures. It's output is the same as output of plain SQL query. So I have no idea, what do you mean by printing. Anyway you should create a separate question if you need a help on another topic.
Comment: Thanks Dawid. Do you know how I can print logs like "notices" using plpgsql?

Edit a function into 0xdbe


How to design a database that can handle unknown reports?

Question: I am working on a project which stores large amounts of data on multiple industries.
I have been tasked with designing the database schema.
I need to make the database schema flexible so it can handle complex reporting on the data.
For example,
<code>what products are trending in industry x
what other companies have a similar product to my company
how is my company website different to x company website
</code>
There could be all sorts of reports. Right now everything is vague. But I know for sure the reports need to be fast.
Am I right in thinking my best path is to try to make as many association tables as I can? The idea being (for example) if the product table is linked to the industry table, it'll be relatively easy to get all products for a certain industry without having to go through joins on other tables to try to make a connection to the data.
This seems insane though. The schema will be so large and complex.
Please tell me if what I'm doing is correct or if there is some other known solution for this problem. Perhaps the solution is to hire a data scientist or DBA whose job is to do this sort of thing, rather than getting the programmer to do it.
Thank you.
Answer: I think getting these kinds of answers from a relational/operational database will be very difficult and the queries will be really slow.
The best approach I think will be to create multidimensional data structures (in other words a data warehouse) where you will have flattened data which will be easier to query than a relational database. It will also have historical data for trend analysis.
If there is a need for complex statistical or predictive analysis, then the data scientists can use the data warehouse as their source.
Answer: Adding to Amit's answer above, the problem is that what you need from your transactional database is a heavily normalized association of facts for operational purposes.  For an analytic side you want what are effectively tagged facts.
In other words what you want is a series of star schemas where you can add whatever associations you want.


Is Multiplying the Inverse Better or Worse?

Question: When dealing with double data types is multiplying by the inverse better or worse?
Which way is faster?
Which way uses less memory?
Which way is preferred?
How does MSIL handle this?
SquareInches = MMSquared / 645.16
SquareInches = MMSquared * 0.0015500031000062000124000248000496

NB: 10K users will note that this is a duplicate of this question,
which was deleted because the original
question asker decided to berate
everyone in the 'comments' section of
the question.

This question was reposted because it is a 'good' question.
Please 'uncheck' Community Wiki for your answer, as I'm only posting this as CW so that it's not seen as a 'reputation' grab.
Related Question:

Should I use multiplication or division?
Comment: This one sounds familiar, I think it might be a duplicate.
Comment: I'm really hoping we can get a user voice request through to force peoples names to be put next the offensive tag if they click it.  This is yet another case of abuse.
Comment: @JaredPar : To be fair, the OP berated everyone who asked him to clarify his question, it was fair to mark it as offensive because that was the only way to punish his abusive behavior.
Comment: Dup of http://stackoverflow.com/questions/226465/should-i-use-multiplication-or-division.
Comment: So do Python and .NET handle it the same way, David?
Comment: I spent so much time answering the first version of this question.. anyway, I did it again :)
Comment: To be fair to the posters who spent time, the old question should be re-opened.
Comment: @Gortok, But I'm not seeing any abuse in this question.  If someone is going to mark this question as offensive when the post itself does not appear to be (went through the revs didn't see anything obvious) they should at least give some context.
Comment: @JaredPar : The OP's question was marked offensive by 6 people because of his comments.  This question obviously isn't offensive, and generally speaking, neither question should have been marked offensive. But the OP's comments should have been marked offensive. No mechanism to do that exists though
Comment: @Gortok:  The question I referred to mentioned Python but didn't restrict itself to it, and the answer is almost certainly hardware-based, and the same in both cases.
Comment: @David Thornley : So MSIL doesn't handle it a certain way?
Comment: Wondering why the offensives were taken off this question, and the old original question remains locked/marked as offensive. I think a better solution would have been to re-open the other question and delete all comments that are offensive.  The asker should have been respected instead of badgered.
Comment: So what is offensive about this question, Brian?
Comment: And can you see how he treated multiple people in the comments section? Or does it not show that?
Comment: @Gortok: I'll stay out of it.
Comment: @Brian : It's an honest question. If I don't know why this question is offensive, then I can't correct it, can I? If you voted it offensive, it'd help to know why.
Comment: @Gortok: My comment was referring only to the actions of the moderator, not about this question being offensive to me.
Comment: This question needs to be left up.  You god damn mods are way too power trippy.  You should be adding value instead of subtracting it.  If half of the people with the power to edit/close fixed up posts instead of being anal and trying to close borderline questions SO would be better off.
Comment: @brian : When a question is deleted, it's automatically locked for a reason. One of the Uservoice requests covers that, IIRC.
Comment: @Simulcal : I agree whole-heartedly. I posted this question for that very reason, and RichB and I didn't vote to close this question, someone else did.
Comment: http://stackoverflow.uservoice.com/pages/general/suggestions/124889-offensive-posts-locked-not-deleted-
Comment: @Gortok, oh I wasn't implying it was you.  I'm just tired of coming into posts with downvotes/closevotes, say for example because the post was written by a non-native english speaker.  There will be 2-3 mods in the comments section discussing why the post is bad instead of just fixing it.
Comment: @Gortok, you and RichB are both great mods.  You aren't the norm though.
Comment: I will cast a re-open if someone explains why it's different from the question posted by @David Thornley
Comment: To be fair, I only re-posted this question, so I have no dog in this fight; but David Thornley's question didn't address how the MSIL handles this issue; and this one does. Technically, it's not a duplicate (at least not with how this crowd hates when I 'split hairs')
Comment: I think there's no answers that gives any MSIL specific reasoning.
Comment: @Brian R Bondy: Isn't that a fault of the answers, and not of the question ? Or should the question be made more precisely?
Comment: @Gortok: I think it probably indicates that the question reduces to the same thing.  The other question is more general and this question is a subset of that topic.  I could be wrong and MSIL handles this situation different from everyone else.
Comment: @Gortok: Perhaps indicate why you think that MISL behaves differently.
Comment: @Brian: If I knew the answer to that, I wouldn't need to ask the question...
Comment: @Gortok: lol, I meant indicate what urges you to be specific about MSIL.  What can be gained from an MSIL specific answer that cannot from a general answer.  Anyway I'm moving on.
Comment: Well, it'd help to know how the MSIL handles this particular issue; does it optimize before it even goes to Machine code?
Comment: @Gortok: I re-opened. Cheers.
Answer: Multiplying by the inverse is faster.  Compilers don't optimize this automatically because it can result in a small loss of precision.  (This actually came up on a D newsgroup Walter Bright frequents, and he made it clear that compilers do not do this automatically.)  You should normally divide because it is more readable and accurate.
If you are executing a piece of floating point code a billion times in a loop and you don't care about a small loss of precision and you will be dividing by the same number several times, then multiplying by the inverse can be a good optimization.  I have actually gotten significant real world speedup in a few cases like the ones described by multiplying by the inverse, but these are extreme edge cases in loops executed several billion times that pretty much do nothing but multiply floats.
Comment: A simple example: Raytracers need to do vector normalization or similar things for every ray (typically several times per pixel per frame).
Comment: And if you're going for multiplication because you're executing it a bazillion times a second, nothing stopping you from adding a comment with the division value for readability.
Answer: Which one is "faster" is indeed a cpu-specific issue, or at least how much faster is CPU specific, yes, division is typically seen as slower than multiplication. And of course all performance questions can be answered with "it depends."
HOWEVER, if you'd asked which is "better" rather than which is faster there would be a clear answer, the more readable one is better. The performance improvement you're looking at is likely on the order of several clock cycles, so unless you're talking about doing this millions of times, you're trying to save yourself microseconds. And there is no microsecond optimization that is worth sacrificing readability and maintainability.
Answer: The benefit will be very small or zero, depending on both the compiler and the hardware.
But it could still matter (in a tight loop), and then for readability you should write
SquareInches = MMSquared * (1 / 645.16)

And preferably use a constant for 645.16.
Comment: Because every compiler will do the (1 / 645.16) compile-time. So it just a different (and better) notation for 0.0015...0496
Comment: How can be multiplication and division faster then either of these two?
Comment: Oh, right, didn't see that. This is for sure nicer notation, +1.
Answer: The answer will depend on the architecture of the executing environment. In general, divisions are usually slightly more costly than multiplication on most processors.
So unless this is actually a performance concern, I probably wouldn't worry about it. Pick the conversion factor that's more understandable.
Comment: The compiler does NOT optimize this because it could affect precision slightly.
Answer: from my VB code timer
Dim SquareInches As Double
Dim MMSquared As Double = 81
Const d As Double = 645.16
Const m As Double = 1 / 645.16
Private Function TestCase1() As Boolean 'One
    'Test One Code Here
    SquareInches = MMSquared / d
    'end test code
    Return True
End Function
Private Function TestCase2() As Boolean 'Two
    'Test Two Code Here
    SquareInches = MMSquared * m
    'end test code
    Return True
End Function

results
     3/17/2009 2:13:27 PM   CPU - 1.794GHz
 One - Using Division
 Two - Using Multiplication
 Outer Loops(OL)=7  Inner Loops=262,144
  ( times in ticks.  1 ms. = 10,000 ticks )
 >> Two faster, 0.0488 ticks/loop
  Ticks / Loop
 0.0342         0.0819          0.0331          0.0488
 OL Base        One             Two              One - Two
 1   8,936          21,459          8,609           12,850
 2   9,008          21,416          8,682           12,734
 3   8,965          21,423          8,643           12,780
 4   8,964          21,457          8,659           12,798
 5   8,966          21,469          8,640           12,829
 6   8,987          21,660          8,688           12,972
 7   8,963          21,429          8,802           12,627

  Average
 8,969          21,473          8,674           12,799
  Variance
 431.4          6,160.3         3,315.9
  Standard Deviation
 20.8           78.5            57.6
 3/17/2009 2:13:27 PM

Comment: as a relative measurement i guess it is ok.  as an absolute measurement of time, that might be a different story.  the times come from the Stopwatch class.
Answer: Division algorithms are slower than multiplication algorithms in most cases.
It's a tradeoff, you can choose either the more readable way, or the faster way.
// Using division operation
SquareInches = MMSquared / 645.16

This is easy to read and maintain, but performs slower than its multiplicative counterpart:
// Using a multiplication
SquareInches = MMSquared * 0.0015500031000062000124000248000496

If you go this way, you'll need more space in memory to store the inverse number digits, but the algorithm runs substancially faster. A user tested it on a VS2005 project, and reported an 8X faster performance for the multiplicative version.
The reason for that is that a multiplication can be blindly converted to shift and add operations on the processor, which are the most optimized operations on a CPU. A good algorithm for signed multiplication is Booth's algorithm (the processor does this for you). On the other hand, more control overhead is required when performing a division algorithm, thus rendering division algorithms slower.
If performance is your need, use additions, substractions (nothing more than adding the two's complement), multiplications, shiftings, but never divisions. You'd get a substantial non-negligible improvement if you compute all your inverses in advance, and use them to multiply in a division intensive program.
Comment: If both numbers are converted to double, then they use the same amount of memory.
Answer: Regarding compilers performing the optimization to mult, they can optimize this (GCC does):
SquareInches = MMSquared * (1 / 645.16).
Answer: If you're dividing by a literal value like 645.16 then it's very likely that there is no difference because the compiler can easily determine which version is faster and use that.
If you're dividing or multiplying by a variable then it's likely that multiplication is slightly faster because the logic is generally more simple.
As with anything, to be sure, use a profiler.
Comment: At least GCC -O2 on x86-32 does not perform such optimizations and does generate the fdivrs instruction. Such an optimization is full of potential pitfalls, so I doubt that many compilers do that.
Answer: Multiplies and adds are the fastest operations the processor supports. Some processors don't even have hardware implementations of things like division, square root, etc.
Answer: With most processors, it's faster to multiply than divide. But it's really insignificant for most applications, in my opinion you're better off with whichever is more readable, unless profiling shows it's a critical path.
If it's an interpreted language, the amount of time to read the source and convert it to numbers will overwhelm the time taken to actually do the math, especially if you use that many significant digits for the multiply. (Are you sure you really need that many significant digits?)
Answer: I would think the first method is clearly preferred because it is explicit. Imagine finding this in someone else's code. How are you sure that 0.00155... is really 1/645.16? What if the original programmer made a mistake? Furthermore, how do I know that 645.16 is the correct conversion factor? It's always best to not leave numbers compacted or represented in uniform for simplicity. The most basic example is as follows:
//hours per day * days per year
int hoursPerYear = 24*365;

We can clearly see that this number is correct, but how would you know, offhand, that 8760 is the correct answer? If you need to perform many of these operations, you may want to preprocess the data to the correct form BEFORE entering your intensive calculations. In this manner, you won't need incredible efficiency, and the question becomes moot.


Existence of an $L^2$ function.

Question: Let $f_n \in L^2([0,1])$ be non-zero for all $n \in \Bbb{N}$. Prove there exists a function $g \in L^2([0,1])$ such that
$$\int_0^1 g(x) f_n(x) dx \neq 0.$$
So first I tried contradiction which implies $g(x)f_n(x)$ need be zero almost everywhere which would imply $g$ to be the zero function. But then again I thought maybe $g(x)=1$ on the whole unit interval could work? Its certainly in $L^2$...
Comment: Do you want $$\forall n\in\Bbb N\quad\int_0^1 g(x) f_n(x) dx \neq 0?$$ And do you assume $$\forall n\in\Bbb N\quad f_n\ne0?$$ Please edit your post to clarify **both points**, instead of answering in comment.
Comment: Can $g$ be dependent on $n$, or do you want a $g$, s.t. the equation holds for any $n$?
Comment: Please re-edit your post to specify it also (as asked in my comment above).
Comment: Is $n$ an index for a sequence of functions?
Comment: yes it rangers over the natruals @whpowell96
Comment: @AnneBauval for all $n \in \Bbb{N}, f_n \neq 0$..
Comment: edited @AnneBauval
Comment: For $g = 1$, take $f_n = 1-2x$.
Comment: I want a $g$ that works for any $n$ @tychonovs-scholar
Answer: The hyperplanes $f_n^\perp$ are nowhere dense in the complete space $H:=L^2([0,1])$, hence by Baire's category theorem, their union does not cover $H$.
Comment: I could easily guess who was the first downvoter and I didn't care, but the second downvote makes me wonder: what is wrong with this answer? Is it not detailed enough? Or shouldn't I have posted it because you think the question was below the quality standards of this site?
Answer: For each $n \in \Bbb{N}$, put
$$U_n:=\{g \in L^2: \int_0^1 gf_n \neq 0\}.$$
Next, define linear functionals $L_n$ on $L^2$ via
$$L_n(g):=\int gf_n dx.$$
Then $U_n=L^{-1}(\{0\})^c$. And by continuity of $L_n$, $U_n$ is open as it is the preimage of an open set. Moreover, given any scalar $t$,
\begin{align*}
    L_n(g+tf_n)&=L_n(g)+tL_n(f_n)\\
    &=L_n(g) + t\vert \vert f_n \vert \vert^2.
\end{align*}
And since $\vert \vert f_n \vert \vert \neq 0$, there exists only one value of $t$ for which
$$g+tf_n \not\in U_n.$$
Thus $U_n$ is dense. Thus $(U_n)_n$ is a countable family of dense sets in $L^2([0,1])$ which is complete thus by Baire Category theorem,
$$\bigcap_n U_n \neq \emptyset.$$
And any $g \in \cap_n U_n$ has the property that
$$\int_0^1 gf_n dx \neq 0.$$

Existence of an $L^2$ function.


Time Series Forecast: Convert differenced forecast back to before difference level

Question: I am using R and I need an easier way to produce forecasts of data at the original level based on forecasts using differenced data.
The situation, in more detail, is this: I am using several different models (including SVM and a few others) to forecast a time series. My models are based on differenced data since the original data is not stationary. Now I have a vector of predicted values for each model, but all the forecasts are for the differenced data. How can I get forecasts of the original data before it's differenced?
In other words, if I have forecasts of returns, how do I automatically get the forecasts of stock prices of the same period in R? I know the hard-coded way to do it, but I am looking for an easier way. In testing situations like rolling windows with different forecast horizons, things could be trickier I believe. To be more specific, if the window is rolling with horizon 7 (days), then $\hat{y}_{t+1}$ until $\hat{y}_{t+7}$ is easy to calculate by Glen's answer below. However, after we roll the window once we will be standing at time $t+7$, where we have both $y_{t+7}$ and $\hat{y}_{t+7}$. I want to calculate $\hat{y}_{t+8}$ as $y_{t+7}+\hat{z}_{t+8}$ and $\hat{y}_{t+9}$ as $y_{t+7}+\hat{z}_{t+8}+\hat{z}_{t+9}$, and so on.  So, for $\hat{y}_{t+8}$ to $\hat{y}_{t+14}$ the value $y_{t+7}$ needs to be used and this could go on until the end of the dataset. Is there any R function I can use to make this calculation conveniently?
Comment: There's something unclear about your circumstances; you may be aware of important details that we aren't. Why is $y_{t+7}$ needed?
Comment: @Glen_b Because using rolling window with horizon $h=7$ we get new information step by step, at time $t+7$, we already know $y_{t+7}$, so I believe it makes more sense to calculate $\hat{y}_{t+8}$ as $y_{t+7}+\hat{z}_{t+8}$ rather than $y_{t+1}+\hat{z}_{t+1}+...+\hat{z}_{t+8}$.
Comment: @Glen_b Thank you for clearing things up, I think I know how to proceed now.
Comment: I moved the comment to my answer.
Answer: The usual approach to the point forecasts is to cumulatively add the difference-forecasts to the last cumulative observation. If $z$ are the differenced data and $y$ the original, then:
$\hat{y}_{t+1}=y_t+\hat{z}_{t+1}$
$\hat{y}_{t+2}=\hat{y}_{t+1}+\hat{z}_{t+2}=y_t+\hat{z}_{t+1}+\hat{z}_{t+2}$
and so on. The cumulative sums of the $\hat{z}$ values are easy, and adding $y_t$ is also easy. Details of what to do in R would depend on the specific model (e.g. if you fitted an ARMA to the differences, just specify the corresponding ARIMA to the original and predict that).
On your second question, you have more data, so you have to calculate new parameter estimates anyway. Since you have new parameter estimates you'd just recalculate forecasts the same way as before, but with those 7 additional observations. In some circumstances the parameter updates can be computed in terms of the old estimates and the data (e.g. state-space models), but for many models you just recompute everything like you did with the previous forecasts.
Comment: Lets say for fitted values, how will we know the real fitted values as it has been differenced twice already. what will be yt in that case? and how to proceed in that? I have an example here http://stats.stackexchange.com/questions/188595/convert-double-differenced-forecast-into-actual-value


WebScraping - Site com opções de escolhas

Question: tenho uma pergunta mais genérica (embora esse site seja mais apropriado para coisas mais específicas), e agradeceria se alguém puder ajudar com algumas dicas de por onde começar.
É possível fazer scraping em um site que tenha caixas de opções, como esse?
https://filia-consulta.tse.jus.br/#/principal/download

Tenho conhecimento básico do rvest e sei como pegar dados simples como esse:
partidos <- "http://www.tse.jus.br/partidos/partidos-politicos/registrados-no-tse"

partidos <- partidos %>%
read_html() %>%
html_table() %>%
.[[1]]

Mas, não tenho ideia de como fazer a raspagem dos dados em links como o indicado acima. O problema é que não consigo encontrar o(s) link(s) de onde estão armazenados os dados que aparecem para download ao clicar em "consultar". Alguém tem alguma dica ou sugere algum material para eu pesquisar?
Answer: Um ponto de partida para se conhecer o funcionamento de qualquer site são as ferramentas para desenvolvedor disponíveis nos navegadores. Neste caso, eu utilizei a aba Network (Rede) do Chrome para verificar de onde o arquivo estava sendo baixado:

Daí percebi que ao selecionar o PT do Espírito Santo, por exemplo, o navegador fez uma requisição para a URL:
http://agencia.tse.jus.br/estatistica/sead/eleitorado/filiados/uf/filiados_pt_es.zip
Você pode perceber um padrão aí. Mas argumento que, mais importante do que resolver o seu caso específico, é aprender a utilizar bem as ferramentas de desenvolvimento disponíveis nos próprios navegadores, para isso recomendo os materiais abaixo:
https://developer.mozilla.org/pt-BR/docs/Tools/Network_Monitor
https://developers.google.com/web/tools/chrome-devtools
No futuro, quando quiser lidar com sites assim, você pode utilizar ferramentas como o Selenium para automatizar operações:

Esses pacotes não são suficientes para acessar todo tipo de conteúdo
da web. Um exemplo claro disso são páginas em que o conteúdo é
produzido por javascript, o que acontece em muitos sites modernos.
Para trabalhar com esses sites, é necessário realmente "simular" um
navegador que acessa a página web. Uma das melhores ferramentas para
isso é o selenium. Não discutiremos selenium nesse curso, mas caso
queira se aprofundar, acesse aqui. 2
Comment: Muito obrigado, felubra. Agora consegui encontrar os links. E ótimas dicas, vou pesquisar sobre elas com tempo. Por ora, agora conseguirei baixar os dados no site do tse. Super valeu!


Zero COUNTs in JOIN with three tables

Question: I have three tables; County, Cemetery & Graves.  The Marked column in the Graves table is boolean.  The query result should include the number of "Marked" graves in each cemetery including the zero count.
    County
-------------------------
|  CountyID  | Name      |
-------------------------|
|   351      | Lee       |
|   352      | Glascock  |
-------------------------

   Cemetery
--------------------------------------
| CEMID  |  CountyID  | Name          |
--------------------------------------|
|  1     |      352   | Smith Family  |
|  2     |      352   | Adams Family  |
|  3     |      352   | Jones Family  |
|  4     |      351   | Harris Family |
--------------------------------------

   Graves
--------------------------------------
|  ID | CEMID |     Name     | Marked |
--------------------------------------|
|  1  |   1   | John Smith   |   Y    |
|  2  |   1   | Mary Smith   |   N    |
|  3  |   1   | Frank Smith  |   Y    |
|  4  |   1   | Jane Smith   |   N    |
|  5  |   2   | John Adams   |   Y    |
|  6  |   2   | Ed Adams     |   N    |
|  7  |   3   | Susan Jones  |   N    |
--------------------------------------

   Query Result
----------------------------------
|  CEMID |     Name       | Count |
----------------------------------|
|  1     |  Smith Family  |  2    |
|  2     |  Adams Family  |  1    |
|  2     |  Jones Family  |  0    |
----------------------------------|

My current SELECT statement:

SELECT Cemetery.Name, Cemetery.CEMID, COUNT(Grave.Marked) AS Count
         FROM Cemetery
         JOIN County
         ON Cemetery.CountyID = County.CountyID
         JOIN Grave
         ON Cemetery.CEMID = Grave.CEMID
         WHERE CountyID = 352
         AND Grave.Marked = TRUE
         GROUP BY Cemetery.CEMID;

This statement returns the result but doe not include the Jones Family cemetery because the Marked count is zero.  I understand that the "Grave.Marked = TRUE" is in the wrong place, but where should I qualify the Count to include a cemetery where the Marked count is zero.
Answer: You want to use left join:
SELECT c.Name, c.CEMID, COUNT(g.Marked) AS Count
FROM Cemetery c LEFT JOIN
     Grave g
     ON c.CEMID = g.CEMID AND g.Marked = TRUE
WHERE c.CountyID = 352
GROUP BY c.CEMID;

Changes to the query:

The county table is not needed.  You can get the id from cemetary.
The joins are now left join.
The condition on Marked has been moved to the on clause instead of the where clause.
The use of table aliases makes the query easier to write and to read.
Comment: Thanks, that worked.  The execution time was rather long for the query.  It took almost 33 seconds on the example from my database with 200 cemeteries and 900 graves.
Comment: If this query is taking seconds to complete on such small data, then you need indexes on columns used in the `join`.

Zero COUNTs in JOIN with three tables


What exactly is the boot disk from google cloud platform (cgp) compute engine?

Question: I want to use google's compute engine as a database. When using the calculator, I got confused about what the
boot disk is. Google's documentation didn't help either. Is the boot disk only for the OS or is it where everything is stored? If I don't specify the boot disk size, will I be able to set up my database in the compute engine? If yes, what would be the storage limit for the database?
Answer: Boot disk is simply the first disk attached to the instance. It will have a boot loader and OS installed to it.
It has same performance characteristics as any other Persistent Disk volumes you may attach to a VM (with a few minor exceptions). You can also install database and keep all the data on it.
But many people prefer to separate their data disk and OS disk. This allows apply different disaster recovery policies to those disks. It is also not uncommon to treat boot devices as ephemeral. Meaning people can just throw away boot disk, keep data disk and rebuild VM from scratch (e.g. during upgrade, or as a mitigation to an outage) while still keeping the data.
Separation of OS and data can be used for efficiency/price optimization. Boot devices rarely require high performance so those can be created as Balanced or even Standard PD, while it could make sense to put database files to higher performing SSD PD or even Extreme PD. If durability does not matter much data can be placed to local SSD.
The one caveat that pops to mind is that you can't have Regional PD as your boot disk. Meaning if you want to use it you must have zonal device attached as a boot disk and regional device as 2nd, or 3rd, or Nth device.
Comment: Yes. And it is currently not possible to use Regional disk as a first/boot device. Note that zonal devices still provide redundancy against regular hardware failures.
Comment: Does that mean that boot disks are always equivalent to zonal disks with respect to data redundancy characteristics?


Eclipse RCP Java Perspective extension

Question: I want to extend the default Eclipse IDE 'Java' perspective with a new view which will be by default opened in the bottom panel (where we have for instance 'Problems', 'Search', 'Console', etc).
How to ensure that my new view will be shown in that bottom panel in the first position (before 'Problems' view)?
Answer: Use Perspective Extension.
In you extension node add a view node and set relative and relation attribute to accomplish your needs.
<extension point="org.eclipse.ui.perspectiveExtensions">
    <perspectiveExtension
        targetID="existing Perspective ID to extend">
        <view id="Your View ID"
            relative="offset View ID"
            relationship="relation"/>

        <view id="org.eclipse.jdt.ui.TypeHierarchy"
            relative="org.eclipse.ui.views.ResourceNavigator"
            relationship="left"
            ratio="0.50"/>
    </perspectiveExtension>
</extension>

Comment: This is what I tried but then I got those views in separate 'folders' so i see them separately. Do I need to setup any flag, value etc?!
Answer: Perspective Extensions is the correct answer but you should use:

relationship="stack"
relative="org.eclipse.ui.console.ConsoleView"

Example:
<perspectiveExtension
            targetID="org.eclipse.jdt.ui.JavaPerspective">
         <view
               id="your.view.id"
               minimized="false"
               relationship="stack"
               relative="org.eclipse.ui.console.ConsoleView">
        </view>
</perspectiveExtension>

Start your Eclipse with your Plugin and open the View. It should appear next to the Console-View

Eclipse RCP Java Perspective extension


Page displays everything that is in the database

Question: The PageSize field indicates that information should be displayed on one page, about eight objects, but the page displays everything that is in the database.
        private readonly IObjectRepository _objectRepository;
        private readonly IWebHostEnvironment hostingEnvironment;
        public int PageSize = 8;

        public HomeController(IObjectRepository objectRepository, IWebHostEnvironment hostingEnvironment)
        {
            _objectRepository = objectRepository;
            this.hostingEnvironment = hostingEnvironment;
        }

        public ViewResult Index(int objectPage)
        {
            var model = _objectRepository.GetAllObjects();
            model.OrderBy(o => o.Id)
                 .Skip((objectPage - 1) * PageSize)
                 .Take(PageSize);
            return View(model);
        }

Comment: [How to ask](https://stackoverflow.com/help/how-to-ask) "Does not work" is not a technical description of a problem.
Comment: Sry, my bad. Corrected.
Answer: Skip and Take return a new IEnumerable as a result, instead of modifying the existing one in place. So, you should replace this line:
model.OrderBy(o => o.Id)
             .Skip((objectPage - 1) * PageSize)
             .Take(PageSize);

with:
model=model.OrderBy(o => o.Id)
             .Skip((objectPage - 1) * PageSize)
             .Take(PageSize);

This way, you assign the new query value to the baseQuery and then when you enumerate it, it will return the expected entities.
Answer: Thanks everyone! I found another solution with Methanit, thanks him a lot.
1 - Changed my PageViewModel
public class PageViewModel
    {
        public int PageNumber { get; set; }
        public int TotalPages { get; set; }

    public PageViewModel(int count, int pageNumber, int pageSize)
    {
        PageNumber = pageNumber;
        TotalPages = (int)Math.Ceiling(count / (double)pageSize);
    }

    public bool HasPreviousPage
    {
        get
        {
            return (PageNumber > 1);
        }
    }

    public bool HasNextPage
    {
        get
        {
            return (PageNumber < TotalPages);
        }
    }
}

2 - Changed method Index in Controller:
public IActionResult Index(int page = 1)
        {
            int pageSize = 6;
            var model = _objectRepository.GetAllObjects();
            var count = model.Count();
            var items = model.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            PageViewModel pageViewModel = new PageViewModel(count, page, pageSize);
            IndexViewModel viewModel = new IndexViewModel
            {
                PageViewModel = pageViewModel,
                Objects = items
            };
            return View(viewModel);
        }

3 - The application is working correctly.
Thanks all a lot!


Exploratory factor analysis of turtle data

Question: I'm learning a bit about exploratory factor analysis working with some datasets, but some doubts came in mind.
I'm using this data to practice turtle data. I have two groups of turtles: male and female and measures of 3 variables length, width and height.
The output of factor model using R is
<code>  Uniquenesses:
        length     width     height
    0.017 0.026 0.053

    Loadings:
      Factor1
    length 0.991
    width 0.987
    height 0.973

               Factor1
SS loadings      2.904
Proportion Var   0.968

The degrees of freedom for the model is 0 and the fit was 0
</code>
The above result, shows that a single factor is good enough to describe the covariance structure of the data. Then I calculated the factor scores using the regression option and did a plot of it

(1) Clearly there are differences between males and females, but what conclusions could I draw from the scores?
(2) In this case I have a single factor and can't do a biplot, how I could check what variable is the one that most differentiates males and females?
(3) I used some rotation (varimax and promax) and results were the same that I get without rotation. Is it because I have a single factor?
(4) Is there any difference between use Regression Scores and Barlett scores?
Comment: I think that tag multivariate analysis is not appropriate here.
Answer: That's four questions.  I will take them one at a time:

(1) Clearly there are differences between males and females, but what
  conclusions could I draw from the scores?

First, if you are interested in differences between males and females, I'd look at a parallel boxplot and a t-test. However, one conclusion is clear: While both males and females can have negative or small positive scores, only males have scores over about 1.  Since the variables all have positive loadings, this means that large turtles are all male.

(2) In this case I have a single factor and can't do a biplot, how I
  could check what variable is the one that most differentiates males
  and females?

With length, width and height, this is unlikely to be fruitful because the 3 variables are likely to be highly correlated. I haven't checked the correlations, but you could easily do so.  If you really wanted to do this, you could run 3 t-tests comparing males and females on the 3 variables and seeing which had the largest t.

(3) I used some rotation (varimax and promax) and results were the
  same that I get without rotation. Is it because I have a single
  factor?

Yes.  With only one factor, there is nothing to rotate.

(4) Is there any difference between use Regression Scores and Barlett
  scores?

I don't know.
Comment: Although the name already says that this is an exploratory analysis, the only thing that is expected is to study the correlation structure of the data?
Comment: Ummm, I don't understand your question @Roland


How can I make this LINQ query?

Question: I have a Dropdownlist that I fill with all consultants.
This is my entities I am using for this LINQ query:

What I want to do is to get all consultants ids that have a goalcard with Complete_date set. I have no idea how to do this.
Right now I have this following LINQ query to get all consultants ids.
public List<Consultant> GetAllConsultantsByID()
{
    var allConsultants = from id in db.Consultant
                         select id;
    return allConsultants.ToList();
}

Any kind of help is appreciated
Thanks in advance
Update:
This is how I have to use my Linq method in my Get Action Method:
var consultants = repository.GetAllConsultantsByID();
model.Consultants = new SelectList(consultants, "Id", "Name");

Comment: Right, I have seen that you want a full `Consultant` object a bit late, edited my answer to reflect that too :)
Answer: You can use the Consultant.GoalCard navigation property and the Any extension method:
var query = from con in db.Consultant
            where con.GoalCard.Any(card => card.Completed_Date != null)
            select con;
return query.ToList();

Consultant.Goalcard exposes all GoalCards of the Consultant as a queryable property. So you can perform queries on that, too. (This example assumes Completed_Date is nullable)
Note: Seeing that a Consultant can have several GoalCards, you might want to rename the Consultant's GoalCard navigation property to GoalCards (to make it clear there can be several).
Comment: And +1 to you (because why not?) for a different syntax and more elaborate answer! :)
Comment: Thanks for a great answer but Its not working for me since my List have to be List beacuse List is not working.
Comment: @RammtinAvar You said "What I want to do is to get all consultants ids", that was confusing me. Updated my answer, it now returns a `List`.
Answer: Now assuming the Complete_Date is of type DateTime?, you could do it like that:
public IEnumerable<Consultant> GetConsultantIds()
{
     return db.Consultant.Where(c => c.GoalCard != null && c.GoalCard.Completed_Date.HasValue).Select(c => c.Id).AsEnumerable();
}

[EDIT]
Since GoalCard is a collection (misleading name :) ), you can do something like that to get the IDs of Consultants who have at least one completed date set on any of the cards:
public IEnumerable<int> GetConsultantIds()
{
     return db.Consultant.Where(c => c.GoalCard != null && c.GoalCard.Any(card => card.Completed_Date.HasValue)).Select(c => c.Id).AsEnumerable();
}

That's for the list of IDs only, for the list of Consultant objects meeting the criteria:
public IEnumerable<Consultant> GetConsultantIds()
{
     return db.Consultant.Where(c => c.GoalCard != null && c.GoalCard.Any(card => card.Completed_Date.HasValue)).AsEnumerable();
}

Comment: I tried your code but GoalCard doesnt have any properties I cant type `c.GoalCard.Completed_date`
Comment: c.GoalCard is a collection so you need to query the collection
Comment: Ah, right, it changes the approach a bit. But should it return the IDs of the consultants who have ANY of the cards' dates set, all of the dates, some of the dates...? :)

How can I make this LINQ query?


Views - Clicked element + corresponding content

Question: I have a content type which contains the following fields

title
text body
image

An I need to achieve something like below

The 4-image grid is a view which covers 50% of the page. The green coloured box represents the clicked image. I need the text-area right next to the view to contain the the text corresponding to the image which is clicked.
Is it possible to achieve this using views alone?
Comment: Yes, it is absolutely possible! Apart from views it goes without saying that ajax is essential, except if you want a page reload when an image is clicked.
Comment: @mchar : thanks , I don't want a page reload. I've enabled ajax for this view.
Answer: Step 1: Create the View, the block and the required fields (order matters).
Block's instructions (page can be different):

Format:

Grid
Number of columns: 2

Fields:

Nid: Exclude from display
Title:

Link this field to the original piece of content: Unchecked
REWRITE RESULTS -> Rewrite the output of field -> Output this field as a link -> Link path: ajax-link/nojs/[nid]
Link class: use-ajax

Image:

Link image to: Nothing
REWRITE RESULTS -> ... Same as "Title"
Link class: use-ajax

So, the title's or image's url should have this structure: hook-menu-registered-path/nojs/argument
Step 2: Create a custom module and implement the following code.
/**
 * Implements hook_menu.
 */
function custom_module_menu() {
  // A menu callback is required when using ajax outside of the Form API.
  $items['ajax-link'] = array(
    'page callback' => '_custom_module_response',
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 *  Callback function.
 *
 * @param int $nid
 *   Either a valid node id or 0 (zero) if not available.
 *
 *  @param string $type
 *   Either 'ajax' or 'nojs. Type is simply the normal URL argument to this URL.
 *
 *  @return string|array
 *    If $type == 'ajax', returns an array of AJAX Commands,
 *   otherwise, just returns the content, which will end up being a page.
 */
function _custom_module_response($type, $nid = 0) {
  $output = _custom_module_node_load($nid);
  if ($type == 'ajax') {
    $commands = array();
    // Selector: A jQuery selector string, either a .class or #id.
    $commands[] = ajax_command_replace('.selector', '
' . $output . '
');
    $page = array('#type' => 'ajax', '#commands' => $commands);
    ajax_deliver($page);
  }
  else {
    $output = isset($output) ? '
' . $output . '
' : t('Node does not exist!');
    return $output;
  }
}

/**
 *  Node loader function.
 *
 *  @return string
 *   The themed node in its define view mode.
 */
function _custom_module_node_load($nid = 0) {
  $node = node_load($nid);
  if ($node) {
    $pre_rendered_node = node_view($node, $view_mode = 'full');
    return theme('node', $pre_rendered_node);
  }
}

Step 3: Load the necessary library. I chose the template.php file to do it.
/**
 * Implements template_preprocess_views_view.
 */
function custom_theme_preprocess_views_view(&$vars) {
  $view = $vars['view'];
  if ($view->name == 'my_view_name') {
    // drupal_add_library is invoked automatically when a form element has the
    // '#ajax' property, but since we are not rendering a form here, we have to
    // do it ourselves.
    drupal_add_library('system', 'drupal.ajax');
    $output = '
' . $vars['rows'];
    $output .= '
';
    $vars['rows'] = $output;
  }
}

Now, should only the body field must be displayed (or a certain set of fields) I suggest the definition of a view mode per case, then define that view mode to the node_view function.

Note:
Ajax framework's "magic" class: use-ajax

By adding the 'use-ajax' class to a link, the link will be loaded via an Ajax call. When using this method, the href of the link can contain '/nojs/' as part of the path. When the Ajax framework makes the request, it will convert this to '/ajax/'. The server is then able to easily tell if this request was made through an actual Ajax request or in a degraded state, and respond appropriately.

Ref.: Drupal examples modules, How to use Drupal 7's built-in Ajax Framework
Comment: Thankyou so much. I've already had found a workaround since I ran out of time. I used two view grids and wrote some jquery to add an class which then is used to selectively display content at the right pane. However, this looks exactly like what I was looking for. I'll keep you posted when I implement this. Again, hats off !!


Return array object in asp.net WebAPI

Question: I want to create WEB API which sends input to Angular. I want to send data in JSON format as an array.
Below is my code:
[HttpGet]
[ActionName("GetEmployeeByID")]
public Employee Get(int id)
{
    Employee emp = null;
    while (reader.Read())
    {
        emp = new Employee();
        emp.ClientId = Convert.ToInt32(reader.GetValue(0));
        emp.ClientName = reader.GetValue(1).ToString();
    }
    return emp;
}

Actual output:
{"ClientId":15,"ClientName":"Abhinav Singh"}

Expected output:
[{"ClientId":15,"ClientName":"Abhinav Singh"}]

Comment: you are returning a single object. Send a list of employees and add that employee to the list.
Comment: The actual output is correct if you should stick with the rest principles. If you ask for a user by Id, you don't expect to get a list in return..
Answer: Your code return only a single element. Change it to return a collection by using List   as follows,
  public List<Employee> Get(int id)
    {
        Employee emp = null;
        List<Employee> _employees = new List<Employee>();
        while (reader.Read())
        {
            emp = new Employee();
            emp.ClientId = Convert.ToInt32(reader.GetValue(0));
            emp.ClientName = reader.GetValue(1).ToString();
            _employees.Add(emp);
        }
        return _employees;
     }

Return array object in asp.net WebAPI


Java: How to profile a single request in production

Question: I am looking for something like Jvisualvm's polling profiler that can be used in production to profile a single method call.
I can not use visualvm in production or any of the other external tools available for a number of reasons.
I am looking for Java code that I could add to my code to profile a specific method call.
I can not find anything that does this without using an external tool.
Answer: I thought I would share my solution here, if anyone has a better one please share.
It is an Aspect but can also be used directly like this...
void test()
{
   Profiler profiler = new Profiler(Thread.currentThread(), joinpoint.getTarget().getClass().getSimpleName());

   // call some methods here

   profiler.dump();
}

This is the Profiler Class.
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;

import com.google.common.base.Stopwatch;

import au.com.noojee.aspects.AspectProfile.Tree.Node;
import au.com.noojee.aspects.annotations.AopProfile;

@Aspect

public class AspectProfile
{

    @Pointcut("execution(@au.com.noojee.aspects.annotations.AopProfile * *.*(..))")
    public void serviceMethods()
    {

    }

    @Around("serviceMethods()")
    public Object aroundMethod(final ProceedingJoinPoint joinpoint) throws Throwable
    {

        MethodSignature signature = (MethodSignature) joinpoint.getSignature();
        Method method = signature.getMethod();

        AopProfile myAnnotation = method.getAnnotation(AopProfile.class);
        long minTimeToLog = myAnnotation.minimumMs();

        Stopwatch timer = Stopwatch.createStarted();
        Profiler profiler = new Profiler(Thread.currentThread(), joinpoint.getTarget().getClass().getSimpleName());
        try
        {
            return joinpoint.proceed();
        }
        finally
        {
            try
            {
                if (timer.elapsed(TimeUnit.MILLISECONDS) > minTimeToLog)
                {
                    LoggerFactoryForAspects.getLogger().warn("Invokation of {}.{}(...) took {}ms",
                            joinpoint.getTarget().getClass().getSimpleName(), joinpoint.getSignature().getName(),
                            timer.elapsed(TimeUnit.MILLISECONDS));
                    profiler.dump();
                }
            }
            catch (Exception e)
            {
                LoggerFactoryForAspects.getLogger().error(e, e);
            }
        }

    }

    public class Profiler implements Runnable
    {
        private final String name;
        private final Thread threadToProfile;
        private final Tree<Call> calls = new Tree<Call>(new Call());
        private final ScheduledFuture<?> future;

        Profiler(Thread threadToProfile, String name)
        {
            this.threadToProfile = threadToProfile;
            this.name = name;
            // future = Executor.scheduler.scheduleAtFixedRate(this, 100, 100,
            // TimeUnit.MILLISECONDS);

            future = Executors.newScheduledThreadPool(1).scheduleAtFixedRate(this, 100, 100, TimeUnit.MILLISECONDS);

        }

        public void dump()

        {
            future.cancel(false);
            dumpNode(calls.root, "");
        }

        void dumpNode(Node<Call> node, String indent)
        {

            LoggerFactoryForAspects.getLogger().warn("'{}' {} [ {} ] {}", name, indent, node.data.count,
                    node.data.name);
            if (node.children.size() > 1)
            {
                LoggerFactoryForAspects.getLogger().warn("'{}' {} children: {}", name, indent, node.children.size());
            }
            for (Node<Call> child : node.children)
            {
                String ch = " ";
                if (node.children.size() > 1)
                {
                    ch = "+";
                }
                dumpNode(child, indent + ch);
            }
        }

        class Call implements Comparable<Call>
        {
            int count = 1;
            String name;

            @Override
            public int compareTo(Call o)
            {
                return count - o.count;
            }

            @Override
            public int hashCode()
            {
                final int prime = 31;
                int result = 1;
                result = prime * result + getOuterType().hashCode();
                result = prime * result + ((name == null) ? 0 : name.hashCode());
                return result;
            }

            @Override
            public boolean equals(Object obj)
            {
                if (this == obj)
                    return true;
                if (obj == null)
                    return false;
                if (getClass() != obj.getClass())
                    return false;
                Call other = (Call) obj;
                if (!getOuterType().equals(other.getOuterType()))
                    return false;
                if (name == null)
                {
                    if (other.name != null)
                        return false;
                }
                else if (!name.equals(other.name))
                    return false;
                return true;
            }

            private Profiler getOuterType()
            {
                return Profiler.this;
            }
        }

        @Override
        public void run()
        {
            Node<Call> node = calls.root;
            List<StackTraceElement> elements = new LinkedList<>();
            for (StackTraceElement element : threadToProfile.getStackTrace())
            {
                elements.add(element);
            }
            Collections.reverse(elements);
            for (StackTraceElement trace : elements)
            {

                Call call = new Call();
                call.name = trace.toString();
                if (!call.name.startsWith("java") && !call.name.startsWith("sun") && !call.name.startsWith("org")
                        && !call.name.startsWith("com."))
                {
                    node = node.findOrCreateChild(call);
                }

            }
            node.data.count++;
        }

    }

    public static class Tree<T>
    {
        private final Node<T> root;

        public Tree(T rootData)
        {
            root = new Node<T>();
            root.data = rootData;
        }

        public static class Node<T>
        {
            private T data;
            // private Node<T> parent;
            private List<Node<T>> children = new LinkedList<Node<T>>();

            Node<T> findOrCreateChild(T target)
            {
                for (Node<T> node : children)
                {
                    if (node.data.equals(target))
                    {
                        return node;
                    }
                }
                return addChild(target);
            }

            Node<T> addChild(T value)
            {
                Node<T> node = new Node<>();
                node.data = value;
                // node.parent = this;
                children.add(node);
                return node;

            }
        }
    }

}


Improper integral: $\int_0^\infty \frac{\sin^4x}{x^2}dx$

Question: I have been trying to determine whether the following improper integral converges or diverges:
$$\int_0^\infty \frac{\sin^4x}{x^2}dx$$
I have parted it into two terms. The first term: $$\int_1^\infty \frac{\sin^4x}{x^2}dx$$ converges (proven easily using the comparison test), but the second term:
$$\int_0^1 \frac{\sin^4x}{x^2}dx$$ troubles me a lot. What could I do?
Comment: you can bound the integral by $1/x^2$ on $[1, \infty]$. on $[0, 1]$ use $sin(x)\leq x$
Comment: Hint: $\frac{\sin^{4}(x)}{x^{2}}$ is continuous on $[0,1]$
Comment: A Taylor expansion of the numerator around $x=0$ will suffice.
Comment: @tired You are right, that works as well. Thanks.
Answer: The inequality $\left|\sin x\right|\leq\min(1,|x|)$ is enough to prove that the integral is converging.
Integration by parts and the well-known $\int_{0}^{+\infty}\frac{\sin x}{x}\,dx=\frac{\pi}{2}$ then give:
$$\begin{eqnarray*} I = \int_{0}^{+\infty}\frac{\sin^4 x}{x^2}\,dx &=& \int_{0}^{+\infty}\frac{4\cos x \sin^3 x}{x}\,dx\\&=&\int_{0}^{+\infty}\frac{\sin(2x)-\frac{1}{2}\sin(4x)}{x}\,dx\\&=&\left(1-\frac{1}{2}\right)\int_{0}^{+\infty}\frac{\sin x}{x}\,dx=\color{red}{\frac{\pi}{4}}.\end{eqnarray*}$$
Answer: For the second term, you can re-write your function as $\frac{\sin x}{x} \cdot \frac{\sin x}{x} \cdot \sin^2(x)$.  Note that on $[0,1]$, this function is continuous (by the Fundamental Trig Limit you can extend the function to be defined as $f(0)=1$ at $x=0$).  But then any continuous function on a closed interval is integrable, so $\int_0^1 \frac{\sin^4(x)}{x^2}$ converges.  Hence the whole integral converges.
Comment: Clever solution to the problem. Thanks for your answer!


Python Add_Lowest to sns.lineplt

Question: How can i make the line disappear?
rmodel = sm.GLM.from_formula("rBPXSY1 ~ rRIDAGEYR", data=da)
res = rmodel.fit()
res.summary()

pp = sns.lineplot(da.rRIDAGEYR,da.rBPXSY1,alpha=0.4, marker='o', ls='')
add_lowess(pp)

Intended result

**My result **
Comment: statsmodels' `add_lowess` needs the plot to be a lineplot. `ax = sns.lineplot(y=..., x=..., alpha=0.4, marker='o', ls='')` or maybe `ax = sns.lineplot(y=..., x=..., alpha=0.4, marker='o', ls='')`. And then `add_lowess(ax)`. Don't forget to add `from statsmodels.graphics.regressionplots import add_lowess` to your code.
Comment: Hi JohanC thanks, i will try that out. However the tutorial answer given was that the data was plotted in scatterplot (shown above in intended result). Do you mean that i plot both scatterplot and lineplot and then use the lineplot for the `add_lowess(ax)` then hide the lineplot?
Comment: With `ax = sns.lineplot(y=..., x=..., alpha=0.4, marker='o', ls='')` you create a lineplot that looks like a scatterplot.
Comment: Hi i have modified accordingly, the red line is showing however the line traces is still be seen. Anyway totally eliminate it?
Comment: Are you using the latest versions of seaborn and matplotlib?   Maybe setting `ls='none'` works in your case.  By the way, it is recommended to call the return value of `sns.lineplot` something like `ax` to ease understanding how matplotlib retouches to the subplot can be called.
Answer: When using the latest versions of each package, and running
import statsmodels.api as sm
import numpy as np
import seaborn as sns
from statsmodels.graphics.regressionplots import add_lowess

g = np.random.default_rng(0)
x = g.random(size=1000)
y = 5*np.sin(2*np.pi*x) + g.standard_normal(1000)
pp = sns.lineplot(x=x,y=y,alpha=0.4, marker='o', ls='')
pp = add_lowess(pp)

you get an image like the one you desire:

Python Add_Lowest to sns.lineplt


Showing that every abelian group is metabelian.

Question: Some terms before I define my problem:

Definition: A group is abelian if every pair of elements commutes.
Proposition: All subgroups of an abelian group are normal.
Definition: A group $G$ is called metabelian if it has an abelian normal subgroup $N$ such that $G/N$ is also an abelian group.

I am tasked with proving that every abelian group is metabelian, but I have no idea where to start. I am inclined to believe that I should prove that $G/N$ is abelian if $G$ is abelian and $N$ is a normal subgroup. This satisfies the definition of metabelian, and since $G$ and $N$ are arbitrary, shouldn't that conclude the argument?
Comment: Not following.  Why can't you just take $N=\{e\}$?  All you need one "good" $N$, right?
Comment: Well...can you see that taking $N=\{e\}$ works for any abelian group $G$?  Alternatively, take $N=G$.  Same principle.
Comment: I am not sure what you mean by that, to be honest. How would I use that to prove all abelian groups are metabelian?
Comment: By the way, another standard definition is to say that $G$ is [metabelian](https://en.wikipedia.org/wiki/Metabelian_group), if it is $2$-step solvable, i.e., if $[G,G]$ is abelian. For an abelian group $G$ this is even more obvious.
Answer: Suppose $G$ is abelian.
Each subgroup of an abelian group is both abelian and normal in the group; in particular, $G\unlhd G$.  Observe that $G/G$ is isomorphic to the trivial group, which is abelian.
Hence $G$ is metabelian.
Comment: And one could equally well take $N=\{e\}$ instead of $N=G$.


Environment variable set but HostingEnvironment.EnvironmentName not updated

Question: Am running .net core 2.2 and hosting asp.net core within a windows service.
eg.  see this https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.2&tabs=visual-studio
I set the environment variable ASPNETCORE_ENVIRONMENT to "Dev"
Just to confirm, within my launchsettings.json
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT ": "Dev"
  }

When starting up the value of HostingEnvironment.EnvironmentName is not updated and still has "Production" which is default.  Why is it not "Dev"?
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .ConfigureLogging((hostingContext, logging) =>
        {
            logging.AddEventLog();
        })
        .ConfigureAppConfiguration((context, config) =>
        {

            // Configure the app here.
            var env = context.HostingEnvironment;
            config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                              .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);

        })
        .UseStartup<Startup>();

}
Comment: Hopefully it's just a typo, but you've got a trailing space in `ASPNETCORE_ENVIRONMENT ` in your `launchSettings.json`.
Comment: I've added ASPNETCORE_ENVIRONMENT: Development in system environment variables. But still, I'm getting Production as Environment name from hostingContext.HostingEnvironment.EnvironmentName. Am i missing anything here?
Comment: Did you solve this? I have the exact same problem.
Comment: Check [Use multiple environments in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-2.2#environment-based-startup-class-and-methods). The docs explain that .NET Core recognized just three values for that environment variable, Development, Staging and Production. It could be that `EnvironmentName` is only set when the contents of the environment variable are recognized
Comment: You mean like a system level environment var?  See above screenshot, I have the environment var set only in the IDE.
Comment: The docs also explain that this setting is used to control several debugging features. The runtime has no idea what `Dev` means so the correct behavior would be to default to production - or throw.
Comment: We have environments like QA and UAT and those are set correctly.
Comment: The framework supports setting it to any value, but the default WebHost builder will only include user secrets in the "Development" environment by default, so that won't work if yours is something else. But you can call your environments anything and add your own extension methods to check for your environments.
Comment: @Kirk - oh good grief, that was it!  Good catch.  I thought I was going nuts
Answer: I spent quite a while trying to work out the best thing for me to do in this situation.
I ended up taking the code from Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder and adding the .UseEnvironment extension on the builder.
            builder.UseEnvironment(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development");

I default to Development rather than the generally preferred Production, but that was personal preference.
It is limited and if you want to be clever and check for commandline arguments etc and so forth, feel free. It's a place to start.
public static IHostBuilder CreateDefaultBuilder(string[] args)
{
    var builder = new HostBuilder();

    // This line has been added to read the environment variable.
    builder.UseEnvironment(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development");

    builder.UseContentRoot(Directory.GetCurrentDirectory());
    builder.ConfigureHostConfiguration(config =>
    {
        config.AddEnvironmentVariables(prefix: "DOTNET_");
        if (args != null)
        {
            config.AddCommandLine(args);
        }
    });

    builder.ConfigureAppConfiguration((hostingContext, config) =>
    {
        var env = hostingContext.HostingEnvironment;

        config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);

        if (env.IsDevelopment() && !string.IsNullOrEmpty(env.ApplicationName))
        {
            var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
            if (appAssembly != null)
            {
                config.AddUserSecrets(appAssembly, optional: true);
            }
        }

        config.AddEnvironmentVariables();

        if (args != null)
        {
            config.AddCommandLine(args);
        }
    })
    .ConfigureLogging((hostingContext, logging) =>
    {
        var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

        // IMPORTANT: This needs to be added *before* configuration is loaded, this lets
        // the defaults be overridden by the configuration.
        if (isWindows)
        {
            // Default the EventLogLoggerProvider to warning or above
            logging.AddFilter<EventLogLoggerProvider>(level => level >= Microsoft.Extensions.Logging.LogLevel.Warning);
        }

        logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
        logging.AddConsole();
        logging.AddDebug();
        logging.AddEventSourceLogger();

        if (isWindows)
        {
            // Add the EventLogLoggerProvider on windows machines
            logging.AddEventLog();
        }
    })
    .UseDefaultServiceProvider((context, options) =>
    {
        var isDevelopment = context.HostingEnvironment.IsDevelopment();
        options.ValidateScopes = isDevelopment;
        options.ValidateOnBuild = isDevelopment;
    });

    return builder;
}

Answer: Kept coming back to this question when a .NET project wouldn't build correctly. It should be looking for ASPNETCORE_ENVIRONMENT. I found it works best just to export all versions of environment that could be used when looking for "environment" in .NET.
context.HostingEnvironment.EnvironmentName;

So I export ENVIRONMENT, ASPNETCORE_ENVIRONMENT, DOTNET_ENVIRONMENT all as the environment you are trying to make. So in this case all set to "dev".


Create a new Data.table from another one and match a vector list on one variable

Question: I have a data.table with  2.7 million observations and 21 variables  and need to produce a new data.table in which Variable 1 matches a vector of values.
I have vector of values that match with some of Variable1 values, like the following
VectorValue=  (A, B, XXZ, UDD...)

I was thinking of something like:
Table_B <- Table_A[Table_A$Variable1 == VectorValue]

or
Table_B <- Table_A[Variable1 == VectorValue]

but I get this error:

When i is a data.table (or character vector), the columns to join by must be specified either using 'on=' argument (see ?data.table) or by keying x (i.e. sorted, and, marked as sorted, see ?setkey). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.
Comment: You might want to work on making a reproducible example https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/28481250#28481250 Your example is too barebones for me to understand it, anyways.
Comment: can you use `dput(head(Table_A))` to give us a look at data structure?
Answer: Two options I see here:

VectorValue is the same length as Table_A$Variable1 and you want to compare values in the same position and return a subset of the data frame where those values are equal. In this case, you may just need to add a comma like so...

Table_B <- Table_A[Table_A$Variable1 == VectorValue, ]
...to indicate that you want all rows where the condition is TRUE and all of the columns in Table_A.

You want to return any row of Table_A where Table_A$Variable1 has a value that matches any value within VectorValue. In this case, you'd want to use the %in% operator instead of ==, like so...

Table_B <- Table_A[Table_A$Variable1 %in% VectorValue, ]
Comment: Thank you Keith, second option seems good, as VectorValue is not of the same lenght.