Do I need some kind of power conditioner or UPS?

Question: In one of my boxen, both my power supply and network card died while in overnight hibernation  - why?
And: What must I do to appease the electricity Gods so that I don't lose more hardware?
In my home I've got... five computers in various states of use (monthly through to continuous), and I've lost power supplies for all of them, including the laptop, generally in lumps (several components around the same time).  These losses have also included other bits and bobs, including a hard drive.
Do I need some kind of power conditioner?  Those power-boards with surge protection, that's just a marketing lie, right?  And a cheap UPS isn't going to filter the electricity any, is it?  So what do I do, spend up big?
Comment: If you do get a UPS most allow you to install corresponding software to monitor their work (PowerChute for APC).  It's interesting to see how often they kick in and if there's a regular pattern to it.
Comment: Also note that a UPS draws about 15amps, continuously! Most household circuits are rated at 20amps so plugging in a UPS will use 75% of that circuit. Do not plug in two UPS' to the same circuit (like I did). If you don't pop the circuit breaker then you'll potentially cause a fire (my circuit breaker didn't pop, but fortunately the only effect was the wire into the breaker melted).  Typically the computer equipment doesn't draw 15amps (case 4 amps, monitor <1 amp, printer 1 amp, router <1 amp, cable modem <1 amp).
Answer: I'm in an area with variable power and daily brownouts, and lost a lot of gear like you. I added a 2u APC rackmount UPS, big thing, and put nearly everything on it. It was wildly successful. The UPS would go on and off all day long, even when I could see no other evidence of power fluctuation. No more hardware losses. So I went and bought more of these big UPSs and put all my stereo gear on one, and other electronic clusters on another. The damage to my gear stopped.
I didn't buy brand new APC UPSs, I waited till they had sales and I bought reconditioned units. That kept the cost down.
Bottom line - I think you need something to smooth your electricity. I don't think it is a marketing lie, but I think you need more than the consumer versions of UPSs available.
Answer: My experience:

Cheap "surge suppresser" powerbars: useless.
Expensive "surge suppressor" powerbars: not quite useless.  They will protect from momentary low spikes, but can't do anything about dips, brownouts, or blackouts.
Cheap UPS (ie APC Back-UPS): reasonable assuming you are not putting too much load on them and the environment they run in is reasonably (electrically) clean.  I use them for my workstations at home, and they get fresh batteries every two years whether they need them or not, which they always do.  I would not put server or mission-critical gear on such a UPS.
Mid-range UPS (ie APC Smart-UPS): adequate entry-level server protection.  The problem is that you either over-buy UPS (ie a Smart-UPS 3000 powering one web server) or you end up gradually acquiring way more computer than the Smart-UPS can reasonably drive (ie: the same Smart-UPS 3000 powering a NetApp 760 with eight fully populated DS-7 shelves).  Management (snmp, plus some form of software to deal with the load) is mandatory.  Battery lifespan management is mandatory.

After that, the sky's the limit but you will end up having to install special electrical circuits to power them.  The software to deal with them is also astronomically priced.
I always complain to customers that they are under-protected because they almost always are.  And when they balk at the cost, I ask them what the cost to the business will be if "whatever is currently inadequately protected" fails.
For home, I currently only have one workstation -- only need one, thanks to VMware -- and it has its own BackUPS-750.  The rest of the "networking gear" (one Linksys wireless router and one cable modem) runs off of a old Belkin 500Va UPS that currently needs a battery refresh.
So, bottom line:

Yes, get a UPS.  Even an entry level one is better than the nothing you currently have.
If you are not running a particular computer, physically disconnect it from the mains unless you require some form of wake-on-LAN.
Answer: Under normal circumstances a UPS should protect you from spikes in the power net.
Ideally a UPS has a power supply that is disconnected from the power it gives to you PC that way it irons out most of the stuff. I vaguely remember some cases where a UPS won't help either but I'm pretty sure someone else can give a technically more correct answer, hence this is just a community wiki.
Answer: Yes.  Power fluctuations, sags, and the like are not kind to computer equipment.  It's not just marketing hype, although it depends a lot on the quality of power you get from your power company.  It also depends on what other kinds of equipment share the circuit with your computers, and on what kinds of electrical noise they create.
So far, I have not lost any component of a computer connected to a UPS due to power-related reasons.  (I did lose much of one computer that was connected to a UPS, but the power supply fan stopped spinning and it overheaded very badly.  This wasn't due to electricity!)
I've lost several power supplies over the years -- so far nothing more critical -- on computers not connected to a UPS, and not after any obvious cause such as a thunderstorm.
Answer: I don't know why  your equipment died, but I can tell you that UPS's have saved my business continuity multiple times.
I don't know how many servers (or how big they are) but a general purpose APC 1500 tower is probably sufficient for your needs, unless you run a rack of equipment.
It also has voltage sensitivity settings. This was useful for me as it was hooked to a generator, and without lowering sensitivity, the generator was not able to output a normal enough signal for the UPSes to cope.
You want battery backup if you want your equipment to be up (or at least, to power down gracefully)
Answer: Yes, yes, yes. But I don't know what to recommend you buy, because power is complicated stuff, vendors of low-end equipment just lie, vendors of high-end equipment don't give adequate explanations.
You want to filter out voltage spikes caused by lightning strikes and by normal fluctuations on the power grid. Perhaps these are two different problems to solve. Whatever the solution, some areas of the world have frequent lightning strikes. It may not be enough to have insurance against this, you may need real protection if you want to stay in business. I don't know how to protect against a nearby lightning strike, but I know they are common in certain parts of the world and can not be ignored. In the Tampa Bay area, it is common for businesses to be destroyed by a nearby lightning strike.
You want to clean up the waveform provided by the power company. I don't know how important this is, but it's not something you can totally ignore.
You need to handle very short power spikes and power dropouts. Ones less catastrophic than blackouts and lightning strikes, but ones that may be very common. There's a continuum between cleaning up the waveform and protecting against surges and blackoutes. I suspect power supplies will last onger if they are given cleaner power, and that random crashes will be less frequent. I suspect that most UPSes don't protect against an ugly waveform. This is speculation and guessing. But if a scope can make me nauseous, it might damage your power supply.
You need to handle a brief (less than 10 minute) power loss. It happens. It's common. This is handled with what people normally call UPSes. I can't state whether UPSes provide the other features I speak of as well.
You need to handle a multi-day power outage. Diesel generators and fuel contracts that provide guarantees even in a widespread emergency.
You need to consider whether your business needs require automatic transfer from the UPS to the generator. It's surprisingly cheap. For many businesses, a single event can cover the cost.,
Remember that UPSes always create a risk of fire. It's a large amount of stored energy.
Answer: Its also worth noting that its a good idea to purchase higher end power supplies for your computers. While its tempting to buy low end "500 WATT SUPER MAX AWESOME SUPPLY" for $20 off newegg, buying something a bit more expensive will net you better capacitors and diodes and help prevent problems like this as well. They won't save you from having your computers turn off during a blackout like a UPS, but they will be more likely to take the hit than pass it on to a motherboard or harddrive.
I remember when I bought a new motherboard with PCI-express built in for the first time, and I didn't have one of those crazy 24 pin ATX supplies. I went out and bought a cheap one, only to hook up one of the 12v +/- connectors going to a powersupply while the machine was running, to see that it was actually 10.5 volts. Took it back. The computer shop refused to take it back because it "wasn't broken". If it was running at 10.5 volts under low load, what happens if my DVD-rom is spun up, harddrive is spinning, video card is sucking down 100 watts, and I get hit with a slight brown out? Or, if I take a surge and the cheap caps in it can't take a small hit?
IF your feeling especially cheap, you can get used UPS's with bad batteries for very cheap (I think I got one for 5$ once at a flea market). Go to walmart and get a motorcycle battery. Tada, now you have a UPS with a brand new battery for less than 1/4 of the price.
Comment: you really shouldn't use car/bike batteries, they won't last long in periods without charge (IE running)
Answer: We have been dealing with this with Optiplex 760 and now Dell says 960 also has this problem.  They gave us a list of rather expensive UPS (>$300) that all produce pure sine-wave power.  The UPS are fine we tried with all but the PC itself.  Once power out for a second or fluctuation the Optiplex dies.  It is not the UPS or watt amount rather the "modified sine wave" power that the UPS puts out while on battery.
see http://en.community.dell.com/forums/t/19262542.aspx
Answer: In one of my boxen, both my power supply and network card died while in overnight hibernation - why?
Spontaneous failure of both point to either static or lightning on both A/C power and the network lines, or outright failure of the Power Supply, which affected one of the always-on circuits of your computer. Have you noticed some of your Ethernet LED's blink even when the system is turned off?
And: What must I do to appease the electricity Gods so that I don't lose more hardware?

You need essential systems on UPS.
You need everything else on a good,
power filtering, lightning arresting
surge suppressors, such as the Tripp
Lite Isobar or the Brick Wall.
You need to eliminate any 2-to-3
prong 110V adapters.
If your network switch or router has
a metal grounding tab, use it.
Connect it by wire to the center screw of a 3
prong outlet plate.
You need Power Supplies with OCP,
Over Current Protection. They shut
down instead of die when shorted.
(Not all cheap power supplies marked
as OCP actually have OCP. I have
proof).

In my home I've got... five computers in various states of use (monthly through to continuous), and I've lost power supplies for all of them, including the laptop, generally in lumps (several components around the same time). These losses have also included other bits and bobs, including a hard drive.
I can relate. At work I have seen countless power incidents, due to our proximity to a rather large and careless manufacturer with big power requirements, and a fragile local grid. We have regular brownouts, interruptions, sags, harmonics, voltage fluctuations and power frequency variations. At one point outside we had a 660V line cross some of our 120V circuits, resulting in the rare but veritable Swell or Overvoltage (aka surge).
What you are suffering is probably a combination of poor component quality and bad power. Power conditioning can lower the failure rate of poor quality components.
Do I need some kind of power conditioner? Those power-boards with surge protection, that's just a marketing lie, right?
Some are a big marketing lie, some are not. There are a few nuts on the Net, worshippers of the Real Earth Ground, who insist nothing can work unless it is a whole-house to earth breaker. They are wrong. Of all the power issues I listed, a whole-house breaker can only protect against the overvoltage, but a good surge protector can protect against all but the sustained interruptions. A good UPS will protect against everything. When the 660V line cross our 120V circuits, everything powered-on not on a power strip died. Everything on even the cheapest power strip survived, except for the power strips. Quality power strips will protect against more subtle voltage shifts.
And a cheap UPS isn't going to filter the electricity any, is it? So what do I do, spend up
big?
A good modern UPS has both boost and buck capability, meaning, instead of switching to battery during minor power issues, it will just fix the issue. You may have to pay a little more to get this capability, but (for example) all our recent 1500VA UPS systems have it. Once you get to a certain size of UPS (600-700VA) you are more likely to get it included be default.
When choosing a UPS, don't equate VA with Watts. A 350VA UPS cannot support 350W of power draw.
Answer: Power Conditioning with an ISOLATION TRANSFORMER is the only sure way to protect hardware from AC line noise, spikes, surges, transients, etc.
If you have an APC UPS for battery back-up, you don't have adequate power conditioning. You should add a transformer-based power conditioner to the APC UPS for complete protection.
The best ones out there are ONEAC/POWERVAR, which we used to eliminate soft failures (error messages, lock-ups, etc) and hard failures (board and power supply failures). Yes, more expensive, but compared to cost of downtime to our business, they pay for themselves within months!
Here's a link to some of their products:  http://www.gryphon-inc.net/#!powervar-power-conditioners/pj5r3


If I want an interpretable model, are there methods other than Linear Regression?

Question: I encountered some statisticians that never use models other than Linear Regression for prediction because they believe that "ML models" such as random forest or gradient boosting are hard to explain or "not interpretable".
In a Linear Regression, given that the set of assumptions is verified (normality of errors, homoskedasticity, no multi-collinearity), the t-tests provide a way to test the significance of variables, tests that to my knowledge are not available in the random forests or gradient boosting models.
Therefore, my question is if I want to model a dependent variable with a set of independent variables, for the sake of interpretability should I always use Linear Regression?
Comment: Depends on what you still consider linear. Generalized linear models and generalized additive models still work on the basis of a linear component being estimated, but can model a wide variety of relationships.
Comment: I don't quite see what inferential statistics and t tests have to do with interpretability, which IMO mainly is about coefficient estimates.
Comment: @StephanKolassa "Interretability" can also pertain to *function form*. For example, the coefficient estimates produced by algorithmic fractional polynomial curve fitting in regression models (whether linear regresion, GLM, or something else), while obtaining nice *fit*, are almost certainly anti-intuitive: can you call to mind the array of shapes produced by models of the form $y_{i}=\beta_{0} + \beta_{1}x_{i}^{-3/5} + \beta_{2}x_{i}^{1/3} + \beta_{3}x_{i}^{3} + \varepsilon_{i}$, and therefore *interpret* the relationship between $y$ and $x$ implied by your coefficient estimates?
Comment: Also depends what you mean by interpretable. Various ways of 'peering into the black box' have been proposed for machine learning models, but may or may not be appropriate for your goals.
Comment: @UserX What you describe is still linear regression (i.e. is linear in the parameters). Contrast $y_{i} = \beta_{0} + \beta_{1}x_{i} + \beta_{2}x_{i}^{2} + \varepsilon_{i}$ with $y_{i} = \beta_{0} + \beta_{1}x_{i} + x_{i}^{\beta_{2}} +\varepsilon_{i}$: the former is a linear regression model, while the latter cannot be estimated using linear regression.
Comment: Generalized linear regression, multilevel regression, nonparametric regression, nonlinear regression, regression build on specific links (e.g., Poisson, negative binomial, probit, logit, etc.) including those with special "tweaks" (zero-inflated count models), double hurdle/two-stage regression, multivariate regression, quantile regression... and of course the *combinations* of these kinds of regression models. To name a few.
Comment: There's also polynomial regression, e.g. a regression equation with squared or cubed terms. Linear regression fails when there's a curve in the data.
Answer: It is hard for me to believe that you heard people saying this, because it would be a dumb thing to say. It's like saying that you use only the hammer (including drilling holes and for changing the lightbulbs), because it's straightforward to use and gives predictable results.
Second, linear regression is not always "interpretable". If you have linear regression model with many polynomial terms, or just a lot of features, it would be hard to interpret. For example, say that you used the raw values of each of the 784 pixels from MNIST† as features. Would knowing that pixel 237 has weight equal to -2311.67 tell you anything about the model? For image data, looking at activation maps of the convolutional neural network would be much easier to understand.
Finally, there are models that are equally interpretable, e.g. logistic regression, decision trees, naive Bayes algorithm, and many more.
† - As noticed by @Ingolifs in the comment, and as discussed in this thread, MNIST may be not the best example, since this is a very simple dataset. For most of the realistic image datasets, logistic regression would not work and looking at the weights would not give any straightforward answers. However, if you look closer at the weights in the linked thread, then their interpretation is also not straightforward, for example weights for predicting "5" or "9" do not show any obvious pattern (see image below, copied from the other thread).
Comment: [This answer](https://stats.stackexchange.com/questions/426873/how-does-a-simple-logistic-regression-model-achieve-a-92-classification-accurac) I think does a good job showing how clearly logistic regression on MNIST can be explained.
Comment: @Ingolifs agree, but this is an activation map, you could do the same for neural network.
Comment: @Ingolifs MNIST is maybe not the best example because it's very simple, but the point is that you'd use same method for neural network.
Comment: Regardless of what it's called, it gives a clear explanation of what the logistic regression is using to make its decisions in a way you don't really get for activation maps of neural networks.
Answer: Decision Tree would be another choice. Or Lasso Regression to create a sparse system.
Check this figure from An Introduction to Statistical Learning book.

http://www.sr-sv.com/wp-content/uploads/2015/09/STAT01.png
Comment: @donlan https://www.amazon.com/Introduction-Statistical-Learning-Applications-Statistics/dp/1461471370
thanks for suggestion answer revised.
Comment: What is the "ISL" book?
Answer: I would agrre with Tim's and mkt's answers - ML models are not necessarily uninterpretable. I would direct you to the Descriptive mAchine Learning EXplanations, DALEX R package, which is devoted to making ML models interpretable.
Comment: the DALEX Package is indeed very interesting, do you know if something similar exists for Python?
Comment: @Victor I don't know of a Python version of DALEX, but you could try calling R from Python using https://rpy2.readthedocs.io/en/version_2.8.x/introduction.html for example.
Answer: No, that is needlessly restrictive. There are a large range of interpretable models including not just (as Frans Rodenburg says) linear models, generalized linear models and generalized additive models, but also machine learning methods used for regression. I include random forests, gradient boosted machines, neural networks, and more. Just because you don't get coefficients out of machine learning models that are similar to those from linear regressions does not mean that their workings cannot be understood. It just takes a bit more work.
To understand why, I'd recommend reading this question: Obtaining knowledge from a random forest . What it shows is how you can approach making almost any machine learning model interpretable.


Which method of List should be used to assign two matching words to the value

Question: 1.//dart language in Flutter
2.//Which method of list should be used to assign two matching words to the value?
3.//The duplicate value should appear next to its matching value ?
//Question:
List colour=["peach","red","orange","yellow","white","pink","red","maroon"];
//Answer:
Print ["peach","red","red","orange","yellow","white","pink","maroon"]
Answer: There is no 'silver bullet' in List, that is able to solve the task, but it possess several useful methods for the case. There could be several ways to solve the problem. For instance, I'm proposing the remove/insert way:
<code>  List<String> colour = ["peach","red","orange","yellow","white","pink","red","maroon", "pink", "red"];
  for (int i = 0; i < colour.length; i++) {
    int indexOfPossibleDuplication = colour.lastIndexOf(colour[i]);
    if (indexOfPossibleDuplication > i) {
      colour.removeAt(indexOfPossibleDuplication);
      colour.insert(i, colour[i]);
    }
  }
  print(colour); //[peach, red, red, red, orange, yellow, white, pink, pink, maroon]
</code>
I deliberately inserted several duplicates to your input example in order to show that the code do the trick in cases, when there is more than one duplication took place.


How to practice the overblow

Question: I've managed to learn bending down somehow by trial & error but I yet have to hear my first overblow.
How can I do to get the feeling for overblowing, so that I have a good start for the consequent hours of practice? Do I have to blow really strong or is it just a matter of lip/tongue magic?
Answer: This lesson by Jason Ricci should help you. The trick about bending a drawn note and holding that tongue position when blowing afterwards seems to help get you there, I don't think you have to blow particularly strongly.
Answer: See the Diatonic Harmonica Reference article at http://www.angelfire.com/tx/myquill/Overblows.html.  The most important things to do are 1) Adjust the reed gaps, and 2) learn your blow bends very well, with good control.
Answer: One thing that can really help you out in the beginning is to remove the top cover plates and use your finger to block the blow reed in the hole you're trying to overblow.
(I know most of my tips can be found in the link by user9328, but I think it's in the wrong order, and that the finger trick deserves more attention.)
Overblows are produce by getting the air you blow to activate the draw reed instead of the blow reed, so forcibly blocking the blow reed gets you half the way there. Overblows should NOT require very much force, especially with this technique, so just experiment with shaping your mouth cavity in various ways, sort of resembling what you do while bending, until you get it. It can be helpful to try to, very carefully and slowly, shape your mouth as is you're saying oyoyo, eyeyey or echi-echi-echi; the overblows will hopefully pop out at the consonants if you get them right. (I should probably mention that I play using a pucker technique rather than a tongue-block one, and my advice assume you do the same. It's probably similar for tongue blockers, but you'd have to ask one to know.)
After learning this, try to get this happening in an uncovered hole. On most blues harps, hole 6 or maybe 5 or 4 should be the easiest. The variability comes from your average harp not being set up for overblows, as it's considered an advanced technique, and the receptiveness is more or less random. Go through your harps, trying holes 4-6 until you find one that's a little easier. Once your skill improves you'll find more and more holes will be overblowable!
To actually get the overblow without your finger, it can be helpful to see the overblow as a two step process: first you make the blow reed choke, then you make the draw reed sound. In other words, while playing a blow note, you could first try to shape your mouth so as to make the sound go away while keeping your blow pressure. THIS step could be helped by a sudden slight increase in your blow force, especially if your just beginning, but don't overdo it. When the blow note is silenced and the air chokes, you have a split second to try and redirect the air to the draw reed. Personally, I find that mentally picture the air I blow turning downwards inside the chamber, and trying to make it so with my mouth, makes it easier to get my mouth cavity the right shape, but that might be just me. EDIT: The actual direction of the air probably doesn't matter, I just find this a useful picture to shape my mouth.
A rule of thumb while going through your harps is that very cheap harps probably won't work as well as slightly fancier ones, but a respected brand name on the covers is no guarantee overblows will work well.
You could also try to adjust the reeds to make overblows easier, but if you have a few harps I would try and see if there's any hole that's working well first. That way, you'll know what you're looking for when making your adjustments. There are a bunch of videos, just search for reed gaping and you'll be fine.

How to practice the overblow


Comparar id em duas tabelas e retornar valor da promocão sql

Question: Olá!
Na minha tabela de produto e na tabela de promoção constam idcategoria, tenho meu produto com determinada categoria e quando encontrar o mesmo idcategoria na tabela de promoção e esta estiver com estado ativo, retornar o valor do desconto da promoção(tabela promoção). É possível fazer em uma consulta?
Comment: Pesquise por outer join https://pt.wikipedia.org/wiki/Join_(SQL)#Jun%C3%A7%C3%A3o_externa_(outer_join)
Comment: Isto responde à sua pergunta? [Qual é a diferença entre INNER JOIN e OUTER JOIN?](https://pt.stackoverflow.com/questions/6441/qual-%c3%a9-a-diferen%c3%a7a-entre-inner-join-e-outer-join)
Answer: Boa tarde,
ficaria algo mais ou menos assim:
<code>SELECT DESCONTO, IDPRODUTO FROM PRODUTOS P
INNER JOIN PROMOCAO PR ON PR.IDCATEGORIA = P.IDCATEGORIA
WHERE P.IDPRODUTO = X AND PR.ATIVO = 1;
</code>

PR.ATIVO = 1 NÃO SEI O QUE VC SALVA COMO TRUE OU FALSE MAS NORMALMENTE
É 0 FALSE E 1 ATIVO.
Comment: Perfeito, funcionou! Muito obrigada!


ZFS, dedupe and PST files

Question: I am interested to know what would be expected maximum dedupe ratio for a set of PST files.
I have ~40G of pst files from ~15 usres with high level of duplication of attachments. I am running tests to see if I can have significant space savings if I store the data on ZFS with dedupe.
For this purpose I have installed a test setup of Nexenta, but was wondering if someone here had already done this and what level of deduplication I might expect (or in another words how sensitive are pst files to block alignment and what are the parameters that can influence the ratio?).
Initial test show very low dedupe ratio and I did find explanation that block level dedupe would not be efficient here and that byte level dedupe would be much better (and that it should be performed by application that is aware of internal organization), so I am just double checking here if someone have some more input.
Otherwise I will probably be converting PST files to IMAP.
Answer: Yeah, PST files aren't likely to yield the dedup ratios you're looking for.  Attachments inside a PST aren't going to be block aligned and ripe for deduplication.  If you're looking to maximize dedupe possibilities with ZFS you're going to want a storage format where the attachments are distinct files.
Comment: +1, yes this is what I experienced with initial tests... wishful thinking strikes back
Comment: Have you considered dedupe + compression?

ZFS, dedupe and PST files


composition of finite rank projection and bounded operator

Question: If $P\in B(H)$ is a finite rank projection,we assume the rank is $n$,I know the fact $PB(H)P\cong M_n(\mathbb{C})$,but how to construct the isomorphism?
Comment: I think this is pretty much the same as the result that is usually taken for granted, that there is a 1:1 corresponsance between the set of linear transformation on a finite dimensional vector space and their matrix 'representations' (set of matrices of corresponding size).
Answer: Let $x_1,\ldots,x_n$ be an orthonormal basis of $PH$. Write $P=\sum_{j=1}^n P_{jj}$, where $P_j$ is the orthogonal projection onto $\mathbb C x_j$, i.e., $P_{jj}x=\langle x,x_j\rangle\,x_j$. Let $P_{kj}$ be the rank-one operator that takes $x_j$ to $x_k$, i.e. $P_{kj}x=\langle x,x_j\rangle\,x_k$.
Given any $T\in B(H)$, the operator $P_kTP_j$ is rank-one, and maps $x_j$ to $x_k$. We have  $$
P_kTP_jx=\langle TP_jx,x_k\rangle\,x_k=\langle Tx_j,x_k\rangle \,\langle x,x_j\rangle\,x_k=\langle Tx_j,x_k\rangle\,P_{kj}x.
$$
So
$$\tag1
PTP=\sum_{k,j}P_kTP_j=\sum_{k,j}\langle Tx_j,x_k\rangle\,P_{kj}.
$$
We also have
$$\tag2
P_{kj}P_{ab}x=\langle x,x_b\rangle P_{kj}x_a=\langle x,x_b\rangle\,\langle x_a,x_j\rangle\,x_k=\delta_{a,j}\,\langle x,x_b\rangle\, x_k=\delta_{a,j}\,P_{kb}x.
$$
Given $A\in M_n(\mathbb C)$, we write $A=\sum_{k,j} A_{kj}\,E_{kj}$, where $\{E_{kj}\}$ are the canonical matrix units. Define $\Gamma:M_n(\mathbb C)\to PB(H)P$ by
$$
\Gamma(A)=\sum_{k,j} A_{kj}\,P_{kj}.
$$
It is easy to see that this is one-to-one, $*$-preserving, and linear. It is onto by $(1)$. And, using $(2)$,
\begin{align}
\Gamma(AB)&=\sum_{k,j} (AB)_{kj}\,P_{kj}=\sum_{k,j}\sum_{\ell} A_{k\ell}B_{\ell j}\,P_{kj}=\sum_{k,j}\sum_{\ell,m} A_{k\ell}B_{m j}\,P_{k\ell}P_{m j}\\ \ \\
&=\left(\sum_{k,\ell} A_{k\ell} \,P_{k\ell}\right)
\left(\sum_{j,m} B_{mj} \,P_{mj}\right)
=\Gamma(A)\Gamma(B).
\end{align}


how to start the neovim gio from the cli

Question: I'm trying to switch from vim/gvim to neovim on Linux. Up to now my standard workflow started with opening the cli, navigate to my project directory, and run gvim <filename> with the file I intend to start working with.
With neovim I can start it from the KDE menu to get a nice GUI. according to the menu settings, it simply runs nvim with an optional filename parameter. But I don't find the way to run nvim from the cli in a way, that it starts the GUI. Running nvim <filename> simply starts the cli UI.
Google gave me a lot of interesting information, but not, what I'm looking for.
Answer: There are different GUIs for neovim. Check which one do you actually use and start it from the command line. Navigate to the KDE menu for neovim GUI, right-click on it and select Edit application... Go to the Application tab and check the Command edit box. There you'll see the actual command which is run by KDE when you select the corresponding menu item. You can create your own shell script or alias which will run this command and use it on the command line.
UPDATE
Maybe some parameter or environment variable is passed to nvim so it changes its behavior. You can try to see what system call KDE actually performs to start the editor. For example, I'm using KDE plasma, so pidof plasmashell gives me the pid which I need. Then:
strace -f -v -e trace=execve -p `pidof plasmashell` &> plasma.trace

After that go to KDE menu and start neovim. Terminate the strace command with Ctrl-C and check the plasma.trace file for the execve system calls made to start the neovim process.
Comment: Thank you for your help. The menu entry says, it runs nvim. I also have nvim-gtk and nvim-qt installed, but none of them are the one, that it starts. Actually both of them are suboptimal in different ways.
Comment: Maybe you can try to check some hidden parameters by checking the actual system calls made to start the nvim, as I explain in the update to the answer.
Comment: Thank you very much again. Turns out, the menu entry starts konsole with nvim inside. In the meantime I've tried with nvim-qt, but I didn't even manage to persuade it to show the menu as a Qt menu. The nvim-gtk seems to put more emphasis on nice look, than on usability and integration with freedesktop standards. Therefore for me there are two ways forward: if there's a good tutorial how to write a nvim UI, I could write my own. If not, I better stick with vim and wait, till a usefull UI is available.


Trouble rewriting expression

Question: I have trouble rewriting an algebraic expression again. I have to go from:
$$\frac{1}{\frac{\sqrt{1-x}}{\sqrt{1+x}}*(1+x)^2}$$
to
$$\frac{1}{(1+x)\sqrt{1-x^2}}$$
I'm not seeing it, what am I missing? Thanks in advance.
Comment: Is the $*$ a multiplication?
Comment: You are missing a factor of $2$ in the last expression
Comment: @NazimJ Yes the * is a multiplication.
Comment: @Andrei Sorry, you're right. I corrected it.
Answer: The first step you are looking for is this one
$\frac{1}{2\frac{\sqrt{1-x}}{\sqrt{1+x}}*(1+x)^2} = \frac{1}{2\frac{\sqrt{1-x}*\sqrt{1+x}}{\sqrt{1+x}*\sqrt{1+x}}*(1+x)^2}$
Comment: Alternative way of solving it compared to the other two answers. It's clear, thank you!
Answer: \begin{align*}
\frac{1}{\frac{\sqrt{1-x}}{\sqrt{1+x}}(1+x)^2}
&= \frac{1}{\frac{\sqrt{1+x}}{\sqrt{1-x}}\frac{{1-x}}{{1+x}}(1+x)^2} \\
&= \frac{1}{\frac{\sqrt{1+x}}{\sqrt{1-x}}(1-x)(1+x)} \\
&= \frac{1}{\sqrt{1+x}\sqrt{1-x}(1+x)} \\
&= \frac{1}{(1+x)\sqrt{1-x^2}} \\
\end{align*}
Comment: Thanks a lot, similar approach to the one used above by Andrei. Thank you!
Answer: $$\begin{align}\frac{1}{\frac{\sqrt{1-x}}{\sqrt{1+x}}(1+x)^2}&=\frac{1}{\frac{\sqrt{1-x}}{\sqrt{1+x}}(1+x)(1+x)}\\&=\frac{1}{\frac{\sqrt{1-x}}{\sqrt{1+x}}\sqrt{1+x}\sqrt{1+x}(1+x)}\\&=\frac{1}{\sqrt{1-x}\sqrt{1+x}(1+x)}\\&=\frac{1}{\sqrt{1-x^2}(1+x)}\end{align}$$
Comment: Ah I get it now, expanding the (1+x)^2 into factors (one containing two roots) did the trick. Not a trick I'm used to using, but will keep it in the back of my mind. Thanks a bunch!

Trouble rewriting expression


Family bounded in $\mathcal{L}^1$ has limit a.e.

Question: Let $(X, \mathcal{F} , \mu )$ be a measure space.
Suppose $\lbrace X_n \rbrace$ is a family of functions in $\mathcal{L}^1$, bounded in $\mathcal{L}^1$ i.e. there exist $K \geq 0 $ such that $$||X_n||_1 \leq K  \ \ \forall n $$Is it true that $$\lim_{n \to \infty} X_n$$ exists a.e. ? Why ?
Comment: The answer is no. (Keyword: Oscillation)
Answer: No. Take in $\mathcal L^1[0,1]$:
$$
X_{2n}(x)=1\quad\text{nad}\quad X_{2n-1}(x)=0.
$$
Worse example, in $\mathcal L^1[0,1]$,
where not even a subsequence converges pointwise is
$$
X_n(x)=\sin nx, \quad n\in\mathbb N.
$$
Answer: No. Consider this sequence.  Let $f_1$ be the indicator function on $[0,1/2]$, then $f_2$ be the indicator function on $[1/2,1]$. Now go back to zero and go by quarters to get $f_3$ through $f_6$. Continue in this fashion with 1/8, 1/16, etc.
This sequence will converge to 0 in $\mathcal{L}^1$ but it will diverge by a.e. pointwise. This will occur at any number that is not a dyadic rational.


Some confusion on learning of Generative Adversarial Networks (GANs)

Question: I have some experience with machine learning, but no background in deep learning at all. The idea of a GAN looks so cool, and there are so many sources out there that talks about the idea, but there is no good source that I could find which can convey how to train GANs to a deep learning beginner.
Here are my detailed questions:

Why is there a need for the vector $z$? And why $p(z) = N(0,1)$ initially?
Is the latent vector $z$ learned in the training step of the generator network?
Do we ever learn the distributions $p(x)$ and $p(z)$? If so, when?
According to here, the discriminator network is trained with the real samples and the fake samples in separate steps. When there is only one class of samples (either real or fake), how come you can train a "discriminator" (there is nothing to discriminate)?
Answer: First off, if you are new to deep learning, a good idea is to start from scratch, like a "linear GAN", and deep learning is just replacing the linear models with neural networks. They do the same thing, just performing better on images/texts etc.
Suppose you have some 1D data $X = \{x_1, \dots, x_n\}$, and you want your generator function $G$ to produce some new data different from $X$ but look like $X$ (one purpose of GAN is to create labeled data because they are often expensive), so you cannot cheat by taking the average $\bar{x}$ as that's just one data. You will need some randomness, for example, $z \sim N(0,1)$ as the seed for your next generated data. Say you decide to use $G(z) = w_1z + b_1$ as your generator, and initialize your $W, b$ randomly.
Now your $G$ produces random data $x \sim N(b_1, w_1)$ different from $X$, but how to achieve the second goal (look like $X$)? The answer is to use a classifier. Say your classifier is logistic $D(x) = \sigma(w_2x + b_2)$, and you 1) sample some data from $X$; 2) generate some data from $G(z)$. You label them with $1$ for real data from $X$ and $0$ for fake data from $G(z)$, and train your logistic classifier as usual.
Your discriminator works nicely now, and then you want your generator to be good, too. So you generate some data from $G$, and for the data that successfully fooled $D$, you want $G$ to generate more, and less otherwise. You tune $w_1, b_1$ to achieve this.
Then you go back to train your discriminator again. The process will continue until the Nash equilibrium, where your generator works perfectly and your discriminator decides randomly.
Regarding your questions, IMPO:

1) Why is there a need for the vector z? And why p(z) = N(0,1) initially?

Goodfellow calls the distribution a "noise prior" in the original paper, which explains a lot. Think of $z$ as the random number seed. Since we want to generate fake data, we must give the generator some seed to start with. The choice of $N(0,1)$ is for convenience, I think.

2) Is the latent vector z learned in the training step of the generator network?

No, we don't want to learn the seed. We want to learn the function that processes the seed, i.e. the parameters that define the generator network.

3) Do we ever learn the distributions p(x) and p(z)? If so, when?

In the end we want that given $z \sim p(z)$, we have $G(z) \sim p(x)$. So in some sense, we do want the generator to learn $p(x)$ through training. but there is no point to learn $p(z)$.

4) According to here, the discriminator network is trained with the real samples and the fake samples in separate steps. When there is only one class of samples (either real or fake), how come you can train a "discriminator" (there is nothing to discriminate)?

The link to "here" seems to be dead, but at least according to Goodfellow's original paper, you do sample two classes of examples during discriminator training (using the cross-entropy loss). As the comment points out, SGD confuses people a bit by only taking some data in each loop, but the stochastic gradient does have the same gradient in expectation as the regular GD. The discussion is beyond the range of this question, though.
Comment: To clarify 4 a bit: in practice, you likely update the discriminator with a batch of all real samples and then with a batch of all generated samples for convenience. It's just an SGD step, and it still "remembers" the previous updates, so this should be basically the same as mixing the two batches together and then taking a training step on the mixed batch.
Comment: I don't fully understand the training process in the link you provided. Maybe take a look at Goodfellow's actual code if you are not confident: https://github.com/goodfeli/adversarial
Comment: @Jiāgěng You said "z is sampled from our seed generator p(z)". Is not p(z) the standard Gaussian? Is it standard Gaussian only in the beginning and changing over time after the generator has a good sense of the data?
Comment: @user5054 I have clarified my answer a bit. $p(z)$ is the standard Gaussian and does not change. The only thing $p(z)$ does in the model is to provide some randomness to our generated data. The job of "having a good sense of the data" goes to the generator network, not the seed it is fed with.
Comment: @Jiāgěng Thanks! 2 more questions and I really appreciate your response. 1) So, we do not learn a latent structure for the data at all. I at first was thinking that we learn the latent vector $z$, which would be a low-dimensional representation of the data. Are you aware of a GAN extension which can do that? 2) Do you think 600 samples is too few to train a GAN in a setting where I want to generate fake samples from $p(x)$ which is 42000-dimensional? This is a genomic dataset but I think the setting resembles generating a fake image where there are 600 training images each with 42000 pixels.
Comment: @user5054 1) AFAIK no. A lot of work is dedicated to better train the generator, e.g. Wasserstein GAN, but they are all concerned about the network structure and loss function, not the shape of the latent space, but it does sound like a good idea. Please share if you find any! 2) That's indeed too low. I'm not familiar with the training, but maybe take a look at the experiments in DCGAN.


Exception "Component is not available" when iterating over window object's properties

Question: I'm trying to convert a Google Chrome extension to Firefox using Addon SDK (Jetpack). The following code (run as content-script)
var property, winProperties = {};
for (property in window) {
    winProperties[property] = true;
}

throws this exception when run in Firefox 5.0 and 6.0:
Traceback (most recent call last):
File "sfc-bgcore.js", line 299, in null
File "resource://jid1-q4cqhvcl3sc4vq-at-jetpack-api-utils-lib/content/content-proxy.js", line 519, in null
for each (name in Object.keys(obj)) {
[Exception... "Component is not available"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame ::
   resource://jid1-q4cqhvcl3sc4vq-at-jetpack-api-utils-lib/securable-module.js ->
   resource://jid1-q4cqhvcl3sc4vq-at-jetpack-api-utils-lib/content/content-proxy.js ::
   <TOP_LEVEL> ::
   line 519"  data: no]

Does anyone know how to catch this exception or how to avoid the "problematic" property and continue the loop?
Note that I can't just put a try-catch statement in the loop's body, since even this triggers the error:
for (var property in window) {};

However if I execute the same or a similar statement in Firefox's "Web Console" then it runs fine:
for (var property in window) { console.log(property); };

Answer: I couldn't reproduce this with a testcase extension by installing it via the Test button and then visiting http://example.org/ - there were some properties printed to the console, followed by the message "done", with no errors.
The testcase code:
exports.main = function(options, callbacks) {
    var pageMod = require("page-mod");
    pageMod.PageMod({
      include: "*.org",
      contentScript: 'for (property in window) {console.log(property)}; console.log("done");'
    });
};


Why are square brackets needed in SPARC assembly ld/st instructions?

Question: On the 32-bit SPARC architecture, both the load and store instructions (ld, ldub, ldsb, lduh, st, stb, etc.) all require square brackets around the memory address. For example,
st %l0, [%fp - 4]
ld [%i0], %l0

Why is this? Since the load and store instructions are the only ones that can access memory, why are the square brackets needed?
Is this just for readability or does another usage for load and store operations exist which do not use square brackets?
Answer: This is a common convention across many (if not most) assembly languages: when something is being dereferenced as a memory address, it is enclosed in brackets.
Even though SPARC doesn't allow alternative usages of ld, st, etc, the convention is still adhered to in order to avoid any ambiguity.


Is indicator function integrable?

Question:
f is discontinuous on [0,1] so it's not integrable? but I think the answer is yes, it is integrable. But i dont know how to prove that.
any hint would be great. thanks
Comment: Here http://math.stackexchange.com/a/252474/27978 is an example of a function that is discontinuous on an uncountable set of points but is Riemann Integrable.
Comment: @Dafty: Note that, your question has two parts.
Comment: @copper.hat Thanks a lot !!! Copper.hat!!
Answer: Notice that for any partition $\pi$, we have $L(f,\pi) = 0$, so we know what the result will be.
To directly show that $f$ is Riemann integrable, let $\epsilon>0$. We need to construct a partition. Let $0, \frac{1}{2} \epsilon$ be the first two points in the partition. Since $f \le 1$, we see that $\sup_{x \in [0, \frac{1}{2} \epsilon]} f(x) l([0, \frac{1}{2} \epsilon]) \le \frac{1}{2} \epsilon$.
Note that $E \cap (\frac{1}{2} \epsilon, 1]$ is finite, and let $p_1< p_2 < \cdots < p_n$ be the points. Choose the points $o_k,q_k$ so that
$o_1 < p_1 < q_1 < o_2 < p_2 < q_2 < \cdots < o_n <  p_n < q_n$ such that
$q_k-o_k < \frac{1}{2n} \epsilon$, and note that $f(x) = 0$ for $ x \in (\frac{1}{2} \epsilon, 1] \cap ( \cup_k [o_k, q_k] )^c$.
Then with the partition $\pi=(0,\frac{1}{2} \epsilon, o_1 , p_1 , q_1 , o_2 , p_2 , q_2 , \cdots , o_n ,  p_n , q_n, 1)$, we see that
$U(f,\pi) \le  \frac{1}{2} \epsilon + n \frac{1}{2n} \epsilon = \epsilon$.
Hence $\inf_\pi U(f,\pi) = 0$. It follows that $\int_0^1 f(x) dx = 0$.
Answer: I assume you are talking about Riemann Integrability. The following result is useful to check the Riemann integrability of your function

A function $g(x)$ is Riemann integrable on $[a,b]$ iff
i) $g$ is bounded
ii) $g$ has a countable number of discontinuities (or it is discontinuous on a set of measure zero).
Comment: This is not correct. (ii) should be that the set of continuities has measure zero.
Comment: @MhenniBenghorbal Thanks a lot for the tips!
Comment: @copper.hat thank you. how do i compute int f(x)dx?
Comment: I will add an answer to that effect.
Comment: @copper.hat: Are you sure?
Comment: @MhenniBenghorbal: Yes, it is one of the results relating Riemann and Lebesgue integration. I added a reference to an example in the comments on the question (indicator function of the Cantor set).
Comment: @Dafty: You are very welcome.
Comment: @MhenniBenghorbal: My comment should be that the set of DIScontinuities has measure zero. Sorry about that.
Comment: @copper.hat: No problem. It happens with everyone of us.

Is indicator function integrable?


Order of antiderivatives of Schwartz functions

Question: For a Schwartz function $f\in\mathcal S(\mathbb R)$ it is known that
$$\exists F\in\mathcal S(\mathbb R): F'=f \iff \int\limits_{-\infty}^{+\infty}f(x) dx = 0 $$
in this case $F(x) = \int_{x}^{+\infty}f(t)dt$, see related question here.
Question: Does there exist $f\in\mathcal S(\mathbb R)$ with $f^{(-k)}\in\mathcal S(\mathbb R)$ for all $k\ge 0$ (my guess would be no)
I.e. for a given $f$ we can test if it has an antiderivate $F$ in the Schwartz space by simply checking if its mean is $0$. Then we can do the same with $F$. Does this process always stop at some point?
My work: It seems that all functions of the type $f(x) = p(x)e^{-\alpha x^2}$ with $p$ polynomial only have antiderivatives of finite order in $\mathcal S(\mathbb R)$. (I think I can prove this). As one can construct an orthonormal basis of $\mathcal S(\mathbb R)$ with such functions, e.g. the Hermite functions, I would guess that there is no function with antiderivates of arbitrary order in $\mathcal S(\mathbb R)$.
Remark: If there is such an $f$, then $(x^k \star f) = 0$ for all $k\ge 0$; then via Fourier transform, this would imply that in the sense of distributions:
$$0 = \mathcal F[x^k\star f] = \mathcal F [x^k] \mathcal F[f] = \Big(\frac{i}{2\pi}\Big)^k\delta^{(k)}(w)\hat f(w)$$
Answer: You have pretty much answered your own question already: looking at the Fourier transforms, we want a $g\in\mathcal S$ such that $g(\xi)\xi^{-k}\in\mathcal S$ also for all $k\ge 1$. This is easy: our only potential problem occurs at $\xi =0$, so it suffices to take a $g\in\mathcal S$ with $0\notin\textrm{supp}(g)$.
Comment: So the idea is to use the time integration formula $$ \mathcal F \Big[\int_{-\infty}^t f(x)dx \Big](w) = \frac{\hat f(w)}{w} + \hat f(0) \delta(w)$$ (with some additional constant factors depending on the normalization of $\mathcal F$) with  $\hat f = g$ as you described above. I checked and this seems to work nicely! (I wasn't really aware of this formula) The only thing we need of course is not simply $0\notin\text{supp}(g)$, but rather $g^{(k)}(0) = 0 \implies \lim_{x\to 0} \frac{g(x)}{x^k} = 0$ for all $k\ge 0$
Comment: So one concrete example is given by $$f = \mathcal F[e^{-(\frac{1}{x^2} + x^2)}]$$ which looks similar to a $\text{sinc}$ function. Is it then correct to say that the qualitative difference between $f$ and functions of the type $p(x)e^{-x^2}$ is that the latter only features a finite amount of oscillations ($\sim$ number of isolated zeroes), and the number of oscillations decreases under integration. Thus a finite order antiderivative of it is either positive or negative for all $x$. This doesn't happen necessarily with $f$ since you have an infinite amount of oscillations to begin with.
Comment: @Hyperplane: The support is defined as the *closure* of the set of points where $g\not=0$, so $0\notin\textrm{supp}(g)$ means that $g=0$ in a neighborhood of zero. But your example (a $g$ that vanishes at zero fast enough) works fine too.


Drupal 7 GetLocations field geocoding off?

Question: I am using this: https://www.drupal.org/project/getlocations
The problem is, when I add a geolocations field to a content type, and type in, for example:
Boulders Beach, Kleintuin Road, Cape Town, Western Cape

If I see maps.google.co.za, I get:
-34.197116,18.451423

But the geolocations field gives me:
-34.1964859,18.45004849999998

In this specific case the difference isn't that big, but I've had a few cases where it's completely wrong. For example:
Spier Wine Farm, Stellenbosch

Correct google result:
-33.973474,18.782544

what I get on the geolocations field:
-33.9805299, 18.773583700000017

It looks like they are off by 0.007, 0.009.
Any ideas why this could be happening?
Answer: The API geocoder may be different from the Maps geocoder (see the FAQ in the API documentation). The results may even vary for users from different users from different countries. For me, Spier Wine Farm, Stellenbosch results on Google Maps in -33.9733628,18.7825561.
In general, it seems that sometimes providing less information in an address results in more exact coordinates, see this similar question on s.o.
UPDATE: Interesting fact: the same address produces even different coordinates for different browsers. Coordinates stated above came from Google Chrome. When doing the same in Mozilla Firefox, I get -33.973474,18.782544 (which is what you had in your question).


How to profile for HDD usage pattern?

Question: I'm considering upgrading the storage system for some of my servers, and all the guides and manuals advise to consider the storage usage patterns of your app before deciding on a (RAID? SSD? iSCSI? NAS?) solution.
Is there a tool I can use which can tell me:

if my servers are doing mostly sequential or random IO,

if I'm doing more reads or more writes,
the average read and write size,
and whatever other info I can use to make a decision?

I know about iostat, and it seems I can use it to answer question 2. But I think I need other tools to answer the other questions.
It seems that people usually like to make educated guesses in these matters based on the running software, but I would much rather measure than reason.
The OS is ubuntu 8.04, but I'm willing to change the OS if something else has better measuring tools.
Comment: This is kind of a dupe - http://serverfault.com/questions/88954
Answer: collectl can answer your questions 1, 2, and 3.
Also you might check out seekwatcher.
Answer: You might also check out munin and specifically the diskstat plugin which will give you nice fun graphs of:

iostat outputs
disk throughput (read, write)
disk IO totals (read, write, avg req size, avg read req size, avg write req size)
disk IO times (read, write, avg req time, avg read req time, avg write req time)
disk utilization (%)

Example:
http://mirror.inode.at/munin/inode.at/mirror.inode.at.html#Disk
Perhaps one of the advantages of using something more broad in scope like munin is that you will have the ability to correlate data between different subsystems more easily than you would just looking solely at IO data.
Current distribution versions of munin(as of this writing, at least) do not have this plugin by default, so you'll have to grab it and install it manually. Here's another link worth reading about the plugin:
http://blogs.amd.co.at/robe/2008/12/graphing-linux-disk-io-statistics-with-munin.html
And the plugin itself: https://workbench.amd.co.at/trac/munin-plugins/
HTH.
Answer: Solaris/Opensolaris with DTrace will give you any information you'll ever need about this. In my opinion, DTrace gives you the measuring tools available anywhere, so if switching OS is an option, I'd give this some serious consideration.

How to profile for HDD usage pattern?


What is the criteria for selecting the range in normalization?

Question: Generally the range is 0 to 1. But I have read papers where different ranges are used Say 1 to 7.
I want to know the logic behind this.
Comment: Every problem has its own logic in normalisation although there are typical ones. Maybe you can share the paper that uses the range 1-7 and we can have an understanding why they choose to do so.
Answer: If by "normalization" you mean "scaling" than the idea behind this procedure is to ensure that all your variables lie in the same range and have the same importance for the model.
For example, if you measure your distance in feet and the velocity in m/h - the influence that distance will have would be roughly 0.3 of the influence that the velocity will have.
The common practice for scaling is to make all the features lie in range of [0, 1], but it doesn't really matter in terms of performance, (i.e. you could make all your variables range from 100 to 200 and the performance would be the same), it's only important to scale all of your variables (by all I mean numeric variables off course).
Hope that helps.
Cheers.
Answer: If your output activation function has a range of [0,1], then obviously you must ensure that the target values lie within that range. But it is generally better to choose an output activation function suited to the distribution of the targets than to force your data to conform to the output activation function.
Comment: lets assume you scaled target variable in between 0 and 5 and you are using  activation funtion sigmoid .In each iteration of the neural network ,it is comparing the predicted value having  range [0,1] with actual value between [0,5].Did u think it is  fair.
Comment: I see your point of confusion there. The thing is that scaling is applied on the features, not on the target variable, which in case on regression will have a real measured value, and in case of classification will be a 1-hot-vector (1 for the class index, 0 for the rest). In your example, if you can use a target in range of [0, 5] (i.e. in case of 5 classes, or for regression for predicting a real  value in range [0, 5]), but your activation will not be a function that outputs values in [0, 1], but it has nothing to do with scaling - it's just how the learning process  works.
Comment: There is absolutely no connection between the activation function and the range of the variable. Your variables can, and usually will be much larger than 1, and in case of Neural Networks where you apply the activation to the weighted sum of the inputs (i.e. the variables) it most probably will be several magnitudes larger than 1. In the end, what "squashes" those values to the [0,1] interval is the activation itself, be it sigmoid, ReLu or other activation function.


How to keep practicing to compose music when you're too picky to listen to yourself playing

Question: I'm a pianist, and I also compose songs in DAWs. My main spare time occupation is to improvise on the piano, and I've been doing it for several years now.
Even before I learned any instruments (when I was a kid) I always analyzed music in my head, trying to predict how the rhythms, melodies and chords would play out before they actually did. This made practicing a lot harder, since I already had a good feel of what I enjoyed to listen to.
I've always played mainly by ear and several years ago I started teaching myself how to improvise; just trying to play what I could hear in my head. My technique isn't close to be able to keep up with the symphonies in my head, but I think I'm doing alright now - and my neighbors often say they enjoy when I play (I live in a small apartment with very thin walls).
The last year, however, I've started to become frustrated after playing a few minutes of music that isn't good enough to satisfy me. So I just stop and start listening to music I enjoy instead. It's becoming a bad habit, and it's a shame since I still have great ambitions for composing.
This summer I was on a songwriter course, just for the heck of it. One thing I was advised there was to learn to let go of the inner critic, and just try to compose a simple song that is good enough to make you satisfied. I thought it was good advice but I didn't succeed at it in the week I was there.
I'm still trying to apply the advice today but when I compose something, and suddenly hit something I enjoy I get excited and feel like I'm finally about to compose a song that I'll be satisfied with. Shortly afterwards it either starts getting too predictable or too special, and then I suddenly become impatient, longing to be back into the vibe I just experienced. After a few minutes of trying to get back on track, or just starting over with something new, I usually give up, or at least get the feeling of sadness and discouragement.

Is there some general advice to composers who are discouraged by their lack of practical musician skills?
I mean, 'keep practicing' is the obvious answer here, but what about on the mental part and practices that pays off better to more rapid improvements?
Comment: @Luke - creativity does have a psychological component, IMHO, but OP will likely get better musically practical advice in this forum than in another one.
Comment: This is more of a psychological question than a music question.
Comment: Could also be worth looking at productivity SE as elements of this question are on topic there.
Answer: I've had the same problem, but I managed to get mostly rid of it.
My first step was to be able to accept my style, when you're playing you have to know that you're not going to play the music you listen to, and if you're not used to the idea it can lead you to think it's bad just because it doesn't sound like what you enjoy listening.
My second step was to record myself and take the habit to do an analysis of what I played, not to see if I played well but mostly to improve the songwriting, and how I can have made a part better just by changing the way it's played.
The third step was to accept the mistakes I can do while playing, and not to make a big deal out of it, to play well you have to play relaxed.
Playing with other people also can be inspiring, and can help you to like your own style when hearing it as a part of a whole.
The lack of skill is not the problem, what you should first improve is your feeling, when you get to like at least objectively what you do, you'll be able to find more pleasure in improvising and then improve your skills.
Answer: I admire your devotion to working at your improvisational skills but think that your playing skills may not be your primary problem.
Those of us who write (authors, not composers), can run into the same problem where if our first draft is not great, we abandon the story or idea.
The best advice I have been given is to just get something written.  It's far better to let the idea live long enough to survive an attempt to edit it or even let you walk away from it for a day before killing it.
Though easier said than done, patience and dilligence can vastly enhance your already inate talent for imagining the music in your head.
Best of luck with your composing!
Comment: Sometimes I'll walk away for a week or more… it helps me be more fairly critical, without having any attachment to the work. Usually, I end up liking it more than I did while I was creating it!
Comment: @Josh- I agree that time and distance can be important tools to let ideas ripen.
Answer: Practicing
Practicing is not listening to music. Yes, you must listen while you practice, but you do so expressly in order to detect mistakes and inconsistencies so that you can correct them. You cannot expect to be able to play for the pleasure of listening without first learning how to play!
Method
Improvisation is always good, especially if you are playing what you hear in your head (as opposed to playing, and then hearing what you played). If you have an imbalance of head-creativity to physical technique, then you should really work on reigning in your improvisational head-creativity to the place where it is within your zone of proximal development for your physical technique. Once you know where that zone is, you can make a plan for expanding your physical technique to the point where it is more in-sync with your head-creativity. This is where real practice comes into play--my internal monologue might sound like:

Okay, I hear a riff in my head that I can't play immediately, but I can transcribe it and play it after a few minutes of practice. Now, let's turn it into an idee fixe, playing it over and over again in different rhythms, then do the same in all 12 keys, then play it in a few different modes, then invert it, then reorder the pitches...

There are a lot of possibilities there. You don't have to do them all, but those that appear to you as useful and relevant to your head-music can get you hours of practice that will develop technique that you didn't have before.
Efficiency of practice
Understand that your musical brain is made up of all of the music you have ever heard before being remixed and influenced by other non-musical stimuli. This means that the music you come up with in your head has roots in and shared technique with existing pieces of literature.
This is where notation comes in handy (and I see you mentioned you play mostly by ear, but bear with me)--you can use those existing pieces of music to help develop the technique that you require in order to play the music your own head comes up with. Identify what literature influences your creative mind, and then learn how to play it! The alternative to learning from existing sheet music is to learn after transcribing everything--either by actually writing down the music before playing it or by playing it by ear. Transcribing is an incredibly valuable skill, but when you do it you are spending time exercising your ear to figure out the piece that you could be devoting towards developing the technique to play the piece. If you want to practice more efficiently, you need to figure out the proper balance for what you want to achieve.
It is for this reason that learning to read music is a required skill for virtuoso-level playing in the western classical tradition. Exceptions can be made for certain traditions passed down aurally; you will find some great jazz and folk musicians with virtuoso-level talent, but those traditions are not reliant upon sheet music in the first place, AND in almost all cases these are people whose creative minds have grown up in sync with their technique. For us, we need to be a bit more strategic.
Composing
Composing music is GREAT, but it can be a daunting task. There is some wisdom to just putting in the hours--even if you spend an hour a day writing motives on scraps of paper that you end up throwing away or never use, that's still something. Writing lots of little pieces is going to benefit you far more than spending the same amount of time on one large piece. Particularly, if you are having trouble just getting something DONE, you need to make sure you set your compositional goals as achievable as possible, and give yourself STRICT GUIDELINES and limits to your compositional process.
One of my teachers once told me that creativity does not come from complete freedom, it comes from limits. It took me a LONG time to realize she was right, but the point is IF you give yourself some artificial rules to follow, for example:

Compose eight bars of music in 4/4 time using only the notes in D major and related secondary dominants.
Write a 16-bar two-part invention in the style of Bach.
Write 32 bars of music based entirely on a three note theme x y z.

...or even...

Write 3 bars of music consisting solely of rhythms and articulations on the pitch A4 with a clear beginning, middle, and end.

... then you will find ways to be creative within those constraints, and the same constraints will make it easier to actually finish pieces. The constraints above I made up off the top of my head, but I'll list below some specific composition exercises that my teachers have assigned that could be useful:

Arrange "Hark, the Herald Angels Sing" for solo piano by reharmonizing.
Be handed a sheet of staff paper that is blank except for the first bar of music, which has been provided for you. You must fill the remainder of the page. You have 40 minutes.
Set the text of a poem of your choice as an art song. (This one is nice if you have problems determining your compositions' pacing, since that will be decided for you by the text.)

So, the above won't work for everyone, but hopefully it will provide some food for thought on a few of the topics you mentioned. Essentially, don't become discouraged by perceiving yourself as lacking technique, instead, become motivated to develop that technique so you can put it to use! And, as Steve Vai has been known to say on occasion:

"If you want to play something that you can't, you need to see and hear yourself doing it in your minds eye. It will start to happen."

To paraphrase: if you can visualize yourself playing/improvising/composing the way you would like to and with the facility that you desire, you've already taken the first step to achieving that goal.
Comment: +1 Congrats on your 10k! And 10.000 thanks for all your superb and inspiring answers!
Answer: For actual composing, you might want to ditch the DAW in favor of a little notebook of staff-pages. When you improvise a nice riff or melodic fragment, write it down before you improvise on it too much.
Most of my pages have just a few (2, 4, 8) measures of melody and rhythm. But the great part is when you need a melodic or rhythmic idea, you can borrow from your past self. If you need a busy syncopated left-hand rhythm, you can scan just the beams for a measure with lots lines. If you need a sweet melody with an early jump, and if you've been doing this diligently for a few months, you've probably got one.
While the computer is a great tool in realising your work; for the storage of musical ideas, pen and paper is still tops.
This can also help to focus your improvising sessions. Sometimes you want to come up with an entire song; sometimes you only need something worth remembering (to develop later).
Comment: I think it's easier to use a dictaphone, since you don't need to pause while improvising, and then you don't have to use focus on memorizing what you're coming up with. Of course, you can end up having lots of more material than you want, but usually what I need to improve a song is just to hear the "draft" again.
Comment: I have worked that way in the past. But in a way it's exactly what OP doesn't want, being "too picky". Using a notebook means much more "music" gets discarded, only the themes, the *seeds* that led to compelling moments go into the book. The same "territory" can easily be found again by improvising on the theme. And the ability to *scan* should not be underestimated. Many music books contain thematic indices for much the same purpose. ...  But *combining these two methods* may be ideal. How else are you gonna find that great solo that was somewhere between 'Untitled 32' and 'Untitled 97'?
Answer: I think that you may be held back by your focus on improvisation: one of the wonderful things about composition is the ability to go back and revise already-written material. Consider trying traditional notation, or thinking of your recordings as rough drafts that you then edit slowly in a sequencer—it's unreasonable to expect a great work of music to spring from your fingers without revision.
Just as a sculptor first forms the clay into a general shape, then refines it, then adds final details, you must learn that the most important part of music composition isn't that what you have is amazing... the most important thing is that your piece is becoming more amazing every time you edit it. Having that right 'trajectory' will, ultimately, produce better work than an exceptional first draft.
When seen in this new context, your high standards become an asset rather than an annoyance—they will help you know what to edit, and help you continue to edit until you have something you love.


With MVVM, does each UI window have its own ViewModel?

Question: When I'm designing multiple views under the MVVM pattern, does each view get its own ViewModel or do they all share the same one?  I understand that this is ultimately a flexible decision, but what is the best practice?
My gut tells me to have a ViewModel for each view (i.e. each separate UI window).  All of the blog examples of MVVM show a single view but not much beyond that.
Answer: Yes, basically the idea is that your viewModel should only be used by one view.  If you use a viewModel to populate an area (like in ASP.NET MVC) then that viewModel is "reused" each time that view is presented in difference places.
This article is a discussion by Josh Smith of the MVVM pattern.  Then, Ward Bell discusses in this article what he thinks Josh left out, while maintaining that Josh's work is still very strong.
Ward does an excellent job of laying out the complexities of this pattern and showing the tension that exists.  Here is his take on the tension:

In my experience there is a "dialog" between View and ViewModel design. The VM exists to  serve a view even as it strives for independence from any particular concrete view. A VM is useless if  there is no view that will work with it; clearly the VM developer must
  heed the imprecations of the View developer.
On the other hand, in business applications the application's imperatives – what the view  must do to satisfy business requirements – are the province of the programmer and are > best articulated through the capabilities of the ViewModel.
Therein lies the necessary tension between View and ViewModel design. As a developer my allegiance is with the ViewModel ("the application should do something worthwhile") but it would be silly to defend that allegiance at the expense of the View ("a good UX is essential to making an application easy to learn and to use").
Answer: To me thats a subjective statement- text book, I would say definately a 1-1 pairing - and there is certainly nothing wrong w/ being proactive and setting the paradigm by having a 1-1. However, if you have multiple views each representing a slice of the same data you dont necessarily have to have 1 per- you could reuse the same one across multiple views until you had a deviation. The purpose of the view model being a bridge between the ui and the business layer...if the business functions are the same you are either going to have a common view model interface or base and cast down or you are going to be replicating the same logic multiple times. If the view is the only thing that changes I see no issue in reusing the same view model until there is deviation.
In wpf, you should be binding to values on the model so unless your view model has a reference to your concrete view that shouldnt be an issue. Even it does, you could abstract out to a view contract (interface) and change the property to be that type instead.
Answer: Yup, each view should have its on ViewModel.
I don't know WPF inside out, but generally the ViewModel mediates between a UI component and a business logic component. In other words: It's specific to a view/model pair - this is the only reason for this component to exist...
HTH.


Django - Annotate within for loop - what is the difference between my two codes

Question: I am trying to sum up two columns in a view with values() and annotate().

Column 1
Column 2

5
0

5
-2

Currently calling "total" will return the total for each row and not the overall total.
Returning in template
5
3

instead of
8

I believe this is because I print the total in a for loop. What confuses me is that I have an almost similar code working perfectly fine in another view.
How can I get the total of the several rows together?
Update to answer Willem's question - timestamp is used to order the list of model objects when they are created.
This was not the result I initially wanted when I wrote the code. But realised I could use this view to render a report of the objects as they are being created, so I added the timestamp to order the objects starting with the most recent one.
This is not relevant for my problem. I removed it to avoid confusion. Sorry for this.
views
def function(request, userprofile_id):
venue = UserProfile.objects.filter(user=request.user).values('venue')
points_cummulated_per_user_per_venue = Itemised_Loyalty_Card.objects.filter(user=userprofile_id).filter(venue=request.user.userprofile.venue).values('venue__name','timestamp').annotate(sum_points=Sum('add_points')).annotate(less_points=Sum('use_points')).annotate(total=F('add_points')-F('use_points')).
return render(request,"main/account/venue_loyalty_card.html",{'venue':venue,'points_cummulated_per_user_per_venue':points_cummulated_per_user_per_venue})

template
{%for model in points_cummulated_per_user_per_venue %}
Total: {{model.total}}
{%endfor%}

models
class Itemised_Loyalty_Card(models.Model):
    user = models.ForeignKey(UserProfile, blank=True, null=True, on_delete=models.CASCADE)
    venue = models.ForeignKey(Venue, blank=True, null=True, on_delete=models.CASCADE)
    add_points = models.IntegerField(name = 'add_points', null = True, blank=True, default=0)
    use_points = models.IntegerField(name= 'use_points', null = True, blank=True, default=0)

class Venue(models.Model, HitCountMixin):
    id = models.AutoField(primary_key=True)
    name = models.CharField(verbose_name="Name",max_length=100, blank=True)

Comment: WHat are column1 and column 2 here? What are you trying to achieve?
Comment: Furthermore please share the relevant models.
Comment: All updated. What I am trying to achieve is to sum up the 2 model fields (add points and use_points) together to get the total points.
Comment: Pleae include the model of the `Venue`, what is `timestamp` doing here? What do you try to achieve?
Comment: I added the model and a bit more explanation. I should have removed the `timestamp` from the code, as it made my request more confusion. I only added it as I realised the code as I wrote it was not rendering what I was looking for but could be used to render a report of the objects created. Did I answer your question? (thanks for sticking around!)
Answer: Please don't use .values(…). I wrote a short article that describes several problems with this [Django-antipatterns].
from django.db.models import F, Sum

def function(request, userprofile_id):
    profile = request.user.profile
    venue = profile.venue
    venues = Venue.objects.filter(itemised_loyalty_card__user=profile).annotate(
        total=Sum(
            F('itemised_loyalty_card__add_points')
            - F('itemised_loyalty_card__use_points')
        )
    )

    return render(
        request,
        'main/account/venue_loyalty_card.html',
        {
            'venue': venue,
            'venues': venues,
        },
    )
then in your template you enumerate over the venues and render the total:
{%for item in venues %}
    {{ item.name }}: {{ item.total }}
{% endfor %}

Note: Models in Django are written in PascalCase, not snake_case,
so you might want to rename the model from Itemised_Loyalty_Card to ItemisedLoyaltyCard.
Comment: That's well impressive you managed to completely change my code so quickly without much background and still get the expected result. (only had to re-add a filter for venue). I am still trying to map the logic. I wish I could up vote you twice! If you dont mind me asking what sort of risk do I take by writing my model `Model_1` instead of `Model1`? I have loads of models written in this pattern and wondering if I need to change everything.


How to loop over this API response object in React and get 'urls' link for image?

Question: I'm trying to loop over an Object in React, the object is being received from an API, I need to get the url 'regular' link. I have a state that sets the response from the API called 'searchImages',  I have been trying the following:
  {searchImages.map(item => (

   ))}

but i get error: TypeError: undefined is not a function (near '...searchImages.map...')
the actual object received from API is:

next level:

results level:

index 0 level:

urls level:

so I wanted to get the urls regular link for all results in the main results array.
if I haven't described something please let me know and I'll provide more info, otherwise any help would be appreciated.
I have called the API and then the response is set to state:
const [searchImages, setSearchImages] = useState([]);

    useEffect(() => {
        fetch(`https://api.unsplash.com/search/photos/?client_id=btWDn-ckRUbNxJA&count=2&query=${searchInput}&per_page=2&orientation=landscape`)
        .then(response => response.json())
        .then(images => setSearchImages(images));
    },[])

Comment: You need to show the code where you initialized or assigned `searchImages` variable. Btw, do not paste images into your question, that is [not](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors) the SO guideline.
Comment: well What is `searchImages` obviously not an array ... probably you want `searchImages.results.map(...)`
Comment: I get back a dict '{total: 6, total_pages: 3, results: Array}'
Answer: From response you are setting json object in SearchImages instead of json array. So update your code which fetch images. Also make sure you set searchImages with blank array if response don't come.
useEffect(() => {
    fetch(`https://api.unsplash.com/search/photos/?client_id=btWDn-ckRUbNxJA&count=2&query=${searchInput}&per_page=2&orientation=landscape`)
    .then(response => response.json())
    .then(images => setSearchImages(images.results));
},[]);

Comment: Tried that, but it still says 'TypeError: undefined is not an object (evaluating 'searchImages.results.map')'


Treatment and Control group, the sample size

Question: I am doing the evaluation for a program with 200 members (they enrolled in the program at different times in the past year and the program doesn't end). Only 78 completed the pre test survey. Now I have to look for a control group and resources are scant... What is the ideal number of a sample size for the control group? What is the optimal number?
I also know it is a big limitation that treatment and control group didn't take the pre test at the same time, how big is that limitation?
Thanks!
M.
Comment: It is rather hard to say in the abstract. What kind of data do you have? Eg, do you think of the response as continuous? How big of a difference between the treatment & control groups do you want to be able to detect?
Comment: Yes, my main health outcomes are BMI, blood pressure, and glucose level.
Answer: In epidemiological research an optimal ratio is of 4 controls to 1 case (assuming it's an unmatched design). After that, power increases but at a decreasing rate as the ratio of controls/cases increases.

from Woodward, M. Epidemiology Study Design and Analysis. Boca Raton: Chapman and Hall:, 1999, p.265
Comment: Thanks Marijana. Although this is not an epidemiological research. This is a health program, focused on wellness and prevention...
Comment: hi Mariana, I think the same methodological issues apply to public health intervention. What effect size do you wish to achieve with your program? e.g. odds ratio of 1.5, or 2? What is the prevalence of the risk factors. With this information, you can use standard online sample size calculators, like http://sampsize.sourceforge.net/iface/s3.html#ccp


Shiny R Histogram

Question: I am using below code to lean Shiny R , when i run this code, it gives me this error:

Warning: Error in hist.default: 'x' must be numeric
    [No stack trace available]

library(shiny)

ui <- fluidPage(
  selectInput("Ind","Indipendent Variable",choices = names(mtcars)),
  selectInput('Dep','  Dependent Variable',choices = names(mtcars)),
  plotOutput("BoxPlot"),
  plotOutput('Hist'))

server <- function(input, output, session) {

  data1 <- reactive({input$Ind})
  data2 <- reactive({input$Dep})

  output$BoxPlot <- renderPlot({boxplot(get(data2()) ~ get(data1()) , data=mtcars)})

  output$Hist <- renderPlot({hist(get(data1())})

}

shinyApp(ui, server)

any help why would it say so ?
Answer: Try not to put everything into 1 line as it doesnt improve readability, you can use Google's R Style Guide if you like.To answer your questions you can access the variable via [[]] like so:
library(shiny)

ui <- fluidPage(
  selectInput("Ind","Indipendent Variable",choices = names(mtcars)),
  selectInput('Dep','  Dependent Variable',choices = names(mtcars)),
  plotOutput("BoxPlot"),
  plotOutput('Hist')
)
server <- function(input, output, session) {

  data1 <- reactive({
    input$Ind
  })
  data2 <- reactive({
    input$Dep
  })

  output$BoxPlot <- renderPlot({
    boxplot(get(data2()) ~ get(data1()) , data=mtcars)
  })

  output$Hist <- renderPlot({
    req(data1())
    hist(mtcars[[data1()]])
  })

}

shinyApp(ui, server)

Comment: @Fahadakbar Probably also worth pointing out that the reason it wasn't working in the first place is because `get(data1())` was being translated to, for example, `get("mpg")`, which returns the entire `mtcars` data frame. As a result, you were originally calling `hist` on the data frame, and not on the specific variable. This answer gets around that by calling the variable directly from the `mtcars` dataset.
Comment: Hi Pork Chop, great suggestion. it worked, but quick question , whats the difference between [] and [[]]
Comment: The double brackets are for accessing variables inside more complex objects such as lists, you can read more in this nice blog https://davetang.org/muse/2013/08/16/double-square-brackets-in-r/ and also in the manual
https://cran.r-project.org/doc/manuals/R-lang.html#Indexing
Comment: awesome , and why do we need req function ? I also noticed that we used it for the histogram , but not for the boxplot , why so ?? thanks a lot for your help
Comment: Using `req()` is just a habit of mine, which I think is a good practice to get into, you shouldnt need it here unless you're dynamically generating content

Shiny R Histogram


How do I safely get the internal path to the current site in a multisite setup?

Question: I'm working with a multisite Drupal 7 install with many sites. The site accepts both "www." and without via Apache. I'm developing a themes in /sites/all/themes which is used by many of these sites and I want something like this:
$apple_icon =  array(
    '#tag' => 'link',
    '#attributes' => array(
      'href' => '/' . path_to_site() . '/apple-touch-icon.png',
      'rel' => 'apple-touch-icon',
    ),
  );
  drupal_add_html_head($apple_icon, 'apple-touch-icon');

where path_to_site gives like /www/drupal7/sites/blah.com etc. depending on the site being used. I need this since each site will need a different icon.
I guess something like '/sites/' . $_SERVER['HTTP_HOST'] and then I can use symlink aliases for the "www." variant.
How can I do this properly?
Answer: You can use conf_path to get the path root to the current site - then append the rest of your path to that.

Returns the configuration path based on the site's hostname, port, and
  pathname.

e.g:
$apple_icon =  array(
  '#tag' => 'link',
  '#attributes' => array(
    'href' => base_path() . conf_path() . '/apple-touch-icon.png',
    'rel' => 'apple-touch-icon',
  ),
);
drupal_add_html_head($apple_icon, 'apple-touch-icon');


ORMLite collection of entities without reference

Question: I want to add an Attachment entity which I will be refering to from multiple different Entities, but it does not refer back to these, how do I get this working in ORMLite?
I keep getting this Exception:
 Caused by: java.sql.SQLException: Foreign collection class entity.Attachment for
    field 'attachments' column-name does not contain a foreign field named
    'attachmentId' of class enity.News

For example I have a News Entity
@DatabaseTable
public class News extends Record {

    @DatabaseField(index = true, id = true)
    private long newsArticleId;
    @DatabaseField
    private String subject;
    @DatabaseField
    private String content;

    @ForeignCollectionField
    Collection<Attachment> attachments;
}

The Attachment Entity:
@DatabaseTable
public class Attachment extends Record {

    @DatabaseField(id = true, index = true)
    private long attachmentId;

    @DatabaseField
    private String attachmentUrl;
}

Could someone please point to me and laugh and tell me why I am doing this wrong and what I'm misunderstanding here.  Thanks.
Answer: This is a FAQ.  To quote from the ORMLite docs on foreign-collections:

Remember that when you have a ForeignCollection field, the class in the collection must (in this example Order) must have a foreign field for the class that has the collection (in this example Account). If Account has a foreign collection of Orders, then Order must have an Account foreign field. It is required so ORMLite can find the orders that match a particular account.

In your example, for ORMLite to figure out which Attachments a particular News entity has, the Attachment entity must have a News field.  The other way to do would be to have a join table, but ORMLite won't do that for you.
Comment: Ok, so i'll just have to make a join table. I'll do this, I was hoping there would be some hidden tables created in the back.

Thanks for your response.


KEYCLOAK VERTX logout

Question: I'm currently using keyckloak with vertx and I'm trying to logout from my application but I can't remove the token. When I logout, I still have the access to the private page. Can you give me some advises?
This is my code:
    InputStream input = new FileInputStream("./config.properties");
    Properties prop = new Properties();
    prop.load(input);

    String resource = prop.getProperty("resource");
    String credentials = prop.getProperty("credentials");
    int listeningPort = Integer.parseInt(prop.getProperty("listeningPort"));

    OpenIDConnectAuth.discover(vertx,
            new OAuth2Options()
            .setFlow(OAuth2FlowType.AUTH_CODE)
            .setSite("http://10.241.0.188:8080/auth/realms/demo")
            .setTenant("demo")
            .setClientID(resource)
            .setClientSecret(credentials))

    .onSuccess(oauth2 -> {
        OAuth2AuthHandler test = OAuth2AuthHandler.create(vertx,oauth2)
            .setupCallback(router.get("/callback"));

        router.route("/private/*").handler(test);

        router.route("/private*").handler(ctx -> {
            ctx.response().sendFile("/home/Documents/private_page.html");
            });

        router.route("/").handler(ctx -> {
            ctx.response().sendFile(index);
            });

        router.route("/webroot/*").handler(StaticHandler.create("webroot"));

        router.route("/logout").handler(context -> {
            AccessToken user = (AccessToken) context.user();
            user.logout(res -> {
              if (res.succeeded()) {
                  context.clearUser();
                  context.session().destroy();
                  context.response().putHeader("location", "/").setStatusCode(302).end();
                    // the logout call succeeded
                  } else {
                    // the user might not have been logged out
                    // to know why:
                    System.err.println(res.cause());
                  }
              });
          });
        vertx.createHttpServer().requestHandler(router).listen(listeningPort);
    });
}

}
Answer: With vert.x 4.x the security module has been improved in a way that the User object is now generic and does not require custom class casts for specific providers.
This means that the example is trying to use deprecated code, so it should be updated for the new API.
Moreover, Vert.x 4.x also improved the support for Oauth2 + OpenId Connect standards, and now supports the official end session url instead of relying on non-standard features like it used to be with: AccessToken.logout().
So to perform a logout you now only need to do:
router.route("/logout")
  .handler(ctxt -> {
    // clear the session
    ctx.session().destroy();
    // use the oauth2/oidc end session url to signal the logout
    ctx.redirect(oauth2.endSessionURL(ctx.user()));
  });

Comment: Thanks for your reply, it worked. I'm trying to redirect to a HTML page in my directory when I'm logged. Do you know how to do it?
Comment: You can use the `redirect()` method just like the logout, replace the argument with the `url` you want it to go to. e.g.: `ctx.redirect("/other.html")`

KEYCLOAK VERTX logout


Custom css for Amcharts

Question: I'm using Amcharts 4 and Angular 7. Could not find any resources to use a custom css for the tooltip. Explored amchart site and the questions here in Stackoverflow but no similar question. Anyone who knows about this? Would appreciate any help. I could use  inlign styling but code would be cleaner with external css.
Comment: Hello gladsching, looks like it is your first post on StackOverflow. I recommend providing more insight about which Angular and Amchart version you are using in order to let other users know about it and also what steps have you tried in order to accomplish your need. Cheers!
Answer: First step for doing this is the next:

If you need complex information in your tooltip - tables, images, CSS
you might consider tooltipHTML. It accepts any valid HTML, including full-fledged CSS, so you can do anything in there.

/**
 * ---------------------------------------
 * This demo was created using amCharts 4.
 *
 * For more information visit:
 * https://www.amcharts.com/
 *
 * Documentation is available at:
 * https://www.amcharts.com/docs/v4/
 * ---------------------------------------
 */

// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end

var chart = am4core.create("chartdiv", am4charts.XYChart);

var data = [];
var value = 120;

var names = ["Raina",
  "Demarcus",
  "Carlo",
  "Jacinda",
  "Richie",
  "Antony",
  "Amada",
  "Idalia",
  "Janella",
  "Marla",
  "Curtis",
  "Shellie",
  "Meggan",
  "Nathanael",
  "Jannette",
  "Tyrell",
  "Sheena",
  "Maranda",
  "Briana",
  "Rosa",
  "Rosanne",
  "Herman",
  "Wayne",
  "Shamika",
  "Suk",
  "Clair",
  "Olivia",
  "Hans",
  "Glennie",
];

for (var i = 0; i < names.length; i++) {
  value += Math.round((Math.random() < 0.5 ? 1 : -1) * Math.random() * 5);
  data.push({ category: names[i], value: value });
}

chart.data = data;
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.dataFields.category = "category";
categoryAxis.renderer.minGridDistance = 15;
categoryAxis.renderer.grid.template.location = 0.5;
categoryAxis.renderer.grid.template.strokeDasharray = "1,3";
categoryAxis.renderer.labels.template.rotation = -90;
categoryAxis.renderer.labels.template.horizontalCenter = "left";
categoryAxis.renderer.labels.template.location = 0.5;

categoryAxis.renderer.labels.template.adapter.add("dx", function(dx, target) {
    return -target.maxRight / 2;
})

var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.tooltip.disabled = true;
valueAxis.renderer.ticks.template.disabled = true;
valueAxis.renderer.axisFills.template.disabled = true;

var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.categoryX = "category";
series.dataFields.valueY = "value";
series.tooltipHTML = `YEAR 2020

  Cars
  1

  Motorcycles
  2

  Bicycles
  3

`;
/*series.sequencedInterpolation = true;
series.fillOpacity = 0;
series.strokeOpacity = 1;
series.strokeDashArray = "1,3";
series.columns.template.width = 0.01;*/

var bullet = series.bullets.create(am4charts.CircleBullet);

chart.cursor = new am4charts.XYCursor();

chart.scrollbarX = new am4core.Scrollbar();
chart.scrollbarY = new am4core.Scrollbar();
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

#chartdiv {
  width: 100%;
  height: 500px;
}

.test_table{
  color: red;

}

Here's the doc for further information

Custom css for Amcharts


What is this symbol that looks like an elongated "L" on the left-hand piano staff, and how can I write it in Musescore?

Question: I'm writing out the Bärenreiter version of Bach Concerto for two violins BWV 1043 on Musescore, and have come across an odd symbol in the left hand piano part.
Here is a picture - the elongated L symbol just before the G#:

At a guess, it looks like it is separating a voice, but I'm not sure what it's called so I can't find it in the Musescore palettes.
Comment: Hmm, I don't know the name, but it's definitely used to indicate that the note above the bottom crook of the line is played by the RH despite being written in the lower staff.
Comment: @PatMuchmore so I have just realised from looking at the number of rests in the RH!
Answer: As Pat correctly stated, this instructs the performer to play this music with the right hand.
You can find this bracket in MuseScore by opening up the Master Palette (press z to open it up). I recommend using the search feature and searching for "hand," and you should see the bracket there.
You may also find this discussion on MuseScore's website helpful.
Comment: Well I never. That's handy...
Comment: There's also a flipped version for playing notes on the upper staff with the left hand.  You could get away with omitting them since the direction of the note stems also gives you the same information, but it never hurts to add clarity.


Acessando Lista de outra classe

Question: Tenho uma classe Armazemque contem uma lista de produtos, como seria a interação dessa lista na classe gerencia utilizando o método retornaProduto() sem parâmetros. Na saída do meu código está dando null.
Classe Armazen
public class Armazem {
  List<Produto> produtos;

  Armazen(){
        this.produto = new ArrayList<Produto>();
  }
  public void adicionarProduto(Produto p) {
            produtos.add(p);
  }
  public List<Produto> getProdutos() {
        return produtos;
  }

Classe Gerencia
public class Gerencia{
    Armazen a = new Armazen();
    private String N_estoque;

    public Gerencia(String N_estoque) {
       this.N_estoque = N_estoque;
   }
   public  Gerencia retornaProdutos() {
       for(Armazen pdto : a.getProdutos())
              System.out.println("esses são os produtos"+ pdto);

}

  public static void main(String[] args) {
       Produto arroz = new Produto("Arroz");
       Gerencia gerencia = arroz.retornaProdutos();
      System.out.println("Em estoque: " + gerencia);

}
Comment: Se alguem puder me ajudar nessa.
Comment: Minha grande dificultade é em entender como usar uma lista que foi populada em outra classe, já tentei criar uma reférência para classe tipo( List  outraClasse; ), e não consegui, já procurei alguns exemplos mas ainda não consegui entender.
Comment: Olá  amigo, obrigado pela atenção, foi só erro de digitação mesmo pois fiz no celular essa postagem, mesmo com this.produtos está retornando null.
Answer: No construtor da classe Armazen, você está usando this.produto e não this.produtos, pois a variável declarada nessa classe é produtos, e não produto.
No seu método de retornaProdutos na classe Gerencia você deveria retornar void ou fazer um retorno de acordo com o que quer. E dentro dos parâmetros do for, você deveria fazer Produto pdto : a.getProdutos(), pois cada elemento retornado de a.getProdutos() é um Produto, e não um Armazen.
E no caso essa sua lógica de salvar o retorno de retornaProdutos dentro de uma variável e depois retorna-la dentro de uma String não irá funcionar, pois você não está retornando uma lista.
Além disso, no método main você não está adicionando nenhum produto na lista.
Suponde que você importou ArrayList e List corretamente, e a classe Produto existir, acredito que o seu código irá funcionar corretamente com essas alterações.
Comment: Obrigado amigo vou fazer as alterações que você me indicou.

Acessando Lista de outra classe