Is $Y$ a function of $X$ (without knowing the shape of the function)?

Question: I have a dataset consisting of pairs of points, $(x_i,y_i)$. Visually, I see that the points are not completely smeared, but that $x$ seems to exert some control on $y$. In fact, I suspect that $y$ is a function of $x$ plus some noise. But I have not idea of the shape of this function. Is there a statistical test to determine if $y$ is a function of $x$, without knowing the shape of the function a priori?
To be more precise, I want to determine whether the data is consistent with a model of the form:
$$Y = f(X)+\eta$$
where $\eta$ is normally distributed with zero mean and unknown mean. The function $f$ is also unknown.
Comment: "Is a function" in what sense? A huge map, that maps 10000000 distinct inputs to 10000000 distinct outputs is also a function, so whatever your data is, it can be output of some very, very complicated function.
Comment: @Tim Not really. A function means that if $x$ is the same, then $y$ is the same too (except for noise).
Comment: well, yes, what I described is a function in that meaninfg. Eg, f(1) = 132123, f(2.1) = 3333, f(5) = 8, ...
Comment: "Function" is way too broad, instead you can test independence using [distance correlation](https://en.wikipedia.org/wiki/Distance_correlation), see also [When is distance covariance less appropriate than linear covariance?](https://stats.stackexchange.com/questions/23785/when-is-distance-covariance-less-appropriate-than-linear-covariance)
Comment: @Francis But "independence" is not specific enough. $X$ and $Y$ might be dependent, and yet $Y$ not be a function of $X$. Imagine a circle. There is not a single value of $Y$ corresponding to each value of $X$.
Comment: A rough but effective exploratory rule of thumb is to split the $x_i$ into tertiles, then compare the mean of the $y_i$ corresponding to the top third of the $x_i$ to the mean of the $y_i$ corresponding to the bottom third.  (This can be carried out mentally when inspecting a scatterplot.)  But there exist more sophisticated methods depending on what you know, or are willing to assume, about the phenomenon you are studying and how the data were collected.
Comment: `[I] want to determine whether the data is consistent with a model of the form:`. Sure, you can determine this insofar as you can list characteristics distinguishing $f(.)$ from $\eta$, with a precision that will be bounded by the difference (under your model) between the former and the latter.
Answer: $Y$ being a function of $X$ is a much more constrained scenario from $Y$ being a function of $X$ plus some noise.
The former case implies that for each value of $X$, there is only one possible value of $Y$ (i.e., the distribution of $Y$ conditional on any given value of $X$ is degenerate). It's easy to check whether a dataset satisfies this rule.
The meaning of the latter depends on what you mean by "noise". If you mean a random variable with mean 0 that's independent of $X$ and $Y$, then you could investigate how credible this proposition is by looking at the mean of $Y$ conditional on each value $x$ of $X$—it should be closer to $x$ the larger your sample is.
This said, none of this is likely to solve your real problem.
Comment: I mean the latter case, see edit. Yes, the "noise" is normally distributed with mean zero but the variance is unknown. I did not understand the last statement, that "looking at the mean of $Y$ conditional on $X$ it should be closer to $X$ for larger sample"? Why? The unknown function relating $Y$ to $X$ need not be linear.
Comment: @becko By hypothesis, the conditional distribution $(Y|X = x)$ is equal to $x + ε$ where $ε$ is a random variable with mean 0, so the mean of $x + ε$ is just $x$. The functional form of $f$ doesn't get to play a role here because of the conditionalization on a particular value of $X$.
Comment: I disagree. If $f$ were known, the conditional distribution $P(Y|X=x,f)$  would be the normal distribution of the noise (assuming also the noise variance is known), in which case the mean of $Y$ would be $f(x)$.
Comment: @becko Ack, you're right, sorry: the conditional mean should be $f(x)$. I guess I was asleep at the wheel. What you can do, then, is look at whether the conditional distribution is normal. That's the only part of your model that's restrictive enough to have much of a consequence for the data.
Comment: But I don't know the variance nor the mean!
Comment: @becko True, but you needn't know either to judge how normal-looking a distribution is. A normal distribution still looks quite different from many other distributions with the same mean and variance.
Comment: Is there a test that I can apply?
Comment: @becko Do you mean a significance test? For that, you would need to be able to formulate an appropriate null hypothesis, but I don't see how you could.


Dimension of an addition of two subspaces

Question: We have $A,B \subset V$ two subspaces of a finite dimension vector space $V$. I have to show that
$$\dim(A+B) = \dim(A) + \dim(B)$$
if $A \cap B = \{0\}$. How can I show this without just saying that
$$\dim(A+B) = \dim(A) + \dim(B) - \dim(A \cap B)?$$
I have tried with example but I don't find one that work.
Comment: Use induction on the dimension.
Answer: Hints. Let $(v_i \mid i = 1,\ldots, n)$ a basis of $A$ and $(v_i \mid i = n+1, \ldots, n+m)$ a basis of $B$. Show that $(v_i \mid i = 1, \ldots, n+m)$ is a basis of $A+B$ (you will need $A \cap B = 0$ in prooving that). The result follows.


How complex numbers can be compared in Cauchy-Schwarz inequality in an inner product space over the complex field

Question: The Cauchy-Schwarz inequality is given by
$|\langle x,y \rangle| \leqslant  \|x\| \|y\|,\, x,y\in V$ . My question is that over the complex fields the RHS of the inequality will be a complex number. But we know that complex numbers cannot be compared. Then how is it possible to compare them in this inequality?
Comment: For all $x\neq 0$, even for a complex vector, we have $\|x\|>0$ is real and positive.
Answer: In $\Bbb C^n$, the RHS is a non-negative real number, since$$\|(z_1,z_2,\ldots,z_n)\rVert=\sqrt{|z_1|^2+|z_2|^2+\cdots+|z_n|^2}.$$
Comment: But norm of x is defined as square root of inner product of x and x . If the field is C then the inner product will also be in C
Comment: In $\Bbb C^n$, the standard inner product is$$\langle(z_1,z_2,\ldots,z_n),(w_1,w_2,\ldots,w_n)\rangle=z_1\overline{w_1}+z_2\overline{w_2}+\cdots+z_n\overline{w_n};$$in particular, if $z,w\in\Bbb C$, $\langle z,w\rangle=z\overline w$. So, $\langle z,z\rangle=z\overline z=|z|^2$ and therefore $\|z\|=|z|$. If you are working with another inner product, then tell us which inner product is that.
Comment: There is an inner product space Mm×n (C). The inner product is defined in the following page https://www.sciencedirect.com/science/article/pii/S0024379513005867
Comment: You can read on page 3 of that article that "any given inner product $\langle,\cdots,\cdot\rangle$ on $M_n(\Bbb C)$ is a bounded sesquilinear form on $M_n(\Bbb C)$". If $B$ is such a sesquilinear form, then, since it is sesquilinear, $B(M,M)\in[0,\infty)$, for every $M\in M_n(\Bbb C)$.
Comment: I am just a beginner in this topic. I have no idea about sesquilinear forms. I just saw an example of an inner product space over C so as to clarify my doubt. Can you please elaborate your explanation
Comment: What I wrote in my previous comment about $B(M,M)$ being always a non-negative real number is not correct (but it is always real). Anyway, it is [part of the definition of inner product on a complex space](https://en.wikipedia.org/wiki/Inner_product_space#Complex_coordinate_space) that you always have $\langle M,M\rangle\geqslant0$.
Comment: So does that mean that norms of any inner product spaces belong to real number set, it will never be a complex number with non zero imaginary part?
Comment: No, **never**.${}$
Comment: Do you mean it will never be complex, right?
Comment: I mean that the norms will **always** be non-negative real numbers.
Comment: Okay. Thankyou so much for your assistance
Comment: If my answer was useful, perhaps that you could mark it as the accepted one.


Seleção parcial de uma classe com jQuery

Question: Olá,
Gostaria de saber se é possível selecionar uma classe/elemento a partir de um valor parcialmente informado, por exemplo:

   100%

Gostaria de selecionar os elementos apenas informando que as classes contém o p antes dos números pois aqueles números são variáveis.
Tentei selecioná-los da seguinte forma e sei que está super errado também haha:
$("div[class*='chart-']").removeClass(div[class*='p']);

Alguma sugestão?
Obrigado!
Comment: Sim, entendi, foi apenas para usar seu exemplo com exemplo. Mas problema resolvido, retirei meu [voto para fechar](http://pt.stackoverflow.com/questions/146039/ocultar-divs-com-id-parecido/146041#146041). :)
Comment: é de fato o tipo de busca que preciso @PedroCamaraJunior, porém não estou conseguindo colocar encaixar ao meu código, segue como tentei fazer: `$("div[class^='chart-']").removeClass("div[class^='p']");`
Comment: Acho que entendi, você precisa selecionar a `div` que contenha a classe `chart-piso` e remover dessa mesma `div ` a classe `p100`. É isso?
Comment: @PedroCamaraJunior que contenha apenas "chart-" pois `piso`é variável e remover sempre a div que contenha um classe iniciada com `p`
Answer: Se entendi o que você está tentando fazer, você poderá usar regex para remover a classe que comece com p e tenha números depois, algo assim:

$("div[class^='chart-']").removeClass(function(index, className) {
  return (className.match(/(p[0-9]+)/g) || []).join(' ');
});
console.log($("div[class^='chart-']").attr("class"));

  100%

Comment: funcionou perfeitamente!! Muito obrigado!
Comment: Uma dica seria usar a expressão: `/\bp\d+\b/g` (com *word boundary*)
Caso queira que classes como `.p100s` não sejam removidas.
Comment: o console me retornou o seguinte: `Uncaught SyntaxError: Unexpected token ^=`
Answer: A resposta do @Lucas Costa já resolve de uma ótima maneira seu problema, vou apenas postar uma outra maneira possível utilizando o String.replace().

var $divChart = $("div[class^='chart-']");
var divClasses = $divChart.prop('class');

$divChart.prop('class', divClasses.replace(/\p[0-9]{3}/g, ''));

console.log('Classes da div: ' + $divChart.prop('class'));

   100%

Answer: Uma alternativa à resposta do @pedro-camara-junior com JS puro, certo que foi solicitado com jQuery, mas as vezes não chega a ser necessário, seria o uso do querySelector():

var el = document.querySelector('div[class^=chart-]');
el.className = el.className.replace(/\b(^|\s)p\d+\b/g, '');

console.log("res: " + el.className);

   100%


Check whether a value exists in an HBase table

Question: I've got an HBase table with data that looks like:
key1 c:hasErrors false
key2 c:hasErrors true
key3 c:hasErrors false

I want to check whether the column qualifier hasErrors has a value true anywhere in the table.
Obviously I can do a scan:
Scan scan = new Scan();
scan.addColumn(colFam, colQual);
Filter filter = new SingleColumnValueFilter(colFam, colQual, CompareFilter.CompareOp.EQUAL,
                new BinaryComparator(Bytes.toBytes("true")));
scan.setFilter(filter);
ResultScanner results = table.scan(scan, auditTableName);

but that's undesirable because any matching rows will be pulled back to my app, and I have to check whether results.next() != false.
Is there a way to just have a boolean returned that tells me whether or not the value is present in at least one row?
Comment: I don't any other way and scans should be avoided for performances reasons. Consider having another HBase table to track counts of hasErrors, and populate it together with the initial table.
Comment: @Harold thanks, I haven't found another way either. Luckily it's not a huge issue (I'm scanning with a row key prefix, and the scan isn't run particularly often).
Answer: Take a look at
org.apache.hadoop.hbase.filter.SingleColumnValueFilter

/**
 * Set whether entire row should be filtered if column is not found.
 *
 * If true, the entire row will be skipped if the column is not found.
 *
 * If false, the row will pass if the column is not found.  This is default.
 * @param filterIfMissing flag
 */
public void setFilterIfMissing(boolean filterIfMissing) {
  this.filterIfMissing = filterIfMissing;
}

According to docs, it will not return rows that did not match.
P.S. If you use Get, you have setCheckExistenceOnly method for the similar purpose


How much disk space is required to install KVM hypervisor on a CentOS machine?

Question: I want to install KVM on my CentOS machine. But the main partition size of my CentOS is about 50GB with only 15GB available. My question is should i extend the main partition in order to install KVM ? if yes, how to extend the main partition size?
Thank you.
Answer: If you want to install KVM, QEMU, libvirt, virt-manager, your available space is more than enough. The absolute minimum is KVM and QEMU which take very little space.
If you want to install oVirt, a vSphere or MS SCVMM like web console, you can also proceed, but probably you'll soon need more space - it also needs a DB backend.
But you should be careful regarding the locations of VMs - virtual disks and ISOs, that's the ones taking space. Probably you'll have to change the default location of the libraries.
Comment: thx!!!!!!!!!!!!


Linear regression questions

Question: I am new to the field of machine learning and am just learning linear regression, and I have some questions about this concept:
Does linear regression allow vector-valued target variables?
Does linear regression not assume that the features are uncorrelated?
Comment: Your second question is addressed [here](https://stats.stackexchange.com/a/563175/247274); there is no such assumption.
Comment: The comment by @Dave answers your second question. Comverning the second question: regression with vector valued targets is called "multivariate regression". For linear regression, it essentially boils down to training a model for each component of the target variable.
Answer:
Does linear regression allow vector-valued target variables?

You can formulate that way. It'll be a parallel set of equations, $y=X\beta$, where $\beta$ is of size $f\times t$ ($f$ is number of features and $t$ is number of targets).

Does linear regression not assume that the features are uncorrelated?

I believe @Dave's comment and the associated post clears this question; but to reiterate, features can be correlated or uncorrelated. Linear regression does not assume anything.

Linear regression questions


Trying to use importxml in google sheets to extract a value from a website, but it returns a completely different value than I am selecting

Question: image of my google sheet
I am trying to create a sheet where I want to scrape values from www.tapology.com of individual fighters and fill columns created like fighter's name, his record, where he is from, etc.
I would like to scrape some values of this fighter so I started with name:
https://www.tapology.com/fightcenter/fighters/119825-dominik-mazur
I put together something like this:
=IMPORTXML("https://www.tapology.com/fightcenter/fighters/119825-dominik-mazur", "//div[@id='stats']/ul[1]/li[1]/span[1]")

The XPath should lead to the name of the fighter which is Dominik Mazur, but for some reason it returns a different fighters name at random.
I guess it gets all the names that have the same structure, but I have no idea how to single out the value that I'm looking for.
Generally my goal is to create a google sheet where I paste a link to any fighter's tapology and it fills my sheet with the information I want instead of me manually typing everything.
Unfortunately I am not a programmer or very technical person so I would really appreciate your help. If anything is unclear please let me know.
Comment: weird! is this a joke? I had never seen this behavior beforewards...
Answer: Solution
Try this
=arrayformula(split(transpose(split(scraping("yourURLhere"),"♥")),"♦"))

with custom function
function scraping(url){
  var source = UrlFetchApp.fetch(url).getContentText().replace(/(\r\n|\n|\r|\t|  )/gm,"")
  var data = source.match(/
[\s\S\w]+?<\/div>/g)
  return (data[0].replace(/
/g,'♥').replace(//g,'♦').replace(/<\/li>||<\/strong>|<\/span>/g,'').replace(/(<([^>]+)>)/g,''))
}

Scrapping multiple urls
function infoTapology(url){
  var source = UrlFetchApp.fetch(url).getContentText().replace(/(\r\n|\n|\r|\t|  )/gm,"")
  var data = source.match(/
[\s\S\w]+?<\/div>/g)
  var infos = data[0].replace(/
/g,'♥').replace(/(<([^>]+)>)/g,'').replace(/'/g,''').replace(/"/g,'"').split('♥')
  var result = []
  infos.forEach(function(info){
    var x = info.split(':')[0]
    if (info) {x=info.replace(x+':','')}
    result.push(x)
  })
  return([result])
}

A comparison between importxml and custom function:
https://docs.google.com/spreadsheets/d/1se1lWH4g4OSvAW2NldjGiTDS5XB19_5QwSBpMqVRy84/copy
Comment: This is definitely a step closer to the goal! What if I want the function returns to be automatically dumped into a separate sheet where that information would be sorted and automatically updated, since the fighter record is not fixed? Like to have a separate sheet where I add rows of links to the fighters, and another sheet where all this information I am looking for is added. Suppose I create columns for name, age, record, etc. I would like the rows to those columns to be filled in with the information from the links on that other sheet. I don't know if this makes sense.
Comment: Can you provide a short list of urls?
Comment: Sure, for example:

https://www.tapology.com/fightcenter/fighters/162087-tobiasz-le
https://www.tapology.com/fightcenter/fighters/121479-sebastian-przybysz
https://www.tapology.com/fightcenter/fighters/247883-patryk-semeniuk
https://www.tapology.com/fightcenter/fighters/241447-daniel-alot
Comment: I have modified my answer, take a new copy of my spreadsheet
Comment: Awesome! Now I can work with it. There are still small details that can be improved, such as the fact that the height shows as 5'10", or that the height and reach are not shown separately, but I do not want to bother you anymore because you really helped me a lot and I'm terribly grateful because I would not have figured it out myself. But if you want, I would even be willing to pay you as long as it does not break the rules of this site.
Comment: No payment, it was a challenge and a pleasure. I will try to find a solution for `5'7"` ... and I still not understand why importxml doesn't work !
Comment: I have added `.replace(/'/,''').replace(/"/,'"')` to remove `'` and `"`
Comment: Wow, appreciate it! Thank you so much once again.


Build menu based in Vocabulary (Taxonomy)?

Question: I just follow this tutorial to build a menu based in the tags vocabulary. Everything is fine but now if I add a new term in admin/structure/taxonomy/tags/list the menu doesn't update, I mean that the new added term doesn't show up.
The problem is that I can't find to check: Synchronises change to this vocabulary because
I don't have this option in admin/structure/taxonomy/tags/edit as showed in the tutorial. Maybe this is because I'm using D7 and the tutorial is for D6? Where are these options in D7?
Answer: Try to use the development snapshot for Drupal 7. The update is available in that version.


Real Amp vs Amp Simulator

Question: I am a beginner guitar player(9 months). So I bought a very cheap amp, which does not even have any gain controls.
Now to get any new tones, I have 3 options.

Buy a real amp.
Use my previous amp along with pedals.
Buy an audio interface and use a guitar amp simulator on my pc and then send the output of my pc to my previous amp.

Which one will you suggest to a beginner on a tight budget of Rs. 7000($70-80) ?
My guitar is a second hand Strat copy.
Comment: For practice or recording you can't beat an amp simulator for price.  You simply can't achieve tones like a simulator without spending a lot of money on amplifiers, sound damping, microphones, cables, etc.  The only reason to buy an amplifier is if you need to jam live with a band.
Comment: @J... I am thinking of buying the Blackstar ID Core 10/20 as it also has a usb interface built in. Is that a good idea?
Comment: For you?  I don't know.  Maybe.  You haven't told us how you play, what you intend to do with the amp, or what your goals are.
Comment: @J... I am a beginner player. Can play most of the open and barre chords. I am inspired by classic rock(Hendrix, Pink Floyd etc.) so I would like to practice playing their solos. As for goals, I don't have any as of now.
Answer: The recommendation would depend on several factors.

do you ever plan on playing with other musicians outside of your bedroom? Then the PC/ amp sim solution is a big hassle. You don't want to drag your PC to every rehearsal.
does the amp that you own have a halfway-decent speaker? If not, all the pedals and amp sims in the world won't help you, your tone will be garbage.
do you plan on doing any home recording? Then an audio interface will be needed anyway at some point (as well as decent monitor speakers and/ or headphones), and the amp sim option becomes a byproduct.
what's the used gear market like where you live? Can you get a used, decent practice amp (maybe with amp sims and effects built in) for the money you want to spend? Can you get a used, decent multieffect/ amp sim unit for the money you want to spend?
what range of sounds are you looking for? 80$ will buy you two, maybe three cheap specialized pedals. Distortion is a must, and then... reverb? Delay? What could a multieffect pedal get you, and, again, can you afford one? Or would you be happy with one good clean sound and one good distorted sound? A decent practice amp with a clean/ distorted switch and no other bells and whistles might be easier to get for little money.

If you can live with the overall sound of your current amp, my personal preference would be to get a multieffect unit and hook it up to your amp; that's flexible and portable. Hope that helps.
Answer: You can consider the following amps. All around a 100$.
Fender Champion 20
A good amount of amp models, mostly fender amps sims, but a few Vox models for good measure. Really decent amount of in-built effects. The effects are basic but good enough for a player who is just getting his/her feet wet.
Blackstar LT-ECHO 10w Practice Amp
what is nice is this amp has two speakers, so you can have your backing tracks go trough one speaker and your guitar trough the other. really nice feature that. It has a in-built delay, but not much in the way of in-built effects.
Orange Amplifiers Crush12
This amp is only a one-channel amp. It has really nice cab emulator features. You cannot hook it up to a bigger cab though, which is a real bummer. A very nice 6 inch speaker can be surprisingly loud
Comment: The wattage quoted does't really give much of an indication of how loud it might be. It will depend aso on the efficiency of the speaker. I've heard 5w amps that are louder than 20w amps. Also bear in mind that double the wattage (in a light bulb, for example) only gives 50% more light.
Comment: Thanks for the recommendations. In India, the fender champ 20W costs almost double to that of lt echo 10. The orange one is not available. So I was considering the blackstar lt echo 15 vs  id core 10. The id core 10 has in inbuilt audio interface but is a bit more expensive. Also is there a lot of difference between 10/15W amps?
Comment: this is probably going to be a better bet than trying to buy a interface and a program like amplitube.

Real Amp vs Amp Simulator


Is memory address 0x0 usable?

Question: I was wondering... what if when you do a new, the address where the reservation starts is 0x0? I guess it is not possible, but why?
is the new operator prepared for that? is that part of the first byte not usable? it is always reserved when the OS starts?
Thanks!
Comment: Note that `NULL` doesn't have to correspond to an address of 0...
Comment: While NULL doesn't *have* to correspond to address zero, it's a royal PITA to implement a conforming runtime environment where that's not the case.
Comment: Related: http://stackoverflow.com/a/7547168/544198
Comment: Perhaps you meant `OS` and not `SO`?
Comment: I hope someone answers if C/C++ standard guarantees that `&x != NULL`.
Comment: IIRC, while a NULL pointer does not have to contain the value of all zeros, it is required, by at least one of the C standards, that casting a zero int value to pointer results in a NULL, and casting a NULL to int results in a zero.
Comment: @HotLicks: Plus it would break pretty much every single piece of code dealing with pointers out there
Answer: The null pointer is not necessarily address 0x0, so potentially an architecture could choose another address to represent the null pointer and you could get 0x0 from new as a valid address. (I don't think anyone does that, btw, it would break the logic behind tons of memset calls and its just harder to implement anyway).
Whether the null pointer is reserved by the Operative System or the C++ implementation is unspecified, but plain new will never return a null pointer, whatever its address is (nothrow new is a different beast). So, to answer your question:

Is memory address 0x0 usable?

Maybe, it depends on the particular implementation/architecture.
Comment: Yes, `p == 0 && reinterpret_cast( p ) != 0` is permitted to be false. The mapping via `reinterpret_cast` from addresses to integers is implementation-defined, and a null pointer does not have to map to 0. For that matter, `reinterpret_cast(strlen("")) == (void*)0` can be false, because the special rule that says a *null pointer constant* must convert to a null pointer doesn't apply to all integer values equal to 0, only to integer constant expressions with value 0.
Comment: Are you sure about that?  Is the following code wrong?  int * p = new( std::nothrow ) int; if( !p ) { ... }
Comment: @PeterRuderman: Why would that code be wrong? Have you read the note about _nothrow `new`_ in my answer?
Comment: Well, the intent of the if is to check if p is non-null.  But isn't it assuming that the null pointer is equivalent to 0?
Comment: @PeterRuderman: No, it doesn't. It's checking whether the pointer is different from the _null pointer_. `!p` is the same thing as `p != 0` and a _literal 0_ is convertible to the _null pointer_, whatever its address is
Comment: So you're saying that on some architectures, the following expression could be false? p == 0 && reinterpret_cast( p ) != 0
Comment: @PeterRuderman: No, but this could be false: `p == 0 && reinterpret_cast( p ) != 0`. Also this one could be true: `p == 0 && p == (void*)0x12345678`!
Comment: The reason is that pointer -> integer -> pointer must restore the original value, but the same is not required of integer -> pointer -> integer. That's why a null pointer is permitted to convert to some integer value other than 0, provided of course that this other value converted back to pointer gives a null pointer. Likewise a 0 that isn't an i.c.e can convert to some pointer value other than null. All this is very unusual, but not forbidden. If you imagine hadware where address 0 is somehow special (an I/O port or a register), the implementation might not want to use it for null.
Comment: @SteveJessop It's fairly unusual today, but in the past, there have been a number of widespread machines where null pointers weren't all 0 bits.  (Prime and Honeywell, amongst others, if my memory serves me right.)  And interestingly enough, in pre-standard days, most Unix implementations made page 0 write protected, but filled with 0's, so you could dereference a null pointer (but not write through it); many (very) early C programs used `NULL` for an empty string (`""`).
Answer: "Early" memory addresses are typically reserved for the operating system. The OS does not use early physical memory addresses to match to virtual memory addresses for use by user programs. Depending on the OS, many things can be there - the Interrupt Vector Table, Page table, etc.
Here is a non-specific graph of layout of physical and virtual memory in Linux; could vary sligthly from distro to distro and release to release:
http://etutorials.org/shared/images/tutorials/tutorial_101/bels_0206.gif
^Don't be confused by the graphic - the Bootloader IS NOT in physical memory... don't know why they included that... but otherwise it's accurate.
Comment: It is possible to put anything anywhere inside the kernel, since you have direct hardware access to the memory. Since the virtual addressing mechanism is "outside of" the kernel, the answer is "it depends on the kernel"
Comment: I thought that was late memory addresses.
Comment: What about inside a kernel?
Comment: @DeadMG That "High Memory" is in virtual memory.
Answer: I think you're asking why virtual memory doesn't map all the way down to 0x0. One of the biggest reasons is so that it's painfully obvious when you failed to assign a pointer - if it's 0x0, it's pointing to "nothing" and always wrong.
Of course, it's possible for NULL to be any value (as it's implementation-dependent), but as an uninitialized int's value is 0, on every implementation I've seen they've chosen to keep NULL 0 for consistency's sake.
There are a whole number of other reasons, but this is a good one. Here is a Wikipedia article talking a little bit more about virtual addressing.
Comment: In fact, in MSVC debug builds, the memory behind most addresses in the low range is filled with a specific pattern so it's easier to detect wrong pointer operations.
Comment: @lethal-guitar: I know they do that with uninitialized memory, and out of bounds memory, but I'm pretty sure they _dont_ do that with low range addresses.
Comment: Hmm, maybe I'm wrong, but I think they do - so if you have a pointer to an object and it's a NULL pointer for some reason, trying to access a member will be 0+something, and by filling the pattern there, it's easy to detect as well. But yeah, I'm not 100% sure..
Comment: @Matt The bootloader certainly is in physical memory, at least when you're booting.  A lot of systems, especially those with small address spaces, will remap the addresses corresponding to the bootloader once they've finished loading, but this isn't necessarily the case.
Comment: @lethal-guitar Most modern VM based systems will simply leave the first page of your address space unmapped, so you the program will trap if you try to access it.  It's not filled with anything, since it's simply not there.
Answer: Many memory addresses are reserved by the system to help with debugging.
0x00000000     Returned by keyword "new" if memory allocation failed
0xCDCDCDCD Allocated in heap, but not initialized
0xDDDDDDDD Released heap memory.
0xFDFDFDFD "NoMansLand" fences automatically placed at boundary of heap memory. Should never be overwritten. If you do overwrite one, you're probably walking off the end of an array.
0xCCCCCCCC Allocated on stack, but not initialized
But like a few others have pointed out, there is a distinction between physical memory addresses which is what the OS uses, and logical memory addresses which are assigned to your application by the OS. Example image shown here.
Comment: `new` throws an exception if allocation failed.
Comment: sorry I was thinking malloc not new.
Comment: @Porkbutts And `malloc` returns a null pointer, which isn't necessarily `0x00000000`.  All of the others are very system specific; on most systems, at least when optimization is active, uninitialized memory can be anything, and released heap memory retains its last values.

Is memory address 0x0 usable?


Problems with fast reading a binary file with numbers c++

Question: i know these topic exist very often. But i cant explain my self the slow results i have.
My Task: read from a file 2.2M Points per sec (better more) and show them in a 3d OpenCv Window.
I try to read on different ways:

Cartesian coordinated system (x,y,z) all __int16 650.000 Points per second
spherical coordinates system (phi, theta, distance) all __int16 560.000  Points per second
spherical coordinates system (distance) __int16 1.384.000  Points per second and calculate phi and theta from sequence (this is maybe possible in far future, but now i havent points with equal angle distance)

I have an SSD and run in release mode.
So i thought it cant be a bottle neck problem.
it is a binary file and i use float. System is 32bit and i will get 2Byte values.
what is my mistake? pls give me an advice.
My code for reading  spherical coordinates system (phi, theta, distance)
Global
 Point *pvertex=nullptr;
 pvertex=new Point[pointsToShow];

readPoints()
RealTime=clock();
std::ifstream FFile;
FFile.open ("read.txt",std::ifstream::in|std::ifstream::binary);

while (FFile!=NULL)
{
    FFile.read((char *)&fphi,sizeof(float));
    FFile.read((char *)&ftheta,sizeof(float));
    FFile.read((char *)&fdistance,sizeof(float));

    pvertex[position].x = fdistance* sin(ftheta)*cos(fphi);
    pvertex[position].z = fdistance* sin(ftheta)*sin(fphi);
    pvertex[position].y = fdistance* cos(ftheta);
    position++;
}

clock_t ende=clock();
if(ende-RealTime>0)
    printf("%lld\n", (long long)(ende-RealTime+(pointsToShow/(ende-RealTime))*1000));

Comment: ***System::Console::WriteLine*** That is should be `c++-cli` although the reading code is `c++`. I would remove the `opengl` tag since this has little to do with that.
Comment: ***what is my mistake?*** Maybe you should tell us. It's unclear what problem you are experiencing. Is the reading of the file too slow? Or is the data corrupted? ***i will get 2Byte values*** floats are not 2 bytes. Not sure if you thought that.
Comment: Have you tried reading more data at once ? I would assume the overhead of calling read multiple times might slow things down.
Comment: ***pls give me an advice.*** If performance is your problem my advice is to benchmark. Does your reading code read fast enough without the drawing to the screen. If not maybe you need to read more values at a time. You may want to also try the file reading in native `c++` to see if that helps any.
Comment: Since this is fundamentally a C++ question, I re-wrote the `Console::WriteLine` to a `printf`, and switched back to the C++ tag.
Comment: Thx for correct the tags. It reads to slow. 2.2mP are round 25MB. Reading vom SSD should be faster. It isnt faster without drawing. Ok i will try reading more values on one time.
Comment: now i read all points at once and use memcpy. Now i can read 7MP per second. Thats enough. Thx for help
Answer: Instead of using read() and fstream, you could create a memory mapping over the file (mmap on Linux, CreateFileMapping on Windows).
This way you can access the data as if it were in memory (directly from the OS disk cache), instead of reading and copying smaller blocks to a user mode buffer.


Impossible Kinds Of Differential Equations

Question: Today my professor told me that there are some differential equations that cannot be solved. Is this true? If it is true, why can they not be solved? How complex would that kind of differential equation have to be?
Comment: Perhaps a more interesting version of this question would ask how we can prove that some some differential equations cannot be solved analytically. I have wondered that myself.
Comment: 99% of equations can't be solved analytically.
Comment: oh ok. Can you give me an example?
Comment: Yes. I should have phrased my question that way. I hear that it is impossible, but I'd like to see more information behind it.
Comment: Why don't you ask your professor?
Comment: If you are interested in integrals that are not analytically solvable: https://math.stackexchange.com/questions/265780/how-to-determine-with-certainty-that-a-function-has-no-elementary-antiderivative/265884#265884
Comment: @AB408 Complete Navier-Stockes equations.
Answer: Ordinary Differential Equations generally admit solutions in the event that the defining functions are "reasonable", i.e. possessed of Lipschitz continuity.  Differentiable functions are generally locally Lipschitz, so we know that equations of the form
$\dot {\vec x} = \vec f(\vec x, t) \tag{1}$
where $\vec x \in \Bbb R^n$, with differentiable $\vec f$, have unique solutions when the initial data
$\vec x(t_0) = \vec x_0 \tag{2}$
is specified.  Most equations of practical interest, say in the sciences or engineering, fall into this category so there's really no problem in the applications.
Partial Differential Equations, on the other hand, yield us no such good fortune.  There are even very simple, first order PDEs which admit no solutions whatsoever.  See, for instance, Lewy's example.  Lewy showed that even such a simple PDE as
$\dfrac{\partial u}{\partial \bar z} - iz \dfrac{\partial u}{\partial t} = \phi'(t) \tag{3}$
admits no local solutions near $0$ on $\Bbb R \times \Bbb C$ when $\phi$ is not analytic.


How Long Should Data Collection Sets run in Windows Server Performance Montioring

Question: I currently have an application server and a database server both running on Windows Server 2008 R2. I have been tasked with generating a weekly report on the utilization of CPU, Memory and Disk. I am planning on using the default Performance Monitoring Data Collection Set Template in Windows Performance Monitor and was wondering what are the best practices for scheduling the job to run? My preference would be for the data collection set to start at the beginning of each week and stop at the end. Would this be overkill? Also, would performance monitoring drag down system performance?
The use of our application will most likely be very irregular. A number of batch jobs run at night and users are likely to access the system when they arrive at work in the morning, so I am worried that a smaller sampling window would miss the true system utilization.
Also, I found some basic tutorials for setting up data collection, but had trouble finding more general info on best practices for weekly performance management using Windows Performance Monitoring. If anyone has a good source please share.
Answer: Where are you logging to? An SQL Database? CSV File?
If it's going to an SQL Database, I used to just create a single job and let it log all day long, forever. Then you query the SQL server to get the data for the range that you're after. You can do this in Excel, or whatever other report builder you have.
I say "used to" because a few years ago I did away with the de-centralised Performance Logging and installed a central Zabbix installation that keeps and tracks all this information forever, providing trends and granular reporting.
In terms of load, I never saw any noticable performance penalty by running the performance logging. Given the number of times each server gets polled by Zabbix each minute to collect all the datapoints, it's really a trivial operation.


Flicker does not reduce after double buffering in MFC CPaintDC

Question: I am trying to make an interactive graph using MFC where the y axis of a sample point in the graph can be changed using mouse click. I implemented double buffering using this tutorial
enter link description here. I should also point out that I need to change the origins of the viewport from time to time for my program. However, when I click on the graph for the sample point to be updated, I can still see it flicker. It's not an inconvenience, but I need to extend this graph to include lots of sample points and other features such as gridlines, axes, labels, boundary areas, etc and I am worried that the flickering might become a problem for me in the future as the size of this project grows. Implementing double buffering did not seem to make any changes to the output. Moreover, now that I have implemented double buffering, the program seems to stop in the middle of execution (when I am running it in Debug mode in Visual Studio) with this error:
Unhandled exception at 0xffffff3a in graph_on_dlgbox.exe: 0xC0000005: Access violation reading location 0xffffff3a.

I am still not sure what causes it to appear, but seems to happen if I start randomly clicking around the graph area rapidly. Since I have not seen this error (yet) in my code that does not use double buffering, I am assuming it has something to do with the double buffering code, but I am not sure.
Anyway I would like to tackle this one problem at a time, and the first problem is the flicker. Here is my code without double buffering:
void Cgraph_on_dlgboxDlg::OnPaint()
{
    CPaintDC dc(this);
    if (IsIconic())
    {
        // CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialogEx::OnPaint();
    }

    CPen pen;
    COLORREF pencolour = RGB(0, 0, 0);
    COLORREF brushcolour = RGB(0, 0, 255);
    COLORREF graphColour = RGB(0, 0, 150);

    // Draw boarder
    pen.CreatePen(PS_SOLID, 3, pencolour);
    // CBrush brush(HS_CROSS, brushcolour);
    dc.SetBkMode(TRANSPARENT);
    dc.SetMapMode(MM_TEXT);
    dc.SetViewportOrg(theGraph.x1, theGraph.y1);
    // Dc.SetViewportExt(theGraph.width, theGraph.height);
     dc.SelectObject(&pen);
    // dc.SelectObject(&brush);

    // Draw graph boundary
    CPoint point1(0,0);
    point1.x = 0;
    point1.y = 0;
    CPoint point2(0,0);
    point2.x = point1.x + theGraph.width;
    point2.y = point1.y + theGraph.height;
    dc.Rectangle(CRect(point1, point2));
    pen.DeleteObject();

    // Draw Horizontal at 0
    pen.CreatePen(PS_SOLID, 1, pencolour);
    dc.SelectObject(&pen);
    dc.MoveTo(0, theGraph.height - ORG_DIST_FROM_BOTTOM);
    dc.LineTo(theGraph.width, theGraph.height - ORG_DIST_FROM_BOTTOM);
    pen.DeleteObject();

    // Shift overall graph origin from top left corner to beginning of this horizontal line
    dc.SetViewportOrg(theGraph.x1, theGraph.y1 + theGraph.height - ORG_DIST_FROM_BOTTOM); // dc.SetViewportOrg() always works relative to the clinet origin

    // Draw graph line
    pen.CreatePen(PS_SOLID, 2, graphColour);
    dc.SelectObject(&pen);
    for(int i = 0; i<NUM_OF_SECTIONS_IN_GRAPH; i++){
        dc.MoveTo(graphSamplePoints[i].x, graphSamplePoints[i].y);
        dc.LineTo(graphSamplePoints[i+1].x, graphSamplePoints[i+1].y);
    }

    // draw circles at graph sample points
    for(int i = 0; i<NUM_OF_POINTS_IN_GRAPH; i++){
        CIRCLE(dc, graphSamplePoints[i].x, graphSamplePoints[i].y, GRP_SMP_RAD);
    }
}

and here is the modified version with double buffering:
void Cgraph_on_dlgboxDlg::OnPaint()
{

    // /*****
    CPaintDC dc_blt(this);
    CDC dc;
    CBitmap bmpDC;
    // CRect rcClient;
    // GetClientRect(rcClient);

    if (IsIconic())
    {
        // CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialogEx::OnPaint();
    }

    dc.CreateCompatibleDC(&dc_blt);
    // bmpDC.CreateCompatibleBitmap(&dc_blt, rcClient.Width(),rcClient.Height());
    bmpDC.CreateCompatibleBitmap(&dc_blt, theGraph.width,theGraph.height );
    dc.SelectObject(&bmpDC);

    // ----------- After this point, do all operations considering (0,0) to be the origin of the bitmap
    // consider bitmap coordinates a device coordinates for Viewport operations

    CPen pen;
    COLORREF pencolour = RGB(0, 0, 0);
    COLORREF brushcolour = RGB(0, 0, 255);
    COLORREF graphColour = RGB(0, 0, 150);

    // Draw boarder
    pen.CreatePen(PS_SOLID, 3, pencolour);
    // CBrush brush(HS_CROSS, brushcolour);
    dc.SetBkMode(TRANSPARENT);
    dc.SetMapMode(MM_TEXT);
    // dc.SetViewportOrg(theGraph.x1, theGraph.y1);
    // dc.SetViewportExt(theGraph.width, theGraph.height);
     dc.SelectObject(&pen);
    // dc.SelectObject(&brush);

    // Draw graph boundary
    CPoint point1(0,0);
    point1.x = 0;
    point1.y = 0;
    CPoint point2(0,0);
    point2.x = point1.x + theGraph.width;
    point2.y = point1.y + theGraph.height;
    dc.Rectangle(CRect(point1, point2));
    pen.DeleteObject();

    // Draw Horizontal at 0
    pen.CreatePen(PS_SOLID, 1, pencolour);
    dc.SelectObject(&pen);
    dc.MoveTo(0, theGraph.height - ORG_DIST_FROM_BOTTOM);
    dc.LineTo(theGraph.width, theGraph.height - ORG_DIST_FROM_BOTTOM);
    pen.DeleteObject();

    // Shift overall graph origin from top left corner to beginning of this horizontal line
    // dc.SetViewportOrg(theGraph.x1, theGraph.y1 + theGraph.height - ORG_DIST_FROM_BOTTOM); // dc.SetViewportOrg() always works relative to the client area origin
    // New origin defined in terms of the Bitmap's origin
    dc.SetViewportOrg(0, theGraph.height - ORG_DIST_FROM_BOTTOM);

    // Draw graph line
    pen.CreatePen(PS_SOLID, 2, graphColour);
    dc.SelectObject(&pen);
    for(int i = 0; i<NUM_OF_SECTIONS_IN_GRAPH; i++){
        dc.MoveTo(graphSamplePoints[i].x, graphSamplePoints[i].y);
        dc.LineTo(graphSamplePoints[i+1].x, graphSamplePoints[i+1].y);
    }

    // draw circles at graph sample points
    for(int i = 0; i<NUM_OF_POINTS_IN_GRAPH; i++){
        CIRCLE(dc, graphSamplePoints[i].x, graphSamplePoints[i].y, GRP_SMP_RAD);
    }

    dc.SetViewportOrg(0, 0);
    // dc_blt.BitBlt(rcClient.left+100,rcClient.top+50,rcClient.Width(), rcClient.Height(), &dc, 0, 0, SRCCOPY);
    // dc_blt.BitBlt(0,0,rcClient.Width(), rcClient.Height(), &dc, theGraph.x1, theGraph.y1, SRCCOPY);

    dc_blt.BitBlt(theGraph.x1,theGraph.y1, theGraph.width, theGraph.height, &dc, 0, 0, SRCCOPY);
    // --- Bring the bitmap to this particular location on screen specified by (theGraph.x1,theGraph.y1, theGraph.width, theGraph.height)

    // dc_blt.BitBlt(0,0,theGraph.width, theGraph.height, &dc, 0, 0, SRCCOPY);
    // dc_blt.BitBlt(theGraph.x1,theGraph.y1,theGraph.width, theGraph.height, &dc, 0, 0, SRCCOPY);
    // *****/

     m_bMyDraw = FALSE;
}

Here is a sample screenshot of the output:

The y axis values of the sample points on the graph can be changed by clicking, and the program redraws the graph after every click by calling InvalidateRect() with the area of the graph as the rectangle to be repainted.

The coordinates of the sample points are stored in a array of CPoint objects, and it's members are updated every time the graph is clicked at the appropriate area. The graph then repaints, due to the call to InvalidateRect(), but with a flicker; unless of course, the program crashes in debug mode with this error:

How do I remove the flickering?
---- UPDATE ----
BOOL Cgraph_on_dlgboxDlg::OnEraseBkgnd(CDC* pDC)
{
    // TODO: Add your message handler code here and/or call default
    if ( m_bMyDraw )
        return TRUE;
    else
        return CDialogEx::OnEraseBkgnd(pDC);
}

This function has been made this way since it was done like this in the tutorial I mentioned earlier
------ UPDATE 2 ----------
If I just put return TRUE; in the body of the above function, the flicker seems to vanish, but now the output looks like this

The dialog box background seems to have taken the contents of my Visual Studio window. How do I prevent this?
Answer: You're close!  The idea of double buffering is to paint every pixel in your window exactly once.  If it is painted zero times, artifacts like Visual Studio remain.  And if it is painted a first time, and then painted again with a different color, you will see flicker.  So, to make sure every pixel is painted, create your compatible dc the full width and height of the window so that when it is copied to the CPaintDC, it covers the entire area and not just theGraph. Keep returning TRUE in OnEraseBkgnd, so that the pixels are not first painted in OnEraseBkgnd, and then again in OnPaint.
Answer: Two things :

Have you made sure OnEraseBkgnd() just returns TRUE and doesn't call the base class to erase the view?
You don't need to do all that drawing for the double buffering in OnPaint(). All you need to do in the OnPaint() is the BitBlt. You can do the drawing to the memory bitmap in a UpdateRect() function which gets called whenever you need to update the screen, which then calls InvalidateRect() to update the screen. I've posted some code about a flicker-free double buffering method I've used many times here which might help.
Comment: Just seen your second update. The reason you're seeing your VS contents is because you're not drawing the whole window in OnPaint(). You need to create a background bitmap that's the size of the whole client area and fill it with a colour (or whatever), even though you're only interested in your graph area.
Comment: I have included my OnEraseBkgnd() in my question. Did you mean that it's function body should just have return TRUE;?
Comment: I am sorry but I did not understand the part about drawing to the memory bitmap in a UpdateRect() function. What is the UpdateRect()? Isn't OnPaint() the function that gets called automatically whenever I need to update the screen? I am drawing this on a non-resizable dialog box so I just need to worry about the cases of other overlapping windows and the parent dialog box being minimized.
Comment: Also, please let me know if I am wrong, but putting all those code for drawing in OnPaint() should not be a cause for flicker should it? Because they are still only drawing into the memDC and not the screen
Comment: Also, just fr reference, I have called `InvalidateRect()` inside the 'OnLButtonDown()' of the dialog box
Comment: Yes, just return TRUE in OnEraseBkgnd(). Don't call the base class. If you're calling the base class, this is probably the cause of your flicker.
Answer: The way that flicker prevention work is that first you return TRUE from OnEraseBkgnd to suppress the default erase. But then your OnPaint code must include a full erase of the window. You don't do that so you get the background image of your source code or whatever was there before. So add a FillSolidRect call to your OnPaint to clear the window.
Your creation of a CPaintDC before calling CDialogEx::OnPaint destroys the dialog's ability to properly paint itself, since that function also creates a CPaintDC. But only one call to CPaintDC is permitted for each paint message. To avoid this problem you need a completely different approach. The dialog should have a picture control on it (a CStatic), and you should paint your graph in a class you derive from CStatic.
Comment: Or don't use a `CPaintDC` but a regular `CDC` instead.
Comment: @NikBougalis : did you mean I need to have two CDC's in the above code? The CPaintDC above is only used to BitBlt the bitmap onto the dialog box window, while I am drawing in the CDC (at least that's what I thought I had been doing)            Scott: I had already tried painting into a class derived from a CStatic control but I ran in to other problems so I am using this approach now. Do you think deriving from a CStatic and painting on it is the only way to remove flickering, or is there any way I can make this current approach work as well?


framer.motion animation is instant instead of animating

Question: I have several boxes that I want to animate through,
Here's a simple app example (Also a codesandbox here)
Each "box" should fade in and fade out, however, in this example, the animation happens isntantly.
const Box = styled.div`
  width: 100px;
  height: 100px;
  background: green;
`;

const Test = ({ isActive }) => {
  return (
    <motion.div
      animate={isActive ? { opacity: 1 } : { opacity: 0 }}
      transition={{ duration: 3 }}
    >
      <Box>hello world</Box>
    </motion.div>
  );
};

export default function App() {
  const [currentIndex, setCurrentIndex] = useState(0);

  const boxes = [
    {
      component: ({ isActive }) => <Test isActive={isActive} />
    },
    {
      component: ({ isActive }) => <Test isActive={isActive} />
    }
  ];

  return (

Hello CodeSandbox

Start editing to see some magic happen!

 setCurrentIndex(currentIndex === 0 ? 1 : 0)}>
        {boxes.map((box, index) => {
          const isActive = index === currentIndex;
          return <box.component isActive={isActive} />;
        })}

  );

Comment: in the codesandbox example, the animation is fading out. Perhaps I am misunderstanding your question. Whenever the user clicks the parent div, the currentIndex switches and one of the boxes slowly fades out. What is your intended effect? The boxes do not 'fade in', is that what you would like to happen?
Comment: @TomBonynge yeah I would expect them to fade in AND fade out
Answer: I have never used framer.motion before, but looking at their documentation, I think you can use variants, to achieve what you need. https://www.framer.com/api/motion/examples/
I've slightly refactored your code, to get it working:
import "./styles.css";
import { motion } from "framer-motion";
import styled from "styled-components";
import { useEffect, useState } from "react";

const Box = styled.div`
  width: 100px;
  height: 100px;
  background: green;
`;

const variants = {
  open: { opacity: 1 },
  closed: { opacity: 0 }
};

const Test = ({ index, currentIndex }) => {
  return (
    <motion.div
      animate={index === currentIndex ? "open" : "closed"}
      variants={variants}
      transition={{ duration: 3 }}
    >
      <Box>hello world</Box>
    </motion.div>
  );
};

export default function App() {
  const [currentIndex, setCurrentIndex] = useState(0);
  const boxes = ["a", "b"];

  return (

Hello CodeSandbox

{currentIndex}

 setCurrentIndex(currentIndex === 0 ? 1 : 0)}>
        {boxes.map((box, i) => {
          return <Test index={i} currentIndex={currentIndex} />;
        })}

  );
}

the currentIndex is passed as props to the child Test components, they check themselves whether their index matches the currentIndex and update their animations accordingly.
Edited codesandbox here: https://codesandbox.io/s/suspicious-austin-tymvx
Comment: Ah thanks for your input Tom, it was actually an issue with delcaring the array of components inside the function, once I delcared the array outside of the component they wouldn't re-render on every state update, see here https://codesandbox.io/s/crazy-mendel-b36jw?file=/src/App.js
Comment: To take this even further, I needed to pass in the components certain props from the parent, so I needed them in the body of the functional component. But to avoid re-rendering, I wrapped the boxes in `useMemo`.
Answer: In framer motion, you have useCycle properties. Here is an example.
Code in example:
import * as React from "react";
import { render } from "react-dom";
import { Frame, useCycle } from "framer";
import "./styles.css";

export function MyComponent() {
  const [animate, cycle] = useCycle(
    { scale: 1.5, rotate: 0, opacity: 1 },
    { scale: 1.0, rotate: 90, opacity: 0 }
  );
  return (
    <Frame
      animate={animate}
      onTap={() => cycle()}
      size={150}
      radius={30}
      background={"#fff"}
    />
  );
}

const rootElement = document.getElementById("root");
render(<MyComponent />, rootElement);

and some simple css:
body {
  margin: 0;
  padding: 0;
}

#root {
  font-family: sans-serif;
  text-align: center;
  width: 100vw;
  height: 100vh;
  display: flex;
  place-content: center;
  place-items: center;
  background: rgba(0, 85, 255, 1);
  margin: 0;
  padding: 0;
  perspective: 1000px;
}

I don't recommend you to use this type of construction:  animate={index === currentIndex ? "open" : "closed"} , because you might have some lagging/breaking animation.
Try always to search examples/elements of MotionAPI lib. You will have less code lines and mostly "clean" code with no useless variables.


How to interpret ACF and PCAF graph

Question:
I want to predict the future data given the time series data with SARIMA model.
In order to determine (p, d, q) and (P, D, Q, m), I plotted the ACF and PACF.
The ACF graph shows that there is a seasonality of 24 intervals, so I set the m as 24.
However, I don't know how to set, p, d, q, and P, D, Q.
In other example, ACF graph usually degrades exponentialy, so they set p and q as 1 or 2.
But my ACF graph has cycles, so I am confused about how to set p and q.
Could you help me?
Comment: You rather obviously have seasonality of cycle length about 24, so I assume your data are hourly with day-over-day seasonality. Is there any particular reason [why you want to build an ARIMA model yourself based on ACF/PACF, rather than use an automated ARIMA modeler](https://stats.stackexchange.com/q/595150/1352)?
Comment: You're right. It is the data that recorded the demand value on an hourly basis for two years. The reason is that I just want to know the parameter selection criteria. I want to answer a question later in a job interview where the interviewer might ask me why I chose the parameters like this.
Answer: Your data show obvious seasonality of cycle length about 24. Since you note these are hourly data, this makes sense. So your first order of business should be to take seasonal differences, then plot the differenced data again and continue from there. Note that this seasonal cycle length needs to be provided based on domain knowledge.
A description of the Box-Jenkins approach to model building is given in Shumway & Stoffer (2016), Time Series Analysis and Its Applications With R Examples, Fourth Edition, section 3.7. I personally find this description singularly unhelpful and would always recommend using an automated ARIMA modeler based on information criteria.
Note also that hourly data may have multiple-seasonalities, specifically day-over-day and week-over-week. ARIMA can't handle this. The tag wiki contains pointers to relevant algorithms and literature.

A word on the wider context. If you are asked this kind of question in a job interview, there are two possibilities.

Either the job truly involves using the older Box-Jenkins approach to ARIMA model building. For instance, it might be an academic position on ARIMA time series modeling research, or it might be on software development where the decision was made to go with Box-Jenkins for whatever reason (perhaps this is very old legacy code). If so, and if you have to ask about this here, then you are possibly in over your head and should reconsider whether this job is a good fit, unless you are willing and prepared to learn a lot (and your employer is fine with this).

Or it is on modeling and possibly forecasting as such, but agnostic about the approach. In this case, you should display some knowledge about ARIMA models (like understanding that the cyclic patterns in your ACF plot indicate seasonality), but then explain that an automated ARIMA modeler using information criteria will yield better results, be more scalable and stable and require less subjective decisions. If your interviewer accepts this, that is good. If not, this is not a good sign. Take this as an opportunity to learn about your potential employer.
Comment: Thank you very much! I'm just looking for a job related with the modeling, so my job is unlikely to be related to the older approach of ARIMA model bulding. So as you say, it seems good to answer in the interview that I found the parameters using automated ARIMA modelder based on information criteria.
Comment: You may find this helpful: https://otexts.com/fpp3/. Good luck!

How to interpret ACF and PCAF graph


If $f$ is differentiable and $f'$ is continuous on the same domain, show that for any closed subinterval, $f$ is uniformly differentiable.

Question: Here is the problem more explicitly:

Let $f:(a,b)\to \mathbb{R}$ be differentiable and $f'(a,b)\to \mathbb{R}$ be continuous. Prove that on any closed subinterval $[c,d]\subset (a,b)$, the function is \textit{uniformly differentiable}, in the sense that given any $\epsilon > 0$, there exists a $\delta$ such that
  $$|f(y) - f(x) - f'(x)(y-x)| < \epsilon$$
  for any  $x,y\in [c,d]$ such that $|y-x| < \delta$.

I know that if $f$ is differentiable, then it is continuous. Also, the sum or product of continuous functions results in a continuous function. So I was thinking of combining them together into one function $h:[c,d]\to \mathbb{R}$:
$$h(x) = f(x) + (x-y)f'(x),\ \ x,y\in [c,d]$$
$h$ is continuous, so for any $\epsilon > 0$, $\exists \delta > 0$ such that
$$|x-y| < \delta \Rightarrow |f(x) - f(y) + (x-y)f'(x) - (x-y)f'(y)| < \epsilon$$
If I could get rid of that $f'(y)$ term with a triangle inequality, this might work, but I can't seem to squeeze anything useful out. Perhaps due to looking at it too long or overthinking it.
Does this seem like a legitimate way to do the proof?
Answer: Firstly, $f:[c,d]\to \mathbb{R}$ is a continuous function on a closed and bounded (ie compact) set, so it is uniformly continuous on this set. Similarly, $f':[c,d]\to \mathbb{R}$ is a continuous function on a closed and bounded set, so it is bounded. Say $|f'(x)|\leq M$ for all $x\in [c,d]$. Let $\epsilon>0$ and let $\delta>0$ be such that whenever $|x-y|<\delta$ (with $x,y\in [c,d]$), then $|f(x)-f(y)|<\epsilon/2$. Without loss of generality, we can require $\delta\leq \epsilon/2M$. Then whenever $x,y\in [c,d]$ with $|x-y|<\delta$, we have
$$
|f(x)-f(y)-f'(x)(y-x)|\leq |f(x)-f(y)|+|f'(x)||y-x|<\epsilon/2+M\delta\leq \epsilon/2+\epsilon/2=\epsilon.
$$
Comment: The problem with your solution lies in your definition of $h$. You could try letting $h_x(y)=f(y)-f'(x)y$ (for some fixed $x$). The problem here is that you need to have this work for each $h_x$ simultaneously. So you have to use the fact that things are uniformly continuous anyway...at that point, you might as well not bother with $h$ and just prove it directly
Comment: I like this solution, but what critique would you give my approach?
Answer: Note that $f'$ is uniformly continuous on $[c,d]$, then given $\epsilon>0$, for some $\delta>0$ we have $u,v\in[c,d]$ and $|u-v|<\delta$ that $|f'(u)-f'(v)|<\epsilon$.
Now
\begin{align*}
|f(y)-f(x)-f'(x)(y-x)|&=|f'(\xi_{x,y})-f'(x)|\cdot|y-x|\\
&<\epsilon\cdot(d-c)
\end{align*}
since $|\xi_{x,y}-x|\leq|x-y|<\delta$, where $\xi_{x,y}$ is taken by Mean Value Theorem.


aws-cdk: I cannot add access permission to existing SQS

Question: I have a code where I need to grant send messages to an existing sqs queue.
I have this code in the aws-cdk. But this is not working. No access permission get added.
const sqsQ = sqs.Queue.fromQueueArn(this, "some-id", "arn:aws:sqs:us-east-2:SOME-ACCOUNT:QUEUE-NAME");
sqsQ.grantSendMessages(new iam.ServicePrincipal("events.amazonaws.com"));

Answer: I don't think it's possible to grant permissions to an existing resource in CDK. Anytime you import a resource into your stack using something like fromQueueArn you can think of this as a read-only reference to the resource.
In other words, you can only update resources which are managed by your CDK code.
You have basically 2 options here:

Move the original SQS into your CDK managed stack. You can do this using CloudFormation resource import feature (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resource-import.html)
Modify SQS permissions outside CDK in the place where it was originally defined.
Comment: If you're referring to `bucket.grantReadWrite(user)`, then the explanation for why that works is that this operation actually modified user, not the bucket, i.e. it's not modifying bucket resource. It's modifying IAM resource.
Comment: Are buckets special? This documentation is what made me think you can do that.
Look at https://docs.aws.amazon.com/cdk/api/latest/docs/aws-s3-readme.html#importing-existing-buckets
Comment: Is this still true?
Answer: Try something like this instead
    sqsQ.addToResourcePolicy(
      new PolicyStatement({
        effect: Effect.ALLOW,
        principals: [new ServicePrincipal(ServicePrincipals.EVENTS)],
        actions: ["sqs:SendMessage"],
        resources: [sqsQ.queueArn],
        conditions: {
          ArnEquals: {
            "aws:SourceArn": <ruleArn or whatever needs permissions here>,
          },
        },
      })
    );

Comment: When you say it did not work how are you checking, are you looking at the permissions on the AWS console and seeing nothing has been added?
Comment: @AnonymousAlias, Yes. Also CDK stack does not show that as a resource change that is going to added
Comment: Ahh hadn't copped you were dealing with an import, this makes sense.


Mongoid::Errors::DocumentNotFound raise_not_found_error

Question: * updated at the bottom *
When looking for user that doesnt exist, I am getting:

Mongoid::Errors::DocumentNotFound in UsersController#show
Problem:
  Document(s) not found for class User with id(s) 22. Summary: When
  calling User.find with an id or array of ids, each parameter must
  match a document in the database or this error will be raised. The
  search was for the id(s): 22 ... (1 total) and the following ids were
  not found: 22. Resolution: Search for an id that is in the database or
  set the Mongoid.raise_not_found_error configuration option to false,
  which will cause a nil to be returned instead of raising this error
  when searching for a single id, or only the matched documents when
  searching for multiples.

However I am setting raise_not_found_error to false
mongoid.yml
development:
  adapter: 'mongoid'
  # Configure available database sessions. (required)
  sessions:
    # Defines the default session. (required)
    default:
      # Defines the name of the default database that Mongoid can connect to.
      # (required).
      database: blog_development
      # Provides the hosts the default session can connect to. Must be an array
      # of host:port pairs. (required)
      hosts:
        - localhost:27017
      options:
          allow_dynamic_fields: false
          identity_map_enabled: true
          include_root_in_json: true
          include_type_for_serialization: true
          # Note this can also be true if you want to preload everything, but this is
          # almost never necessary. Most of the time set this to false.
          preload_models:
            - Canvas
            - Browser
            - Firefox
          scope_overwrite_exception: true
          raise_not_found_error: false
          skip_version_check: false
          use_activesupport_time_zone: false
          use_utc: true
  # Configure Mongoid specific options. (optional)
  options:
    # Enable the identity map, needed for eager loading. (default: false)
    # identity_map_enabled: false

    # Includes the root model name in json serialization. (default: false)
    # include_root_in_json: false

    # Include the _type field in serializaion. (default: false)
    # include_type_for_serialization: false

    # Preload all models in development, needed when models use
    # inheritance. (default: false)
    # preload_models: false

    # Protect id and type from mass assignment. (default: true)
    # protect_sensitive_fields: true

    # Raise an error when performing a #find and the document is not found.
    # (default: true)
    raise_not_found_error: false

    # Raise an error when defining a scope with the same name as an
    # existing method. (default: false)
    scope_overwrite_exception: false

    # Skip the database version check, used when connecting to a db without
    # admin access. (default: false)
    # skip_version_check: false

    # Use Active Support's time zone in conversions. (default: true)
    # use_activesupport_time_zone: true

    # Ensure all times are UTC in the app side. (default: false)
    # use_utc: false
test:
  sessions:
    default:
      database: blog_test
      hosts:
        - localhost:27017
      options:
        consistency: :strong
        # In the test environment we lower the retries and retry interval to
        # low amounts for fast failures.
        max_retries: 1
        retry_interval: 0

Controller
  # GET /users/1
  # GET /users/1.json
  def show

    @user = User.find(params[:id])

    render json: @user
  end

* UPDATE **
fixed a null response (not in a json format) going out by doing this:
  def show

    @user = User.find(params[:id])
    if @user.nil?
      @user = []
    end

    render json: @user
  end

Comment: i have edited my answer, it has good chances to be the solution i hope =)
Comment: You could also do `@user = User.find(params[:id]) || []` directly
Answer: your structure of yml is wrong
has to be -
development:
  sessions:
    options:
      #raise_not_found_error has to be not here but see below
  options: #strictly 2 spaces before
    raise_not_found_error: false #strictly 4 spaces before not 6

so, raise_not_found_error parameter has to be child of development>options, not development>sessions>options
Comment: Thanks this helped me get to where I need to be on the config level. However now its returning null, and not in a JSON format.
Comment: how about `respond_to { |format| format.json {render :json => @user} }` ?
Comment: gives me:
ActionController::UnknownFormat in UsersController#show
I'm using rails-api
Comment: it has to render correct json if everything else behind the scene is correct http://stackoverflow.com/questions/4253238/ruby-array-to-json-and-rails-json-rendering
Comment: if you scroll down, you will see that he set the option correctly, your answer doesn't add any value to the poster's question.
Comment: @Pencilcheck, if you try to look to http://stackoverflow.com/posts/18638745/revisions - it was added to question after my answer, so you have to be more attentive before claim people. cheers
Answer: For me even correct indenting didn't work, what did is to create an initializer file called mongoid.rb in config/initializers/ and put this into it
Mongoid.raise_not_found_error = false

Answer: To save someone few minutes, if you are still having a problem and you are sure your mongoid.yml configs are correct, try to stop spring server as it seems to do a lot of caching!
$ spring stop


Why does `systemctl start myservice` not fork this service?

Question: I have written a systemd service.
When I run systemctl start foo.service, the service starts and runs correctly, but systemctl does not return immediately to the shell.
After a while it exits with
Job for foo.service failed because a timeout was exceeded.

and then the service is no longer running.
Here is foo.service, I RTFM and used Type=forking with a command which forks:
[Unit]
Description=blah blah

[Service]
Type=forking
PIDFile=/var/run/myservice.pid
ExecStart=/my/path/fork my-script my-args

[Install]
WantedBy=multi-user.target

my-script does not itself fork, so /my/path/fork is as follows
#!/bin/bash
PATH="$PATH:/my/path" "$@" &

Why does this service not fork and run in the background as expected? I have done everything as root on CentOS.
Comment: Why are you trying to do this? If the service doesn't fork, you can just use `Type=simple` and get on with your life. No goofy shell scripts needed.
Comment: @MichaelHampton I tried Type=simple, the `systemctl start foo` command doesn't return me to the shell.
Comment: That sounds quite strange. What is `foo`, then?
Comment: It's the placeholder for `actual-name-of-my-service`
Comment: Yes, I figured that out already. Now, what is it really?
Comment: `skls-unixuser.service` Why do you think this matters?
Answer: Service Type=forking is for truly forking programs (apache for example). Your bash script only run another script on background. This is not exactly what systemd wants as forking program.
Why you using
Type=forking

, when your script my-script is normal simple service?
Try to change service type and run your script directly with this:
[Service]
Type=simple
PIDFile=/var/run/myservice.pid
ExecStart=/my/path/my-script my-args

And remove whole /my/path/fork file. I can't see any profit from it.
Also you can try to set TimeoutStartSec=1 option to service configuration file.
I'm using bash script containing infinite loop with this configuration:
[Service]
User=root
ExecStart=/root/ha.sh
WorkingDirectory=/root/
KillSignal=SIGKILL
Restart=on-abort
Type=simple
TimeoutStartSec=1
TimeoutStopSec=1
StandardError=syslog
NotifyAccess=all


Quadratic equation cancellation error.

Question: $$(x-1)^2 + 2x - 2  = (x+1)(x+2)$$
$$(x-1)^2 + 2(x-1) = (x+1) (x+2)$$
$$(x-1) (x-1+2) = (x+1) (x+2)$$
$$(x-1)\require{cancel}\cancel{(x+1)} = \require{cancel}\cancel{(x+1)}(x+2)$$
$$(x-1) = (x+2)$$
$$x-x = 2+1$$
$$0 = 3$$
But when i do it like this
$$(x-1)^2 + 2x - 2  = (x+1) (x+2)$$
$$x^2 - 2x + 1 + 2x -2 = x^2 + 2x + x +2$$
$$x^2 - 1 = x^2 + 3x +2$$
$$-1 -2 = 3x$$
$$-3 = 3x$$
$$-1 = x$$
So in the first solution is my simplifying is wrong?
Comment: You divided by $x-1$, which is a division by a zero in case $x=-1$. You need to check that case before dividing.
Comment: You might like to format this rather better - at least put (double) line breaks in between different statements so we can see what the equations are, and which terms belong to which equation. At the moment it is a complete guess what this all means.
Answer: In the first set of equations, where you reached a contradiction, you divided both sides of the equation by $x+1$, but you can't divide by zero.
So you should have said at that point, either $x=-1$ or I can divide ... and since dividing gives a contradiction, I must have $x=-1$.
Then the two methods become consistent.
Comment: @VedranŠego I agree it is necessary to take care, but if $x=-1$, both sides of the equation before dividing through are zero, so there is nothing to check. Dividing by zero is the only hazard here.
Comment: You're right, I wasn't paying attention.

Quadratic equation cancellation error.


Python: check if value appears anywhere in a list of dataframes

Question: I have a variable var = myString and a list of dataframes dfList. Each dataframe in the list is two columns of strings df = pd.DataFrame({'col1': ['x','y','z'], 'col2': ['a','myString','b']}). If var appears anywhere in any dataframe in the list I need to execute a series of functions. I could check by looping through each dataframe in the list, but I am hoping for a method of checking that I can easily incorporate into part of a one line elif statement.
Comment: and your Question is?
Comment: Is there a way I can check if var appears in any dataframe in the list of dataframes as part of a one line if statement?
Comment: Does the `var` always occur in `col2`?
Comment: no it could be in either column
Answer: Try this.
import pandas as pd

var = 'myString'

df = pd.DataFrame({'col1': ['x','y','z'], 'col2': ['a','myString','b']})

mystringIN = any((df[a] == var).any() for a in df.columns)

print(mystringIN)

Output
True

Comment: I have a list of dataframes, not just a single one
Answer: Starting with this solution, to find if a value is present in a DataFrame, we can extend it to a list of dataframes as:
True in [df.isin([var]).any().any() for df in dfList]

Which will be True if var is present, False otherwise.
It works whether var is a string or any other type.


Alterar dinamicamente o src de um iFrame

Question: Posso trocar o src de um iframe por um valor qualquer? Isto é possível?
document.getElementById('idIframe').src = "www.google.com"

Comment: Claro que pode. Você tentou?
Comment: Chance url? **src** is img and **href** is location. `document.querySelector('img#idIframe').src = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png"`
Comment: Sim... É normal isso acontecer
Comment: Porque fazer alteração dinamicamente? Qual a vantagem em fazer isso? Se colocar o src diretamente no iframe não vai economizar código?
Answer: Como estás a fazer é correto. Tens de ter em atenção duas coisas:

alguns urls não abrem dentro de iframes por proteção de CORS, que impede assim manipular a página dentro de uma iframe
o src tem de ser um url válido. Ou colocas um url relativo (como no exemplo que dei) ou colocas um endereço completo com http://

Exemplo: https://jsfiddle.net/2a37sbrp/


Gender and Medical Condition - Is a Chi-Square Test of Independence the Correct Test to Use?

Question: Data from our local hospital's Emergency Department suggests that there are certain conditions with which females present more often than males. I wish to determine whether the difference in observations is statistically significant.
The following is the gender breakdown for all Emergency Department patients:
Gender         GenderCount
F              70001
M              55466

Which is about a 5:4 ratio, or 1.26 females for each male.
The following is the gender breakdown for Emergeny Deparment patients who present with the studied condition:
Gender        GenderCount
F              8516
M              3836

Which is about an 11:5 ratio, or 2.22 females for each male.
Is the correct test to use a Chi-Square Test of Independence? My current approach is to view the variables this way:
                       Condition Presented
            Studied Condition   |     Any Other Condition
male    |                       |
--------|-----------------------|---------------------------
female  |                       |

Next, I would like to repeat the process for an arbitrary number of other conditions. Is there a good way to perform the same test on a set of independent categorical variables, at once? For example, could I perform a Chi-Square Test of Independence on the following matrix:
                                                  Condition Presented
            Condition 01       |       Condition 02        |      ...      |       Condition n
male    |                      |                           |               |
--------|----------------------|---------------------------|---------------|--------------------
female  |                      |                           |               |

My data is in a SQL server, and I can use R.
I actually have data for all hospital departments, so should I be starting with that data as population data and treating the Emergency Department set as a sample?
Is a Chi-Square Test of Independence the right approach?
Bonus Question (not required for accepted answer) - If I get a statistically significant result, what measure of association should I use for this kind of data?
Comment: A chisquare test should be OK. If you have other covariables than sex, yuou should try logistic regression.  And, as for Association measure, maybe the odds ratio?
Answer: This Problem (depending on a research task) could be handled by a chi-squared test.
There a 2 ways to use chisq.test() in R:

chisq.test(vector) tests against a uniform distribution (you could for example test if the distribution of studied condition & research condition differ from a uniform distribution)
chisq.test(data.frame(vector1, vector2)) tests if the 2 vectors are from the  same distribution. (you could compare female vs male patients based on their condition)

"Next, I would like to repeat the process for an arbitrary number of
  other conditions. Is there a good way to perform the same test on a
  set of independent categorical variables, at once? For example, could
  I perform a Chi-Square Test of Independence on the following matrix:"

the length of the vector (no of condition) is not limited -> yes

I actually have data for all hospital departments, so should I be
  starting with that data as population data and treating the Emergency
  Department set as a sample?

You can compare the departments but I cannot answer if it is useful to your research.


Move OS files to the begin of the disk

Question: I would like to know if it's possible to move the files on a given partition to the begin of the disk, where the read/writes are faster.
I currently have Windows Vista installed on the first partition of the disk with a few more partitions for work related files and other stuff.
Would this guarantee that the OS partition (which was the first to be created) is located at the begin of the disk?
Would a defrag program help with this or the various partitions limit the location of the files on the disk?
Comment: This question is not programming related. Ask over at http://serverfault.com/
Comment: Two answers so far seem to have missed the point. You're asking whether the first partition (for Vista) physically prevents files on *other* partitions from being moved to the start of the physical disk, right?
Comment: Correct, Rob. Going in more detail, I was planning on installing Windows 7 RC on the available free space (I have 160 GB out of 320GB used so far) and later make it the primary OS, but if it will be installed at the middle or end of the disk there will be some speed penalty compared to the current vista installation. I just want to make sure I can move the most used files to the begin of the disk but since I have several partitions I not sure if that's possible.
Comment: Ahh, okay, I misread the question. Sry
Answer: No, it's not possible. Physical partitions separate a disk into circular regions. The first partition occupies the outer ring of the disk, and the next partition occupies the ring inside that one. You can move files within a partition, but all the files of one partition come before any files of any other partition.
If partitions were wedge-shaped, then what you request would be possible.
Comment: Thanks Rob. I've been reading JDefrag forums and indeed the first partition is created at the start of the disk space, then the second one and so on. So I'll be needing to install the OS on the first partition to take advantage of the faster disk location.
Answer: Ultimate Defrag (sry, no link, just google it up, it's free) has the option to move recent used files to the fastest area of the disk
Greetz,
GHad

Move OS files to the begin of the disk


Uniformizable space implies T3 space

Question: A topological space $(X, \mathscr{T})$ is uniformizable if there exists a uniform structure on $X$ that induces $\mathscr{T}$.
I am trying to prove that every uniformizable space on $X$ is T3. To do this, I have to show that:
For every $p \in X$ and $Q \subseteq X$ such that $Q$ is closed and that $p \not \in Q$, there exist open sets $U, V \subseteq X$ such that $$p \in U \text{ and } Q \subseteq V \text{ and } U \cap V = \varnothing.$$
I'm doing the following: for any $p$ and $Q$ that satisfy the hypothesis, it follows that $Q^c$ (the complement of $Q$) is an open set containing $p$. Therefore, there exists an entourage $E$ in the uniform structure such that $Ep \subseteq Q^c$, where $Ep$ is the set of $E$-left-relatives of point $p$, i.e. $$Ep = \{q \in X \mid (q, p) \in E \}.$$ From here, however, I'm not entirely sure how to find an open superset of $Q$ that is disjoint with $Ep$.
I'm looking for a small hint, perhaps pointing me to the proper axiom to use to construct the applicable open sets. Any help is appreciated.
Answer: To show that a space is a $T_3$ space (regular for those using the other nomenclature), we need to show that the closed neighbourhoods form a neighbourhood basis of each point.
In that form, it is easier to show, I think.
So let $x \in X$, and $W$ an arbitrary entourage. We must show that
$$W(x) = \{ y : (x,y) \in W\}$$
contains a closed neighbourhood of $x$. Let $V$ be a symmetric entourage with $V^3 \subset W$ ...
Comment: Thanks! I think I got it without $V$ having to be symmetric, but I'm checking now.
Comment: Yes, one doesn't need the symmetry here, but then one needs - I think - to use $V^{-1}$ in one place. And $V^2 \subset W$ would be enough too, unless I'm mistaken.
Comment: Yeah, $V^2 \subset W$ is enough. I basically just proved that the closure of $V(x)$ was contained in $W(x)$. Didn't require $V^{-1}$.
Comment: Ah, right, since the closure is the intersection of all uniform neighbourhoods, $V(V(x)) \subset W$ is enough. I thought of the more elementary way of looking at the neighbourhoods of $y \in \overline{V(x)}$.

Uniformizable space implies T3 space


Induction proof - divisibility by 3

Question: We want to show whether or not $2^{2n+1}+1$ Is divisible by 3 using induction.
I tried doing this but I'm stuck with $2^{2n+3} + 1= 2^2 \cdot 2^{2n+1} + 1$. I don't know how to show if this is divisible by 3.
Comment: $2^{2n+3} + 1= 2^2 \cdot 2^{2n+1} + 1 = 3\cdot 2^{2n+1} + 2^{2n+1} + 1$ and you are through.
Answer: For $n=0$ this should be clear. So suppose we know that $2^{2\cdot n + 1}$ is divisible by $3$. Then
\begin{align}
2^{2\cdot (n +1) + 1} &= 2^{2\cdot 1 + 2\cdot n + 1}\\
&= 2^2 \cdot 2^{2\cdot n + 1}
\end{align}
is also divisible by $3$, since the second factor is.

Induction proof - divisibility by 3


Get the last two digits of $16^{100}$ and $17^{100}$

Question: I try to get the last two digits of $16^{100}$ and $17^{100}$
I started with:
$6^{1} = 6$
$6^{2} = 36$
$6^{3} = 216$ means last digit for $6$ is always $6$
That is why the last digit for $16^{100}$ is $6$
And for $17^{100}$ i calculated:
$7^{1} = 7$
$7^{2} = 49$
$7^{3} = 343$
$7^{4} = 2401$
$7^{5} = 16807$
And because $4*25 = 100$ or better said $100mod4 = 0$
The last digit for  $17^{100}$ is $1$
But how do i get the penultimate digits? Thanks
Comment: Im asking about $16$ and $17$! But i thought it would be not important for the last digit if i only take the last digit of the number, thats why $6$ and $7$! Hope you understood me?
Comment: No sorry i would like to know the last two digits! But i tried to show i i got the last digit! DO you have any solution for the last two digits? Thanks
Comment: Brute force method, http://www.alpertron.com.ar/BIGCALC.HTM 17^100 ends in(07), 16^100 ends in(76)
Answer: As $(17,100)=1,$ and using Carmichael function $\displaystyle\lambda(100)=20$
$\displaystyle\implies17^{20}\equiv1\pmod{100}$

$16^{100}=(2^4)^{100}=2^{400}$
As $(2^{400},100)=4=2^2\ne1$  let us find $2^{400-2}\pmod{25}$
As $\displaystyle\lambda(25)=\phi(25)=20, 2^{20}\equiv1\pmod{25}$
and $\displaystyle400-2\equiv18\pmod{20}\implies 2^{400-2}\equiv2^{18}\pmod{25}$
Now, $\displaystyle2^9=512\equiv12\pmod{25}\implies 2^{18}=(2^9)^2\equiv12^2=144\equiv19\pmod{25}$
$\displaystyle\implies 2^{400-2}\equiv19\pmod{25}\  \ \ \ (1)$
Now as $\displaystyle a\equiv b\pmod m\implies a\cdot n\equiv b\cdot n\pmod{m\cdot n}$ for any integer $n,$
multiply either sides of $(1)$ by $4$
Comment: @user2724695, yes, determining  the last $n$ digits mean $\pmod{10^n}$  for integer $n\ge1$. I am not sure of an easier solution
Comment: Thanks four your great answer! I only have one more question i calculated the last digit with $mod10$ so i conclude that when i count with $mod100$ i would get the last two digits? Is that right? So is there any easier solution? Thanks
Comment: Sorry but is the correct answer for 16Y100 mod 100 = 16 ?
Comment: @user2724695, nothing to be sorry, I think the answer must be $76$. What's the source of the problem?
Answer: Another way for $16$
We have already found $\displaystyle16^{100}=2^{400}$
$\displaystyle2^{10}=1024\equiv24\pmod{100}\implies 2^{20}\equiv24^2=576\equiv76$
Now, $\displaystyle2^{20a+b}-2^b=2^b(2^{20a}-1)\equiv0\pmod{100}$
if  $4$ divides $2^b\iff$ integer $b\ge2$
and $2^{20a}-1$ is divisible by $2^{20}-1$ for any positive integer $a$ and  $2^{20}\equiv1\pmod{25}$ by the other answer
So, $\displaystyle2^{20a+b}\equiv2^b\pmod{100}$ if integer $b\ge2,a\ge1$
Setting $\displaystyle b=20\implies2^{20(a+1)}\equiv2^{20}\pmod{100}\equiv76$
Now, set $a+1=20$
Comment: @user2724695, another check for $\displaystyle16^{100}\pmod{100}$
Comment: @BenMillwood, thanks for your observation. It should be $20^b$


How does one compute a variational derivative?

Question: The expected regression loss is given as:$$E[L]=\int\int \{y(\mathbf x)-t\}^2 p(\mathbf x,t)d\mathbf xdt$$
To minimise the expected loss,Euler Lagrange equation is used which goes like this in the general form:$$ \frac{\delta F}{\delta y}=\frac{d}{dx}\left( \frac{\delta F}{\delta y'}\right)$$ where $F$ is the functional i.e function of function $\mathit y(x)$.
In our case $F$ would correspond to $E$ and $\mathit y$ to $L$.
Please show a step wise application of this equation to yield the following expression
$$\frac{\delta E[L]}{\delta \mathit y(\mathbf x)}=2 \int\{\mathit y(\mathbf x)-t\}p(\mathbf x,t)
dt=0.$$
Also, please suggest a good reference for all the calculus used in Machine Learning.
Comment: where is $y'$? you don't have it the functional
Answer: I will carry out the steps in a way I hope is clear enough to indicate what assumptions must be made about $y,$ $p,$ and $\delta$ to justify the steps.
When a function $y$ is a local minimum of a functional $\mathcal L,$ adding a sufficiently small multiple $h$ of a "test function" $\delta$ cannot decrease the value of the functional.  (Usually a test function is assumed to be arbitrarily smooth and of compact support; in more complex situations it may have to satisfy constraints imposed by boundary conditions.)  That is, writing
$$\mathcal{L}[y] = \iint \left(y(x)-t\right)^2\,p(x,t)\,\mathrm{d}x\mathrm{d}t,$$
it must be the case that for all $|h|$ in some small neighborhood $U$ of $0$ (which may depend on $\delta$),
$$\eqalign{
0 &\le \mathcal{L}[y+h\delta] - \mathcal{L}[y] \\
&= 2h\iint \delta(x) \left(y(x)-t\right)\,p(x,t)\,\mathrm{d}x\mathrm{d}t + h^2 \iint \delta^2(x) \,p(x,t)\,\mathrm{d}x\mathrm{d}t
.}\tag{1}$$
Given $\delta,$ the right hand side is a quadratic function of $h$ with a zero at $h=0.$ (This assertion follows from the fact that the integral of $\delta^2$ is finite, which guarantees both integrals in $(1)$ exist and are finite provided $y$ and $p$ are not too "badly behaved," which is implicitly assumed in the question.)
In order to be non-negative throughout $U$, this zero must be the vertex of the quadratic; that is,
$$0 = 2\iint \delta(x) \left(y(x)-t\right)\,p(x,t)\,\mathrm{d}x\mathrm{d}t$$
This says the function
$$x \to \int \left(y(x)-t\right)p(x,t)\,\mathrm{d}t$$
is orthogonal to all test functions $\delta,$ implying (by virtue of some assumed "not bad behavior" of $p$) it is almost everywhere zero, QED.

Generally, to find the derivative of a functional $\mathcal L,$ you proceed as in ordinary differential Calculus to form the difference quotient as in $(1)$
$$\frac{\mathcal{L}[y+h\delta] - \mathcal{L}[y]}{h} = \iint \delta(x)\, 2\left(y(x)-t\right)\,p(x,t)\,\mathrm{d}x\mathrm{d}t + o(h).$$
The right hand side applies the linear operator
$$D[\delta] = \int \delta(x)\,\left[2\int (y(x)-t)\,p(x,t)\,\mathrm{d}t\right]\,\mathrm{d}x$$
represented by the generalized function
$$x \to 2\int (y(x)-t)\,p(x,t)\,\mathrm{d}t$$
to $\delta$ and adds an error term $o(h)$ that is vanishingly small compared to $h.$  This conforms with the (usual) definition of the derivative, allowing us to write
$$\frac{\partial \mathcal{L}}{\partial y} = 2\int (y(x)-t)\,p(x,t)\,\mathrm{d}t.$$
Comment: @Aksakal It was integrated out, due to the $\delta(x)$
Comment: where did the $\int d\mathbf x$ go?
Answer: The straightforward application of Euler Lagrange equation would lead to the sought result.
First, the derivative of the integrated expression with respect to $y'$ is zero, simply because $y'$ is nowhere to be seen. Here  $F(y(\mathbf x),\mathbf x)=\int (y(\mathbf x)-t)^2 p(\mathbf x,t)dt$, so we get: $\frac{\partial}{\partial y'}F=0$
Second, the derivative of $F$ with respect to $y(\mathbf x)$ is trivial, no need to even apply Leibnitz rule:
$$F_y=  \frac{\partial}{\partial y(\mathbf x)}\int (y(\mathbf x)-t)^2 p(\mathbf x,t)dt
=2\int (y(\mathbf x)-t) p(\mathbf x,t)dt$$
So, there you get the equation that you're looking for:
$$F_y=2\int (y(\mathbf x)-t) p(\mathbf x,t)dt=0$$
This condition minimizes the expectation.
As to reference to all math that's used in machine learning, there's no such a thing. Whatever the researches decides to use is a fair game. For instance, number theory and abstract algebra concepts can be used, like in this paper. The most common tools tend to be linear algebra, real analysis (calculus), probability and typical computer science toolset such as graph theory.


Is there a closed form expression for $f(n) = \sum_{i=1}^n (-1)^{i+1}\frac{1}{i!}$

Question: I have the series
$$
f(n) = \frac{1}{1!} - \frac{1}{2!} + \frac{1}{3!} - \frac{1}{4!} + ...... + \frac{1}{n!} \\
\text{or} \\
f(n) = \sum_{i=1}^n (-1)^{i+1}\frac{1}{i!}
$$
Is there a closed form solution for this equation?
Comment: Aside from RobPratt's answer, I doubt there's much more to be said. You can obtain a sort of closed form in terms of the incomplete and regular gamma functions (see [Wolfram's result](https://www.wolframalpha.com/input/?i=+%5Csum_%7Bi%3D1%7D%5En+%28-1%29%5E%7Bi%2B1%7D%5Cfrac%7B1%7D%7Bi%21%7D)), but that probably isn't quite what you want.
Comment: It is a partial sum of $1-1/e$.
Comment: @EeveeTrainer Ah I see. Yeah I was hoping for something that would allow me to compute the expression for any $n$ quickly by hand.
Answer: A derangement is a permutation with no fixed point, i.e. a permutation where no element is in its original position. Let $d(n)$ be the number of derangements of $\{1,2,\ldots,n\}$. There's a nice combinatorial argument that shows
$$
d(n)= n!\sum_{k=0}^{n}\frac{(-1)^k}{k!}
$$Note that in terms of your function, we have
$$
f(n) = 1- \frac{d(n)}{n!}
$$
Then you can use the Taylor series for $e^{-x}$ to compute
$$
\lim_{n\to\infty}\frac{d(n)}{n!} = e^{-1}
$$Since the sum is alternating and converges quickly, we have
$$
f(n) = \begin{cases}
1- \frac{1}{n!} \lfloor n!/e\rfloor,& n \text{ odd}\\
1- \frac{1}{n!} \lceil n!/e\rceil,& n \text{ even}\\
\end{cases}
$$I can't say how efficient this is, as it requires calculating $n!$, computing the floor/ceiling quotient somewhat accurately, and then dividing by $n!$ again. But it's something.


How to insert a column which has the format and the formula of the column on its left?

Question: It is similar to these two question:
Enter a new line and copy formula from cells above
excel vba insert row with formatting
I have seen this question, but I don't think it solves my problem.
Answer: Well, at least you have done some research, thus ... I will show about half of the answer - the format.
Take a look at the following:
Option Explicit

Public Sub CopyFormatToTheLeft(lngColumnNumber As Long)

    If lngColumnNumber < 2 Then
        MsgBox "Nope!"
        Exit Sub
    End If

    Columns(lngColumnNumber).Copy
    Columns(lngColumnNumber - 1).PasteSpecial Paste:=xlPasteFormats
    Application.CutCopyMode = False
    Cells(1, 1).Select 'no selection - no fun

End Sub

Public Sub TestMe()

    CopyFormatToTheLeft 3

End Sub

You will transfer the format of column C to column B. To transfer the formulas, take a look af the different posibilities of xlPaste.
Comment: Does your answer insert a new column with a format of Column C or merely copy Column C to B? Because I don't want the content in Column B (in your example) to be replaced.
Answer: If you wanna insert this should do the trick, might not be the cleanest way ;) You can change the Offset as you want.
Sub ColumnOffsetCopy()

Application.ScreenUpdating = False
Application.CutCopyMode = False

With ActiveSheet
    ActiveCell.EntireColumn.Insert
    ActiveCell.EntireColumn.Formula = ActiveCell.Offset(0, 1).EntireColumn.Formula
    ActiveCell.Offset(0, 1).EntireColumn.Copy: ActiveCell.EntireColumn.PasteSpecial xlPasteFormats
End With

Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

Comment: Would your code work if I replace "ActiveCell" as a specific cell? (e.g. sheetname.Cells(0, 9))
Comment: @Aqqqq the fastest fix (imo) is just to add `.Range("I1").Select` after `With ActiveSheet` if its column 9 you want. if you want to change the column you get formats and formulas adjust `Offset`.
Comment: What do you mean by " if its column 9 you want. if you want to change the column you get formats and formulas adjust Offset" I don't want to change the column from which I got formats and formulas from (if that is what you are talking about).
Comment: @Aqqqq You posted `(e.g. sheetname.Cells(0, 9))` the `9` refers to col 9. Just use `.Range("I1").Select` after `With ActiveSheet`. just make sure to use the letter of the column in `Range("yourcolumn and row")`
Comment: Would you mind if change your answer in such a way that it is applicable to a cell defined by its row and column number instead of simply "ActiveCell"? Same apply to the sheet (instead of Activesheet). I am not sure if I understand your answer correctly.
Comment: I just edited your answer to my best understanding of your comment. This is the code I tried and it did not work.
Comment: the point of the `ActiveCell`is that makes it more versatile. Meaning you can Select what ever cell in what ever column and you get you desired result. Why change it? If this helped you to get Your desired result either Accept it or just use it
Comment: In my case it is a step of a automatation process. (so far I have never needed such versatalitity.) The user is not going to select a cell in the middle of that process. No it did not help me to get my desired result. As I said, it did not work.
Comment: It does not work at all. The code will not run after ".Range("O1").EntireColumn.Select" is carried out.
Comment: didnt read it through, but range wont in that matter. i'll see what i can do today
Comment: What do you mean by "range wont in that matter"?
Comment: Correction to my former statement: ".Range("O1").EntireColumn.Select" is not run either
Answer: I just figure that I could insert column analogous to inserting rows. Following is the code for inserting the 15th column of destSheet:
        Application.ScreenUpdating = False
        Application.CutCopyMode = False
        destSheet.Cells(1, 15).EntireColumn.Copy
        Range(destSheet.Cells(1, 15).Offset(1, 0), destSheet.Cells(1, 15).Offset(1, 0)).EntireColumn.Insert Shift:=xlToLeft
        Application.CutCopyMode = False
        Application.ScreenUpdating = True

Comment: More parts of this that looks to be more from what i posted few days back.
Comment: I don't think so. Only the first and the last two lines just happen to be similar to your code, which might not be needed (I put it there just in case). I as a VBA beginner would never be able to go from your code to the third and the fourth line I posted. "More parts of this that looks to be more from what i posted few days back." just proves that you did not read the code carefully at all. Your code also does not work for me.