Binding in React: What does `this` refer to if I don't bind?

Question: I had some problems to understand the whole this issue in React (or JS in general) and found this very helpful article:
https://medium.freecodecamp.org/react-binding-patterns-5-approaches-for-handling-this-92c651b5af56
However, there is one basic thing that I'm still not sure about.
Let's take the Approach 2 as an example:
// Approach 2: Bind in Render
class HelloWorld extends React.Component {
  constructor(props) {
    super(props);
    this.state = { message: 'Hi' };
  }

  logMessage() {
    // This works because of the bind in render below.
    console.log(this.state.message);
  }

  render() {
    return (
      <input type="button" value="Log" onClick={this.logMessage.bind(this)} />
    );
  }
}

Now, let's look at the wrong version of this code where we just do not do the binding that is required in order to refer to the right this (the HelloWorld component):
// Wrong "naive" version of the code
class HelloWorld extends React.Component {
  constructor(props) {
    super(props);
    this.state = { message: 'Hi' };
  }

  logMessage() {
    // This works because of the bind in render below.
    console.log(this.state.message);
  }

  render() {
    return (
      <input type="button" value="Log" onClick={this.logMessage} />
    );
  }
}

My question is very simple: In that wrong version, it is my understanding that the this in console.log(this.state.message) within the logMessage function does not refer to the HelloWorld class object anymore. What does it refer to instead? Thank you!
EDIT: Turns out my understanding is wrong. This is not the this that does not work anymore. It's "the other" this at onClick={this.logMessage}! The reason will be given in the answers below - just wanted to correct this right here in the question.
Comment: To my knowledge, `this` always refers to the class. But when you render the page on browser, it doesn't know what `this` is. So `bind` will help to define your function to the render window. See https://reactjs.org/docs/handling-events.html, according to it `this` refers to `undefined` if you don't bind.
Comment: Thanks for the link. This is the answer that I was looking for: `undefined`. Still find that very weird though, would even say it feels like a bug of JS object notation. :-)
Comment: @ionizer `this` refers to the class? not to the object?
Answer: Whenever you call a function using - (), the function context - this is set automatically based on whatever goes before ().
For example,
let A = {
  foo() {
    console.log(this === A);
  }
};

when you call foo like this -
A.foo() // prints true

the context function foo receives depends on A.foo, here it is A. But when you call the SAME function using a different member - for example -
let B = {
  foo: A.foo
};
B.foo(); // prints false

Even though you're still calling the exact same function, the function/method foo receives a different context (here B) -
And sometimes, you can force the context of a function using one of these three things -
1. .bind
Docs: MDN

The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.

2. .call, .apply
Both of them call the function with a given this value.
Docs: MDN Function.prototype.call
Docs: MDN Function.prototype.apply
3. Arrow function
Docs: MDN Arrow functions
class
JavaScript class methods have the same concepts -
class A {
  foo() {
    console.log(this instanceof A);
  }
}
let a = new A();
a.foo(); // prints true

and when you run the experiment of assigning this function to a different method of a different object,
let b = {
  foo: a.foo
};
b.foo(); // prints false

Whenever you pass a function somewhere else, you're not passing the context along with it, but you're expecting some context inside your function by using this and
The source of the issue
In your example,
<input type="button" value="Log" onClick={this.logMessage} />

specifically,
onClick={this.logMessage}

which is analogous to the above example -
let b = {
  foo: a.foo
};

So, now, whoever calls your function using b.foo (here React) needs to know the context. So you have to set the context for the function before you pass it to onClick
What does it refer to instead if you don't bind?
In strict mode, the following happens -

Thus for a strict mode function, the specified this is not boxed into an object, and if unspecified, this will be undefined

Source: MDN under the section "Securing JavaScript"
And in all of the above examples with b.foo, if you assign it to a variable instead of object property,
let c = a.foo;
c(); // this will be undefined in foo

So, in your logMessage method, the value of this will be undefined.
Comment: I'm maybe late to this, but is it correct to simply think that it's `undefined` because it's not defined as the class's property? Because all the examples I know has something like `this.myFn = this.myFn.bind(this)` which means we define the function as the class property.
Answer: this always refers to your class' attributes and behaviors but you have to bind this to the functions in which you want to use those attributes and behaviors. If you do  not bind class level this with a function so "this" in that function refers to the attributes within the context of that function only.
You can also bind this in component cycle's callbacks like componentWillMount, constructor or anywhere where this has the reference to the class.
Forexampe:
componentWillMount(){
this.anyCallBack = this.anyCallBack.bind(this);
}
anycallBack(){
//now this will refer to the class
console.log(this);
}

Answer: The default value of 'this' depends on which event you are binding to.  With JavaScript, in general, DOM events, such as onClick or onChange have 'this' as a pointer to the DOM element that triggered the event.  For instance, if you were to create a button and attach a click listener, and in that listener, use console.log(this) you will see the button is the value of this.
Note: React has 'this' set as undefined by default.
Event handlers for setTimeout and setInterval, will set 'this' as a pointer to the window object.
There is an inherit danger to using bind.  Each time you bind to a method, JavaScript creates a new method.  The new method is an anonymous method unless you set it's value to a property or variable:
let myBoundMethod = myMethod.bind(this);
If you need to detach an event from a DOM element, unless you have a reference to the bound method, you will not be able to remove the event listener from the event.  This can be a source of memory leaks in your application.  Always use your debugging tools to monitor memory usage.  It is normal for it to go up and down, but it should have a relatively stable baseline.
DOM elements removed from the DOM will often garbage collect along with their event listeners, but if there is still a reference in memory to the element, it will not be garbage collected.


Dissolve using attribute field and area

Question: How can I dissolve a shapefile with polygons and keep the information of the polygons that have the bigger area in QGIS?
example:
two polygons with the same field values but one of them is bigger than the other --> dissolve into one polygon that contains the attribute values of the bigger polygon.
Answer: If the polygons you want to dissolve or merge located inside the bigger polygon , then try to use Eliminate sliver polygons located under Vector → Geoprocessing tools → Eliminate sliver polygons:

Select the polygon layer you want dissolve/merge
Select the Area field from the attribute table (Selection Attribute)
Use the <= to select only the polygons less than the bigger polygons area
Write the threshold area of the bigger polygon
Select Merge by largest area
Run the tool
Comment: @Ntelo You should mention that you are using QGIS 3.2 in your question. It is quite different in QGIS 3.2, you need to use Eliminate selected polygons tool, and before running the tool, you need to select the polygon that are less than the largest polygon that you want to keep. Then the eliminate tool should run on the selected polygon.
Comment: Amazing! Never thought of using this tool to merge polygons.
Comment: @Kazuhito Thank you very much. This tool works great if the small polygons are located inside the bigger polygon, however, I am not sure for OP's case it will give him the desired results or not.
Comment: In the selection attribute I cannot see every attribute that my file has. Therefore I cannot select a unique ID. Also, this tool doesn't exist in the 3.2 QGIS Version.
Comment: To add on ahmadhanab's answer: here's a detailed explanation https://gis.stackexchange.com/questions/336131/eliminate-sliver-polygons-qgis-3

Dissolve using attribute field and area


Why is admittance control better than impedance control for huma robot collaboration?

Question: I have seen many papers that use admittance control for human robot collaboration but no one tells why admittance is the choice and not impedance. Is it something very trivial that I should know or what am I missing?
Answer: One aspect is that impedance control requires direct torque control of the actuators. Admittance control computes joint position or velocity commands in response to a measured force.
Many robot arms on the market simply don't allow external torque commands for the joints, only position and velocity commands. They undoubtedly have a torque control loop in the internal controller but don't expose any torque-control functionality to the user.
Comment: Thank you for the response! So, if we have direct torque control available then is impedance control a better option over admittance control? Like I can achieve compliance by having low stiffness in the impedance control. So why not just use impedance control
Answer: I would like to add a couple of things to the answer from @danzimmerman. It definitely depends on what your robot can measure and control. If you only can command position / velocities and measure forces, then the only option between both is to use admittance control.
Theoretically speaking, both can achieve the same performance. In practice however, both controllers have their own advantages depending on your specific task you want to achieve and especially the environment it will interact with.
Example:
Imagine a manipulator holding a pen. Its task is to draw a straight line on something. This requires following a trajectory and maintaining a constant force against the wall.
Stiff Environment:
Assume the wall is very stiff. At the moment of contact there will be an almost instantaneous feedback. An impedance controller would maintain the force by keeping the position error between the actual position and the internal models position. Since the wall is very stiff the impedance controller can quickly react to positional errors and provide a "good" performance. An admittance controller on the other hand would react to the change in forces. Since the change in forces will be very quick and could potentially overshoot due to the very stiff environment the admittance controller would probably result in a "bouncy" behavior and have a harder time to reach a "steady-state". After a high overshoot it would try to bounce back, and retry reaching the desired force etc...
Soft Environment:
Imagine a very soft environment. At time of contact the force exerted at the end-effector would increase slowly. The admittance controller can slowly react to the change in forces and has the time to "adapt" to the displacement of the surface. Note that it will decelerate at the moment of first contact because there is a small change in force when pushing into the soft material. The impedance controller however, would not notice immediately that there is a change in force because if the material is very soft in the beginning it would maintain its speed perfectly fine. It would continue with the same speed until the material slowly stops its deformation and slow down the end-effector. Only then the impedance controller would get some feedback saying "hey, I notice a change in motion, this is the wall!".
Most of the times you will have an environment which is in between "soft" and "stiff". And your task might also require the manipulator the desired force in a specific amount of time. If you have the opportunity, definitely try both, observe the differences and choose according to your needs. As far as I can tell impedance controllers tend to be more "aggressive" in terms of force tracking, whereas admittance controllers are more "compliant". But this also depends on your tuning.
It is hard to formulate the specific behavior in words, but I hope I could give you some sort of intuition for it.


How do I replace road bike hoods?

Question: I commute daily on a road bike with Shimano Tiagra STI shifter/brake levers. The rubber hoods are pretty grimy and getting sticky, torn up and unpleasant these days. Repair and replacement of pretty much everything on my bike seems very straight-forward, but I can't figure out if these parts can even be replaced, much less how to do it. Ideas?
Comment: Had a similar issue with sticky hoods and could not get them clean. I realize this is quite an old post, but it gave me encouragement when trying to get the Saccon hoods I could find over my shimano 105s. This was not possible by hand alone. After earning myself a blister, I used some silicon spray, which allowed the hoods to slip over the breaks. Silicon is used to keep rubber from cracking, so I think it is a superior choice for getting those little buggers to fit.
Answer: Easiest thing to do is just cut off the old hood then take the new hood and thread it on over the bottom of the brake lever. Some are 'ergo' and have a right and left hood so make sure that you watch for right and left hoods.
Comment: +1 Hoods are are most definitely designed to be replaceable. Also, keep in mind that stretching them a little bit to get them over the lever is OK! No disassembly required.
Answer: If you can't get a replacement hood, try making one yourself.  Here I have stretched a section of 26 x 1.5 - 2.0 inner tube over the brake lever.  The inner tube fits better if you cut off the tip of the "horn" of the aero levers.  With these Shimano Exage Action BL-A351 levers you can slip the edge of the rubber under the plastic front of the lever to help hold it in place.
The lump at the bottom of the dip in the brake lever is caused by a metal tab.  I'd cover that with a leftover piece of padded handlebar tape before adding the inner tube.
To avoid the seams on the surface of the rubber, try turning the inner tube inside out.
Answer: before you do anything, you should check the components documentation on shimano's web site, all the instructions are there - the hoods are quite widely available on order from bike shops although they don't seem to justify the $$ tag.  if it's only sticky, just clean it with a damp cloth or with 1 drop of dish washing liquid if it hasn't been properly cleaned before.  i use mine for over 5yrs+ its very scratched now but still don't need to replace.
Answer: I think the first thing you should do is take the hoods off the bars.  Usually there is a screw or an allen key that will loosen the hood on the bar.  On my hoods this is only viable when the break leaver is pulled down.  After you loosen this screw you should be able to slide the hoods along and off the bar.  (You might need to remove the tape).
Comment: I've never seen a road bike that you have to take the brake assembly off to get at the hoods. If you do it this way you'll also have to retape your bar as the tape goes over the back of the brake assembly.
Comment: Actually now that I have thought about it a bit more that probably makes sense.  On my older road bike, that is how I got them off the first time but you are right it would be easier to do like that.
Comment: I think you are thinking of the brakes themselves, not the brake *hoods*. The hoods are the rubber pieces, not the metal parts underneath.
Comment: Never mind... according to Sheldon's [glossary](http://www.sheldonbrown.com/gloss_ho-z.html#hood), "hoods" can refer to either. I find that highly confusing.
Comment: This helped me a ton, so many thanks! I ended up using the allen wrench to remove the whole lever assembly, then had to remove the brake cable. From there, I was able to (somewhat) easily replace the rubber hoods.
Answer: If you can't get a replacement hood, a desperate, last option "hack" is to get some cushioned handlebar tape and wrap it around the lever body.  You can use electrician's tape to hold the last end and stop the tape from unraveling.

How do I replace road bike hoods?


What were the origins of Persephone in The Matrix: Reloaded?

Question: As shown in the movie Persephone was the wife of The Merovingian, who himself was an obsolete program who denied being deleted. My question is, does anybody know anything about the origins of Persephone? There seems to be no specific information that indicates who she previously was.
Comment: Did you mean origins in the myth sense?
Comment: Nope, I meant in the not-myth sense. I know that Persephone is the daughter of Zeus and blah blah blah...
Answer: Persephone's origin is not mentioned in the movie. But she mentions about silver bullets, thus suggesting that Merovingian has a werewolf background. The DVD Behind the scenes mentions that she is a vampire that seeks after emotions.
She admires the love that Trinity and Neo hold for each other. She also mentions about the love that she had once enjoyed, which suggests that Merv was a better spouse before he is lost in his hunger and greed for power and lust. Hence she appears to be no more bothered about the matrix as well as Merv.
Comment: "Merv" - splendid!
Comment: In the Enter the Matrix videogame you fight your way through several werewolves guarding the Merovingian's château.
Answer: Let us assume that the love that Persephone once enjoyed was with Merovingian.
Merovingian and Persephone have slightly more human traits than other programs, they enjoy fine food, wine, languages. While Persephone talks of love, Merovingian displays lust ("The lipstick that is not on Merovingian's face"). Merovingian is shown to cheat on Persephone. Surprisingly, he uses a special code to trigger sexual reactions in a woman and gets serviced by her! Persephone's envy leads her to give Neo and gang the Key Maker's location.
The Oracle mentions Merovingian to be the oldest of them, a powerful program.
No program other than the Oracle has the purpose to be human like.
The fact that Merovingian and Persephone turn human-like is them exhibiting programmatic roguishness.
Their initial purpose is not mentioned, but the period of love that Persephone mentions is when they went rogue. Merovingian controls the virtual afterlife through the train-man program. This is where exiled programs seek refuge.
Though this is the current operation, perhaps in the beginning, Merovingian was created with the purpose of Programmatic Garbage Collection. Once a program has served its purpose it needs to be de-allocated from the computing resource pool. (Eg: JVM provided by Java has a Garbage Collector which does a clean up periodically). The program Persephone was perhaps a supporting function to this Programmatic Garbage Collection, which is how they met.
Comment: @CrowTRobot  Cypher sure seemed to be enjoying that virtual steak..
Comment: `they enjoy fine food, wine, languages` Well, they enjoy very detailed computer simulations of them. Real humans who know they're in a computer program don't enjoy food or wine which suggests to me they're less than human.
Comment: Surely they are less human but they show traits of human behaviour (just like Ramachandran at the train station). My point was they are rogue programs. Besides, that is a side point. I was merely using that to deduce the origins of the programs.


output file naming

Question: Alright, So I am using a batch process of raster calculator and in the calculator I am using 2 different raster files (meridional and zonal). This calculator will be running for 24 files of each the meridional and zonal. So one run will calculate an output file for, say, Mericional_0000 and Zonal_0000; then the next run will use Meridional_0100 and Zonal_0100, all the way till 2300. Is there a way that when the calculator runs, the output for Meridional_0000 and Zonal_0000 will go to one file while the Zonal_0100 and Meridional_0100 will go to another file. [each of the 24 files will have its own file when calculated]. I tried the %Name%, but that gives me an output for each individual file, and I don't want that. Any help would be great!
Comment: Are you using the actual "Batch" option or are you running this in ModelBuilder?
Comment: ModelBuilder is the way to go if you do not use Python.  However, here is a link to the batch mode: http://resources.arcgis.com/en/help/main/10.1/index.html#//00210000000w000000
Comment: Wouldn't it be easier to have the outputs in the same folder?
Comment: I want them in the same folder, but I want each run of the model builder (which is doing batch run, 24 times) to be saved in its own output file.
Comment: in model builder. I am new to the batch option, so I don't know where to find it within ArcGIS 10.1
Answer: How are your files named in the first instance?  I am presuming that you are working in a file workspace as opposed to geodatabase workspace.
If you are using model builder perhaps use two instances of calculator,  one to calculate the zonal one to calculate the meridional.  In the one instance of calculator you can set the output name to be Meridional_%Name% and the other to be Zonal_%Name%.  You may wish to send them to different output locations too.

Is there a way that when the calculator runs, the output for Meridional_0000 and Zonal_0000 will go to one file while the Zonal_0100 and Meridional_0100 will go to another file.

Do you mean another folder instead?  If so, you can use model builder to create a new folder on each iteration using the original file name to name it.
If I've understood you correctly we should be able to crack this no problem but more information is needed to give a full answer.

output file naming


Is it Mutar to Listen to Music Recorded in a Church?

Question: I read somewhere that listening to music recorded in a church is asur, because it essentially brings the church into one's home. This is common practice for classical music. Has anyone heard of or not heard of this? Does anyone know a source?
Comment: Thanks! For the sake of simplicity, I'm referring to secular music. Plenty of Bach and other baroque composers are recorded in churches by some of my favorite ensembles, such as Voices of Music. I have separate thread a couple before this one on listening to Christian music in general, which I'm hoping will get some answers.
Comment: Welcome Dovid and thanks for the question. You say that it  is common practice to record classical music in a church. Do you want to distinguish between explictily religious music (say a requiem) and other music (say Saint-Saëns's Carnival of the Animals)?
Comment: Classical music maybe was composed for the church but what makes you say it is recorded in a church? Maybe in an orchestral theatre? Or in a music studio
Comment: @Dovid I've always assumed Bach is worse since he dedicated every single piece he wrote to Jesus.
Johann carefully formed the letters J J at the top of the page. With that, the music began to pour from his soul and onto the page. When he was finally satisfied, he wrote the letters SDG at the bottom of the page - Soli Deo Gloria - For the Glory of God Alone. He hoped that when the music was played, it would point toward God.
https://www.google.com/amp/s/www.christianity.com/wiki/people/j-s-bach-soli-deo-gloria-to-the-glory-of-god-alone-11635057.html%3famp=1
Answer: The following Rabbanim address this question and allow it

Rabbi Yuval Sherlo - here
Rabbi Dov Lior - here
Comment: Could you describe what it says in the two links you mentioned for in case a link gets broken....


What are UCI categories for cyclocross events?

Question: Having more than 10 years of MTB experience, I want to try my first CX race. However when I google for CX events in my country, the results contain some scary codenames called UCI C1 and UCI C2. In MTB enduro races you know that you have pros and amateurs riding the same course, just separated by the start times, so there is no worry to lag behind. In cyclocross it's a different story, I'm afraid to make a joke out of myself or even worse, ruin someone's run if I'm choosing a wrong event. So basically, how do I know if I can try one of those events? Do those events require some kind of bureaucracy (UCI license) to enter?
Comment: where are you based? In the UK we have regional leagues that are friendly and welcome all abilities and bikes
Answer: These are quite high-profile events. I think you do need a license, C1 and C2 are pro categories.
From a random website:

What does UCI, C1 and C2 mean?
That means some of the world's best cyclocross racers will be right
  here in Rochester racing at the Rochester Cyclocross in Genesee Valley
  Park!  Including a bunch of current and past national champions, the
  competition will be fierce – so don't miss a second of it! UCI stands
  for the "Union Cycliste Internationale", they are based in Switzerland
  and they are the worlds governing body for professional cycling. C1
  and C2 refers to the level of international event – C1 is the highest
  level ( there are only SEVEN of these in the USA).

https://rochestercyclocross.com/frequently-asked-questions/
There should be non-UCI races around. In UCI races you have to have a frame with the right UCI-approved sticker and 33 mm tyres.  In amateur friendly races the riders are often not eliminated when lapped and can use wider tyres or even other types of bikes.
Note that in America there are often amateur categories as "side races" taking place on the same course during tha same weekend as the C1 and 2 races.


Excel Conditional Formatting : Change Cell Colour Based on Value of Another

Question: For each cell value I would like to change the colour in an adjacent cell based on the value in another. For example:
I have a column of cells with a range on numbers from 81 to -91.
Where cell values are between -30 and -91 the colour is RED
Where cell values are between 0 and -30 the colour is AMBER
Where cell values are between 1 and 81 the colour is GREEN
Comment: You might try search the internet for "Excel between".
Comment: the challenge is to put "to change the colour in an adjacent cell based on the value in another" relative equation in the rule..
Answer:
I think this is what you wanted. Basically, in Excel you can reference cells in different ways. You may sometimes realise that when you click on a cell to reference it in your formula, it's inserted as $A$2 instead of A2. While both are correct, if for instance you start to drag around the former, the formula will be copied directly (e.g if you drag it to A3 it will not change, but remain as $A$2="Hi" in both cells). If you do the same to the latter, the formula will adapt (e.g if you drag it to A3 it will change from A2="Hi" to A3="Hi"). Also note that it is possible to only use one dollar sign/locked reference, such as $A3 (where it will change when dragged on the Y axis, but not the X) or A$3 (where it will change when dragged on the X axis, but not the Y).
Keeping this in mind, we can begin to create our formula. Select the cells you want to be coloured. Click 'Conditional Formatting' > 'New Rule' > 'Use a formula to determine which cells to format'. Click on the formula box. If you just click on a cell from there to select it, it will insert it as $A$2. However, this means that each cell's colour is being determined by the cell A2, as it is locked to only look at that cell. However, if you remove the second dollar sign to get $A2, then it will still only make comparisons in the A column, while looking at the relative row, as the row is open to change. Excel will automatically line up the row with the row it is testing to format, and therefore check in the right place.
In conclusion, make three formulae, all on the same range (the one you want to be coloured). The first, =$A2>0, and set the format to have a green fill. The second, =AND($A2>-31, $A2<1), and have an amber fill. Finally, do =$A2<-30 with a red fill.
I hope this helps.


Before being overturned, did Roe v Wade grant pregnant men the right to have abortions, in addition to pregnant women?

Question: The language in the Roe v Wade decision refers over and over to the rights of a "pregnant woman". Does this mean it protected only the rights of pregnant women, and not pregnant men, to procure abortions?
Answer: Roe and Casey refer to the category "pregnant woman." But in many places, the reasons talk only about a "person" and the interests that underpin the reasoning would clearly apply to all pregnant people:

constitutional protection of the decision to terminate one's pregnancy "derives from the Due Process Clause of the Fourteenth Amendment... The controlling word in the cases before us is 'liberty'" (Casey, p. 846)
"Our cases recognize 'the right of the individual, married or single, to be free from unwarranted governmental intrusion into matters so fundamentally affecting a person as the decision whether to bear or beget a child.'" (Casey, p. 851)
"the liberty of the woman is at stake in a sense unique to the human condition and so unique to the law. The mother who carries a child to full term is subject to anxieties, to physical constraints, to pain that only she must bear." (Casey, p. 852)
the plurality in Casey characterized "Roe's central holding" being that "viability marks the earliest point at which the State's interest in fetal life is constitutionally adequate to justify a legislative ban on nontherapeutic abortions." (p. 860)
and so forth


How does the reciprocal lattice takes into account the basis of a crystal structure?

Question: I am reading about solid state physics, and I think I got right the concept of crystal lattice. We first define a Bravais lattice as the set of vectors spanned by $\{\vec{a}_1,\vec{a}_2,\vec{a}_3 \}$ over the integers, i.e. vector of the form $$R=n_1\vec{a}_1+n_2\vec{a}_2+n_3\vec{a}_3 $$
Now, we need to define the atoms that constitute the crystal lattice. We may arrange a point in the Bravais to be the origin and take the minimum cell and define some points within, i.e.
$$r=x_1\vec{a}_1+x_2\vec{a}_2+x_3\vec{a}_3 ;\quad x_i\in [0,1] \text{ for } i\in\{1,2,3 \}$$
Given a Bravais Lattice and a basis, we call the whole structure the crystal lattice. Now we further define a reciprocal space, which is like an scaled dual in some way such that it is the lattice spanned over the integers of $\{\vec{b}_1,\vec{b}_2,\vec{b}_3 \}$ such that $$\langle b_i,a_j\rangle =2\pi \delta_{ij} $$
So, it is said that x-ray diffraction is a kind of map of the reciprocal lattice, and hence of the crystal lattice, but the basis is never taken into account for the construction of the reciprocal lattice. How can we know the structure (the complete crystal lattice). One big problem that I see in this is that we can have the same crystal lattice described by two different Bravais lattices (and of course two different basis). How does this work? Is there something that I am not understanding?
Answer: Your understanding that the reciprocal lattice is only defined for a Bravais lattice is correct. When you have a so-called lattice with a basis, you would calculate the reciprocal lattice primitive vectors using only the primitive vectors of the underlying Bravais lattice as:
\begin{aligned}\mathbf {b} _{1}&=2\pi {\frac {\mathbf {a} _{2}\times \mathbf {a} _{3}}{\mathbf {a} _{1}\cdot \left(\mathbf {a} _{2}\times \mathbf {a} _{3}\right)}}\\\mathbf {b} _{2}&=2\pi {\frac {\mathbf {a} _{3}\times \mathbf {a} _{1}}{\mathbf {a} _{2}\cdot \left(\mathbf {a} _{3}\times \mathbf {a} _{1}\right)}}\\\mathbf {b} _{3}&=2\pi {\frac {\mathbf {a} _{1}\times \mathbf {a} _{2}}{\mathbf {a} _{3}\cdot \left(\mathbf {a} _{1}\times \mathbf {a} _{2}\right)}}\end{aligned}
Indeed, this does not take into account the effect of the basis. That, however, plays a role in X-ray diffraction experiments and affects which peaks are actually measured. The resultant intensity is determined by how the waves diffracted from each of the constituent atoms of the basis interfere. For instance, consider the body-centered cubic lattice as a simple cubic lattice with a basis at $(0,0)$ and $(\frac{a}{2}, \frac{a}{2}, \frac{a}{2})$. It's possible that at some incident angles diffracted waves from these two atoms interfere destructively and you don't see an intensity peak even though you would expect it from a simple cubic reciprocal lattice. This is taken into account by the geometrical structure factor $F_{hkl}$, defined as:
$$F_{hk\ell }=\sum _{j=1}^{N}f_{j}\mathrm {e} ^{[-2\pi i(hx_{j}+ky_{j}+\ell z_{j})]}$$
where $(hkl)$ indicates the scattering plane, the index $j$ is summed over each atom in the basis with coordinates $(x_{j},y_{j},z_{j})$ and scattering factor $f_{j}$.
This sum can be zero for certain values for $h,k,l$ and in such cases, no diffraction peak is seen even though it is expected from the reciprocal lattice structure of the underlying Bravais lattice.
(I've ignored that BCC is itself a Bravais lattice, for the purpose of this example. Of course, you could calculate the BCC reciprocal lattice primitive vectors using BCC primitive vectors and you'd get the right reciprocal lattice. XRD peak intensities thus determined will be most accurate, but simple structure factor calculations for SC with a basis would at least tell you which peaks won't be observed at all.)
Chapter 6 of the book Solid State Physics by Ashcroft and Mermin is a good reference for X-ray diffraction, and the concept of structure factor in particular.
Answer: The reciprocal lattice definitely takes into account the basis for the Bravais Lattice. Take for example a 3-dimensional lattice with basis $\{ \vec{a}_1, \vec{a}_2, \vec{a}_3 \}$. The reciprocal basis is then

Which clearly depends on the basis vectors.
Every lattice has a reciprocal lattice. In some ways, the reciprocal lattice is like the Fourier transform of the basis. For a specific set of Fourier basis functions (in this case the exponential series), it is unique.
In response to comment:
There was a clarification, the word "basis" in the question refers to the structure of the crystal itself in terms of the atoms within the crystal.
This is taken into account when you actually try to work out for example the diffraction of Xrays and such. There is a term called the structure factor that makes use of the specific position of atoms within your lattice. The "map" of the reciprocal lattice that you would obtain then also depends also on the position of atoms within the lattice cells.
For example. if you have a simple cubic lattice, you may also have atoms in the center of the cell, at fractional basis positions. These are taken into account when you try to determine scattering angles for example.
However, this becomes a much more general question, and is much more involved. A resource I used when I was studying this was the Solid State Physics textbook by Kittel, Chapter 2 page 41 in the 8th edition if you would like to check.
Comment: I do not mean basis in that sense. I mean basis of the crystal structure, as in the atoms that are inside the cell
Comment: Thanks for the clarification, I've made an edit to my answer since the response is quite long
Answer: Reciprocal lattice simply does not take into account the basis of a crystal structure.
The lattice is an array of geometrical points in the space, whereas the structure is the convolution of the lattice with a basis (consituted of one or more atoms). So the lattice is not a real object, the crystal structure is a real (ideally) object that you can analyze using a diffractometer.
What you analyze by diffraction is the crystal structure, not purely the lattice.
A lattice unit cell in the reciprocal space corresponds to a Brillouin zone.


Neural Network Optimization Algorithms

Question: What are some of the popular optimization algorithms used for training neural networks?
Answer: Here's a list of popular algorithms used in training neural networks:

SGD updates parameters in the negative direction of the gradient, learning rate parameter $\epsilon_k$ should be decreased over time, computation time is proportional to mini-batch size $m$:
$$
g = \frac{1}{m}\nabla_\theta \sum_i L(f(x^{(i)};\theta), y^{(i)}) \\
\theta = \theta - \epsilon_k \times g
$$
Momentum accumulates exponentially decaying moving average of past gradients and continues to move in their direction, thus step size depends on how large and how aligned the sequence of gradients are, common values of momentum parameter $\alpha$ are 0.5 and 0.9
$$
 v = \alpha v - \epsilon \nabla_\theta \big(\frac{1}{m}\sum_i
L(f(x^{(i)};\theta), y^{(i)}) \big) \\
\theta = \theta + v
$$
Nesterov Momentum inspired by Nesterov's accelerated gradient method, difference betweent Nesterov and standard momentum is where the gradient is evaluated, with Nesterov's momentum the gradient is evaluated after the current velocity is applied, thus Nesterov's momentum adds a correction factor to the gradient:
$$
 v = \alpha v - \epsilon \nabla_\theta \big(\frac{1}{m}\sum_i
L(f(x^{(i)};\theta + \alpha \times v), y^{(i)}) \big) \\
\theta = \theta + v
$$
AdaGrad adapts the learning rates of all model parameters, learning rate is inversely proportional to the square root of the sum of historical squared values, weights that receive high gradients will have their effective learning rate reduced, while weights that receive small or infrequent updates will have their effective learning rate increased: the net effect is greater progress in the more gently sloped directions of parameter space:
$$
g = \frac{1}{m}\nabla_\theta \sum_i L(f(x^{(i)};\theta), y^{(i)}) \\
s = s + g^{T}g \\
\theta = \theta - \epsilon_k \times g / \sqrt{s+eps}
$$
RMSProp modifies AdaGrad by changing the gradient accumulation into an exponentially weighted moving average, it discards history from the extreme past. RMSProp has been shown to be an effective and practical optimization algorithm for deep neural networks.

$$
g = \frac{1}{m}\nabla_\theta \sum_i L(f(x^{(i)};\theta), y^{(i)}) \\
s = \mathrm{decay\_rate}\times s + (1-\mathrm{decay\_rate}) g^{T}g \\
\theta = \theta - \epsilon_k \times g / \sqrt{s+eps}
$$

Adam derives from "adaptive moments", it can be seen as a variant on the combination of RMSProp and momentum, the update looks like RMSProp except that a smooth version of the gradient is used instead of the raw stochastic gradient, the full adam update also includes a bias correction mechanism, recommended values in the paper are $\epsilon = 1e-8$, $\beta_1 = 0.9$, $\beta_2 = 0.999$
$$
g = \frac{1}{m}\nabla_\theta \sum_i L(f(x^{(i)};\theta), y^{(i)}) \\
m = \beta_1 m + (1-\beta_1) g\\
s = \beta_2 v + (1-\beta_2) g^{T}g \\
\theta = \theta - \epsilon_k \times m / \sqrt{s+eps}
$$

For more information about the algorithms, I recommend referring to deep learning book by Ian Goodfellow and a neural network course. For a TensorFlow implementation have a look at the following ipython notebook.
Answer: On top of the 1st order algos listed out by @VadimSnolyakov, it is perhaps worth mentioning 2nd order gradient methods.

Second order methods often converge much more quickly, but it can be very expensive to calculate and store the Hessian matrix.
In general, most people prefer clever first order methods which need only the value of the error function and its gradient with
  respect to the parameters (source)

2nd order gradient methods include the classical Newtons's method, Broyden-Fletcher-Goldfarb-Shanno (BFGS) and other quasi-Newton methods, where an approximation for the Hessian (or its inverse directly) is built up from changes in the gradient, as it is the case, for example, in Levenberg-Marquardt.

Edit 1:
It has been questioned whether the use of second order methods is "popular".
Well, in order to settle the dispute we would need to agree on how to define and measure "popularity".
However, we read on the notes of the Stanford CS class CS231n: Convolutional Neural Networks for Visual Recognition

Second order methods
A second, popular group of methods for optimization in context of deep
  learning is based on Newton's method (source)

We can not draw on conclusion on our dispute based on this quote but yes, second order methods may be an option, especially if you have shallow NNs (due to the computational burden the Hessian approximation brings).
On top of that, some promising research has already been carried on comparing optimization methodologies when dealing with auto-encoders and in particular sparse auto-encoders:

More significant speed improvements of L-BFGS and CG over SGDs are
  observed in our experiments with sparse autoencoders. This is because
  having a larger minibatch makes the optimization problem easier for
  sparse autoencoders: in this case, the cost of estimating the
  second-order and conjugate information is small compared to the cost
  of computing the gradient (source)

In the end, we might regard the extra cost associated to the approximation of the Hessian as an alternative to:
1) the need of pre-training

why does pre-training work and why is it necessary? Some researchers
  (e.g. Erhan et al., 2010) have investigated this question and proposed
  various explanations such as a higher prevalence of bad local optima
  in the learning objectives of deep models. Another explanation is that
  these objectives exhibit pathological curvature making them nearly
  impossible for curvature-blind methods like gradient-descent to
  successfully navigate (source)

having to tune first-order methods - curvature helps!

One key disadvantage of SGDs is that they require much manual tuning
  of optimization parameters such as learning rates and convergence
  criteria. If one does not know the task at hand well, it is very
  difficult to find a good learning rate or a good convergence
  criterion. (source)

All this is far for being exhaustive but I hope interesting enough to encourage us to dig deeper. In research, we assist to waves of interest and popularity. We might in fact see a resurgence of interest in second order methods in the upcoming future.

Of particular interest to the use of second-order methods is the
  relatively recent (or not so recent, depending on your type of work)
  discovery that saddle points are far more common in high-dimensional
  space than local minima (see [1406.2572] Identifying and attacking the
  saddle point problem in high-dimensional non-convex optimization).
  This is a bit counterintuitive, since local minima are far more
  ubiquitous in lower-dimensional problems. Purely first-order methods
  cannot differentiate between saddle points and local minima, and thus
  for certain problems, SGD can become stuck along paths of slow
  convergence around saddle points (source)
Comment: He specifically asked about training neural networks, not just any optimization methods. While there interesting work in this field, it is very preliminary and can hardly account as a "popular" optimization method.
Comment: @galoosh33 - Not sure how you would define and measure "popularity". 2nd order gradient methods are an option - the answer is surely not out of topic - and it adds a point of view to the question. I fail to understand the downvote.

Neural Network Optimization Algorithms


How do I remove the header/footer of some pages?

Question: I created a template in Word 2010. In this template, there is a footer and a header. When I create a document based on this template, I'd like for some pages not to show them.
Comment: Haven't you got the answer you were looking for, since you haven't accepted?
Comment: If you use LibreOffice writer to edit this document, you can apply different page styles to different pages. One page style can have headers and footers and another can omit them. You can then save your document in any one of a number of Word formats. This is probably the easiest and most flexible method for handling issues like this.
Answer: Use section breaks.
Place each part of your document that requires a different header/footer in separate sections, by adding "Next page" section-breaks (Page layout -> Breaks -> Section breaks -> Next page).
Then, for each section, insert header/footer. When editing header/footer, "de-click" the button "Link to previous" in the toolbar. That indicates that this header/footer will be different from the header/footer of the previous section. Then edit the header/footer, affecting only this section (possibly also the next ones, but not the previous). Do this for all sections.
Comment: This didn't work for me with a page break. But it did work when I inserted a continuous break just above the page break.
Answer: Try this.  I'm sure it will help. Remove Header or Footer from the Second Page of a Word 2007 Document

Click on the first page of your document (within the body).
Go to the Page Layout tab on the ribbon (third tab) and click on the tiny arrow in the lower right of the Page Setup group to expand it (see image).

Click on the Layout tab (third tab).
Check the "Different first page" checkbox.
Ensure that the "Apply to" field is set to "This point Forward."
Click on OK.
Comment: Having a link is nice, but in the future, include all relevant parts here on site, thank you.
Answer: It seem that Microsoft has excluded any away to specifically pick which individual page to show or not show the header or footer. Here the few limited options available: effect all pages at once; effect odd and even pages differently; effect the first page differently from the rest; the combination of all these.
How to configure heading and footer differently depending the page:

Select the Laytop tab from the ribbon
[Click] on either Header or Footer
Select the wanted design
Notice under the sub tab of Design there are check boxes: (See Note 1)

Different First Page
Different Odd & Even Pages (See Note 2)
Show Document Text (Can be disregarded since it's not related this subject.)

Select the wanted settings

Note 1: These choices will effect both the footer and header. Exampe: It isn't possible to have different odd & even pages selected for header with out having different odd & even pages selected for the footer too. Additionally, to have all the pages effected the same, remove the check marks from both choices.
Note 2: When first editing an odd or even page the heading or footer will effect both types pages even if Different Odd & Even Pages is selected. Do not worry, after finishing with the current page header or footer, select the next page and make your changes. Once this has been done, all old pages will be the same as will the even ones.
Comment: Not sure what you are suggesting?
Comment: not possible to use "Breaks" (Page, Section Breaks) ?
Comment: I guess you can take advantage of page-breaks, different odd & even page option, and print page selection. Example: Select have the different odd & even page option. When want to have back-to-back pages with the same header, just put a blank page in between the two pages via a page-break. When ready to print, select **only** the pages that are not blank. I guess you could do it that way. If that was what you were referring too.
Comment: @Kris-I Section breaks is probably what you want -- see my answer.
Answer: I solved this using the page breaks function. I made a page break, then removed the header from that page (page 3 for me), made a page break after that page and copy/pasted the original header from my 1st/2nd page to page 4.


How do I convert a date stored in UTC to the user's current locale in PHP?

Question: I have a date stored in the database in UTC.
2016-01-13 09:01:16

I can query the database and output this date just fine. But it outputs in the date in the wrong timezone.
How do I adjust a date from the database into the current user's locale?
I believe this involves using craft()->timezone at some point, with some method, but I have not had any luck. I'm retrieving the date with the query builder:
$rows = craft()->db->createCommand()
         ->select('dateCreated')
         ->from('mytable')
         ->queryAll();

Bonus points: sometimes I have multiple dates, so I need to modify all dates I get back into the right timezone.
More bonus points: at what point in the process is the best point to modify the date into the right timezone? In MySQL query? In PHP? In Twig?
Answer: Here is some code used in the past.
$timezone = new \DateTimeZone(craft()->getTimeZone());
$newdate = \DateTime::createFromFormat(DateTime::MYSQL_DATETIME, $mysqlDate, $timezone);

I have typically done this before assigning to a model.


version control in virtual machine

Question: My employer wants to run our version control system in a virtual machine. Is this a bad idea or does it not matter? I am concerned about disk access integrity and stability. Are these valid concerns? Are there other concerns I should have?
Thanks
Answer: We have our subversion server running on a ESX 3 VM but the repository is in a SAN to which the VM has access. Best of both worlds if you ask me.
Answer: Should be perfectly fine. In some ways, it's even easier for backup strategies, as you can have VM snapshots etc. Also, you can easily hook up decent NAS solutions as drives in your VM machine, so no need to worry about data integrity of your repository. It really all depends on the implementation.
As long as it is a proper server host, not a little desktop machine being used by the secretary that's running this VM. Well, you get the point.
Answer: Disk integrity and stability are valid concerns, because the whole system is stored on a single file on an external disk. This means that the chances that you lose the whole system is dependent on the configuration of the external disk - you can lose the whole os if you lose that file. However, you would be extremely remiss to not have a system for backing up your vcs. If you use a distributed vcs, like Git or Mercurial, you get a "free" backup - every clone of the repository is a full backup, with history and all - but any other vcs, you should be doing some sort of archiving of your vcs anyway. This is the whole of your IP value, after all.

version control in virtual machine


Why isn't my sump pump kicking on?

Question: My sump pump is not kicking on and has water standing.  The water also seems to have oil in it.  Don't know what that is from but I don't want it to flood my basement.  What should I do?
Comment: Does your sump pump have power?
Comment: My pump stands in a certain amount of water all the time. I don't think a little oil sheen is unusual or uncommon in sump water. If you pour a 5 gallon bucket of water into your sump does the pump kick on? I do that a couple of times a year with mine just to check and exercise the pump. If it doesn't, shop-vac the water out and replace it like Tester says.
Answer: You likely need a new pump.
Submersible pumps are often filled with a non-conductive mineral oil.  If the oil is no longer in the pump, the pump is probably dead.

Why isn't my sump pump kicking on?


DB STARTUP command active for an online database

Question: We had a maintenance activity done on our SQL Servers and after that, we restarted the services. Now the databases took their sweet time to recover and after recovery, we started some jobs thinking that everything is good. Now one of the job runs was blocked by a spid that has its command as DB STARTUP. Suspiciously, I checked the SQL Server logs and there it was showing that one database was still recovering. However, in the object explorer I am able to see that database as online and also I can query the database. I even did some fake updates and truncated some tables too in that database. So, what recovery is exactly going on here? The databases are in AOAG, if that helps.
Comment: What is output of `select @@version`, if you have enterprise edition then you have fast recovery in which database can come online after second phase of recovery and in background third phase can continue. I will add the answer after your revert
Comment: It is an enterprise version. Microsoft SQL Server 2012 (SP3-CU1) (KB3123299) - 11.0.6518.0 (X64)
Answer: As confirmed by you the SQL server is of enterprise version and database was not starting after restore so the recovery process can utilize fast recovery.  In enterprise edition the database would come online after second phase (this is called Fast recovery which was introduced from SS 2005 onwards) and you would see database as online but still internally third phase, the UNDO, phase is going on and would be accessible completely only after third phase completes. What I mean by completely is For fast recovery, a query may bump into one of the locks being held to allow fast recovery – in which case it will have to wait for that lock to be dropped as UNDO progresses
I suggest you also read

When is fast recovery used
3 phases of recovery
Comment: But the DB STARTUP is blocking only one particular spid. Other operations are unaffected. So this means that the lock is there on the objects that the job is trying to alter?
Comment: Can you tell me what is the operation doing which is being blocked by DB startup ?
Comment: It is a step in a job which truncates some tables.  Weird thing is , the DB Startup blocks the job step but it allowed me to truncate those tables manually.
Comment: Can you post the errorlog in the question ?, I need to see information whether database has recovered or not. You can also upload erorrlog on  shared drive and share link in the question.
Comment: @karun10 Are you going to share the output ?
Answer: Just in case someone finds this, each database in an availability group has a redo thread, and the command is always DB STARTUP. In fact, that is how you can identify the redo spid associated with each database - SELECT * FROM sys.dm_exec_requests WHERE command = 'DB STARTUP'.
Additional troubleshooting information is available in the documentation.
Answer: It seems the database is not recovered completely. Please check the SQL server log. Lock will release automatically once database completely recovered.


Mount /tmp on swap in Linux

Question: I have seen this before ... the /tmp directory mounted on swap space. I am aware something similar can be done using tmpfs, but I don't think that what was being used.
I too would like to mount /tmp onto my swap partition without using tmpfs but do not know how.
My (layman's) understanding of tmpfs is that, by default, it uses half the RAM on your system. I also understand that I can be tweaked to use a greater or lesser amount. But can it be configured to use 0 (that is, zero) bytes of RAM but use only available swap partitions? I tried and it did not work for me. But then again, I know very little about this. Maybe some parameters were entered incorrectly.
I like the idea of using swap for an OS temp dir but I do not want to allocate any RAM for this. Is this possible?
Comment: No. It will always use some RAM. If you could use no RAM at all for it then what is the advantage above a regular directory?
Comment: Uhm. You can use swapoff to stop swap. Then format the now unused partition with mke2fs and edit /etc/fstab to mount /tmp on it at the next reboot. -- This will accomplish what you ask, but somehow I doubt it answers what you actually want.
Comment: No, you're right, that's not it. What I want to know is, how can I concurrently use my active swap partition as a tmp directory under a running Linux system.
Comment: OK, maybe this will start to clarify things a bit (I'm a bit new to this Unix thingy): Can tmpfs be used with swap only, that is, without using even a single byte of RAM?
Comment: Thanks Hennes. The advantage for me would be privacy. I was hoping to mount tmp on an encrypted swap. You could use a separate partition for tmp, but I already have four partitions.
Comment: @user1549377: Then simply make an encrypted ext4 partition for `/tmp`. The directory cache is never swapped out anyway.
Comment: You might want to check this out! http://en.wikipedia.org/wiki/TRESOR (Not related to your swap or /tmp, but it's related to security.)
Answer: tmpfs will initially be allocated half the size of RAM, but is is backed by swap space and will swap if memory is low, So it doesn't prevent the system from using all available RAM for other purposes.
I'd recommend simply using tmpfs rather trying something obscure .

Mount /tmp on swap in Linux


How to bookmark a Google Music radio station

Question: I found a radio station in Google Music that I liked. How do I add it to my favourites so that I can listen to it again?
Answer: There doesn't appear to be an option to save a station from the view of the playing song or the view of the playing queue. However, if you go to My Library, and then slide over to the Stations tab, you will find a list of Recent stations. If you select Add to My Library from the ... menu of the station, it will appear in a separate group below Recent stations called My Stations.
Answer: Pull up the station's "homepage" (where it has the station's description and lists artists on the station) and there should be "Add to library" next to "Share".  Click on that.  Now, it will show up in your "Music Library" under My Stations.  This is different from "Saving" the station where it creates a playlist for the station - this is, in effect, bookmarking the station.


Contents of stack area of a process

Question: I've been going through some Unix text books and I can't have a clear picture on the contents of the stack area of the process. Can anyone please explain or point out some references?
Answer: You only get a clear picture of the stack just as the kernel hands off to ld.so, the dynamic linker.  You can find a basic picture here. That shows argc, argv and envp, the traditional 3 arguments to a C program's int main(int argc, char **argv, char **envp).
That view is somewhat simplistic.  An ELF auxiliary vector exists on the stack, too, and conveys a lot of information to ld.so
After ld.so runs, the libc runtime steps in and complicates things. C++ constructors can be run, all kinds of crazy stuff can end up on the stack.  It depends on what compiled the program.  Even simple C programs can do different things based on what library they got compiled with.
Answer: This wikipedia article is fairly concise.  If you google "stack vs. heap" you'll find a ton of stuff; generally they are explained in relation to one another.
If you don't do any programming, this is not a particularly useful or important thing for you to understand.  If you do, then it is; one place most people first encounter the significance of the stack is WRT recursive calls; a more detailed wikipedia article relevant to this regards the call stack.  The call stack is what occupies the "stack area of a process"; it holds data local to function calls, and data for nested or recursive function calls are "stacked" on top of each other in LIFO ordering.
If you haven't done any programming in a language that allows for direct memory addressing (e.g. C/C++), understanding how memory addresses map regions of memory is important, hopefully your textbooks have already been through this.
Answer: Programs typically push function arguments onto the stack, before using the asm CALL instruction to call the function, which pushes the return address onto the stack, so that the RET instruction can later pop it back off and know where to return to.  A function also will typically place its local variables on the stack.  The calling function also may push any registers it is using onto the stack before making a call so it can pop them back after the called function has used those registes for something else.
A visual representation of the words on the stack where functionA has called functionB might look like this:
local1
arg1
functionA+12
local1
local2

Here functionA had a local variable, and then passed an argument to functionB, and stored the return address ( 12 bytes after the start of functionA ).  Then functionB put two of its own local variables on the stack.  If functionB calls functionC, then the stack continues to grow, and then it shrinks again as functions return.

Contents of stack area of a process


Why is this group of matrices isomorphic to the dihedral group?

Question: I am reading Abstract Algebra, Theory and Applications by Judson and in exercise $13$ chapter $9$, Isomorphisms, I need to prove that the set of matrices $$A=\pmatrix{ \omega & 0 \\ 0 & \omega ^{-1}} \qquad B=\pmatrix{ 0 & 1 \\ 1 & 0}$$
Where $\omega = e^{2\pi i /n}$ form a group isomorphic to $D_n$ (dihedral group). I know how matrices work to reflect and rotate objects in a dihedral group, and I know that $$R=e^{2 \pi i /n} =\pmatrix{ \cos (\frac{2\pi i}{n}) & -\sin (\frac{2\pi i}{n}) \\ \sin (\frac{2\pi i}{n}) & \cos (\frac{2\pi i}{n})}$$
I can also see that $A^k$ will yield all the rotations I need, reaching the identity rotation with $A^n$, and I can see that multiplying by $B$ allows us to reach the reflections. It is clear that $A$ and $R$ are related, and even though it seems very logical, I cannot prove it. How are these two groups isomorphic?
Comment: What description of $D_{n}$ is available to you?  Do you have a group presentation for it, or do you understand it purely in terms of physically-performed manipulations of the regular polygon of $n$ vertices inscribed in the unit disc?
Comment: i have a group presentation for it in terms of $R$ and $B$ (matrices in my post)
Comment: Well, it looks like you ought to make your homomorphism so that it maps $A$ directly onto $R$ and maps $B$ directly onto $B$.
Comment: Hmm, yes, I can map $\omega$ to $R$ but I can't map $A$ to $R$
Answer: One way to show that the group $\langle A,B\rangle$ is isomorphic to $D_n$ is, to show that it has the presentation
$$
\langle A,B\mid A^n=B^2=I, AB=BA^{-1}\rangle,
$$
which is just the presentation of the dihedral group $D_n$. A short computation shows that this is the case.


How to search lines which don't contain an empty line before the return statement

Question: I would prefer to have an empty line prior to the last return statement of any Java method. How do I find and replace such lines using Eclipse?
public int foo() {
    ...
    ...

    System.out.println("end of foo");
    return 1;
}

In this case , I would prefer an empty line before the return statement, do note that there could be any statement before return. How do I find and replace in such occurences.
Answer: You could use a regular expression to search for the pattern "; *\n[ \t]*return" and replace the \n with 2 \n characters
Check out this overview of regular expressions in java (only if you need it. You could be a regexp pro for all I know ;) )
http://www.regular-expressions.info/java.html
Answer: You can go to Window -> Preferences and expand the trees Java -> Code Style -> Formatter and change/enforce many rules, but I don't think you can check/enforce a new line before 'return' as a built in option in Eclipse.
Instead you'll have to follow Josiah's advice and write your own nifty check-style tool (which are really fun to have).


Are racial bonuses added to stats at creation, or applied to rolls as modifiers?

Question: Would a Dwarf's +2 to constitution be added to their ability stat, or just their modifier when making a roll?
Answer: It's added to the ability stat.
If you are using point buy then any racial bonuses are added at the end. If you are rolling then you add the bonus after assigning each roll to a particular ability.
This would typically provide a +1 bonus to CON based rolls.
Answer: It is added to the base score during character creation, after initial ability scores are decided (Or race change with Reincarnation or something). It is an untyped, inherent increase, not a bonus. It is treated as if the ability score started that high during ability score determination and it should not be written on the character sheet as a bonus.
If you have 14 CON and choose to be Dwarf, your CON is now naturally 16, not 14+2 bonus.
Comment: No, it's 14+2 racial.  See [the common terms entry for 'bonus'](http://www.d20pfsrd.com/basics-ability-scores/glossary/#Bonus).  It's *certainly* not 'inherent'; inherent is the bonus type granted by e.g. Wish and doesn't stack.  Racial bonuses *do* stack, which means they may as well be untyped for most purposes, but they *are* a bonus type and not an increase to the base score.
Comment: Those Racial bonuses you speak of refer to things like the skills and saving throws granted by the race. The ability score increase is not a racial Bonus.
 *"Dwarves are both tough and wise, but also a bit gruff. They gain +2 Constitution, +2 Wisdom, and –2 Charisma" *
compared to
 *"Hardy: Dwarves gain a +2 racial bonus on saving throws against poison, spells, and spell-like abilities."*
Comment: "bonuses granted to ability scores with one of these qualities count as racial bonuses for the purpose of qualifying for racial trait prerequisites."  Oh, wait... I guess that says 'counts as' not 'is'.  Well, alright then.
Answer: Ability modifiers in general, and racial ones in particular, affect your ability score, not just rolls that depend on it.  So for stats like Con and Str, where individual ranks matter for derived stats, you would benefit from an increase to those derived stats in addition to the bonus on rolls.


What are the primary differences between Ethiopian and Eritrean food?

Question: As far as I can tell based on restaurants in the US, the cuisines of Ethiopia and Eritrea are quite similar. Are there any characteristic differences between the two, or dishes that belong strongly to one and not the other?
Answer: I asked my friend who's written a cookbook adapting traditional ethiopian cuisine for vegetarians, here's what he told me.
Ethiopian and Eritrean food are basically identical. They were the same country until the early 90s, so that's not too surprising, I guess. In both countries, wats are common and are eaten with teff-based injera. Berbere is a primary seasoning in both countries. He said the only differences are due to climate: Eritrea is at a lower elevation, so the food there uses more warm-weather vegetables like tomatoes, eggplants, etc. while Ethiopian cuisine might have more carrots, for example.
However, he did point out that "Eritrean" restaurants he'd been to in the US (specifically, in the Bay Area) were actually closer to what he would consider Ethiopian food anyway, which may explain your experience: you may be eating Ethiopian food at an Eritrean restaurant. Of course, since the cuisines are so similar, this is like going to a "Western New-Mexico" restaurant in China and being served (gasp) "Eastern New-Mexico" food--not too surprising, in any case.
Comment: Great, thanks for the insight! One of the reasons I asked is that a commenter on my blog said that Eritrean food tends to be somewhat more influenced by Middle Eastern / Muslim traditions, but it doesn't sound like that is your friend's experience. By the way, what is the name of your friend's book, sounds like it would be of a lot of interest to me.
Comment: @Michael: Unfortunately it's not yet published. The copy I have is an electronic rough draft. As my friend is heading back to Ethiopia this weekend for about three years, it may be some time before it comes out.
Answer: Lots of differences.... the spice and the way of cooking... and Ethiopians almost have no tomatoes... actually they don't use tomatos - it is mostly onion based. While Eritrean food has tomatoes and onions and we don't use that much butter and that spicey butter. Actually, Eritreans mostly use the butter when making meat dishes.. otherwise we just use oil.
What we have in common is the inerjera based food and sister sauces that are made differently .... specially the lentil sauce, the chicken sauce, the classic meat sauce, and allicha (cabbige sauce)... Other sauces the Ethios have that we don't have, and we have that they don't have. F.eg we never put meat in vegetables... like never.. they do. WE have hilbet (the best Eritrean food in my opinion), they don't have that.
Though similar on the outside, it is actually quite different experience eating Ethiopian vs Eritrean. The Ethios might miss their food among Eritreans, and the Eritreans miss our food among Ethios. They taste very very different...
We were the same country only in the 30 years by American force... I'll tell you one thing, it never affected the food.


Jenkins: use ssh-agent and git plugins together

Question: So, I have the following situation: a server with dedicated users for each project (e.g. foo) and a jenkins server which runs as a jenkins user.
I've generated an SSH key pair for my foo user and added the public one as a deploy key to a github repo. (I verified I can clone the repo with the foo user)
In Jenkins I setup authentication in "Manage Jenkins" > "Manage Credentials" as a "SSH username with private key" with Username "foo" and foo's private key in a "Global" scope.
So I configured my Jenkins job with the correct workspace (e.g. /home/foo/deployment with full ownership for user foo obviously) and using the credentials "foo". For "Source code management" I wanted to use the SSH URL of my repo (e.g. email@example.com:foo/foo.git)
However it immediately notifies me there's a permission problem:
Failed to connect to repository : Command "git -c core.askpass=true ls-remote -h firstname.lastname@example.com:foo/foo.git HEAD" returned status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

If I use the https version of the URL (https://github.com/foo/foo.git) the error disappears, but when I run the job I get the following errors in the console output:
Started by user developer
[EnvInject] - Loading node environment variables.
Building in workspace /home/foo/deployment
Cloning the remote Git repository
Cloning repository https://github.com/foo/foo.git
 > git init /home/foo/deployment # timeout=10
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init /home/foo/deployment
    [long stacktrace]
Caused by: hudson.plugins.git.GitException: Command "git init /home/foo/deployment" returned status code 1:
stdout:
stderr: /home/foo/deployment/.git: Permission denied
    [long stacktrace]
ERROR: null
Finished: FAILURE

The key pair doesn't use a passphrase, I'd like to add one though if I get this working first.
Jenkins runs on a Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-65-generic x86_64) box.
What am I missing here? It appears the credentials I provided aren't being used, which explains why it explodes on permissions. But I don't understand why they're not being used? And why can't use the git@ URL?
Since it chokes on a permission problem with git init I ran that manually in /home/foo/deployment, but rerunning the Jenkins job it chokes on git fetch, again with permissions problems.
Answer: Ah yes, very silly me. The SSH user agent obviously only allows the jenkins user to connect to the remote repo as foo, but doesn't grant it permissions to write to the local file system...


Is the game world interconnected?

Question: Can you revisit all areas? If not, how many separate areas are there in the game and when permanent transitions happen (consider using spoiler tags)?
Collectables would be lost when moving to a new location. I'm well aware that RE7 isn't an "open world" game, i.e. sandbox - I want to know if the world is interconnected like in Dark Souls, for example.
Comment: If its collectibles you're interested in, just ask about that. We have lots of questions asking us if there are missable collectibles.
Comment: @Frank: I'm not asking about collectables. See my updated answer, in Dark Souls the interconnected world is one aspect that defines the game.
Answer: This is not what I would describe as an 'open world game' at all. There are a number of different areas, some of which are reasonably sizeable. However, there are multiple points where you are prevented from re-visiting an area you have previously been to.
In short, no you cannot revisit all areas.
Now for the specifics:
The main sections of the game are as follows:

 Guest House

 Main House (plus the other areas around the main house, e.g. old house, proving ground)

 Ship

 Salt Mines

 Guest House (re-visited)

The points of no return are as follows:

 Although you return to the Guest House at the end of the game, it's not the same as at the beginning. You cannot go back directly from the Main House

 When you reach the Ship, you can no longer return to the Main House area

 When you reach the Salt Mines, you can no longer return to the Ship

 And finally, once you are back in the Guest House, you cannot go back to any other area.
Comment: @user598527: Yeah I rejected it because the formatting didn't look good. I see what you mean, but I just think your formatting made it unreasonable. I will see if I can work something out... sorted!
Comment: Could you separate areas and list them in the order of appearance? How many "points of no return" are there?
Comment: They are listed in the correct order. I was having trouble combining the spoiler tag with any sort of nice formatting. That why it looks so bad, im not sure how to improve it while keeping the spoiler block to be honest
Comment: I edited the post to avoid exposing users to all spoilers at once. I personally wouldn't want to see all areas in advance and would have checked the first only. - I didn't found a better markdown solution if that's the issue.

Is the game world interconnected?


How does voice affect a sound wave or its corresponding waveform?

Question: Someone in the physics stack exchange told me to come here for this question. My question is how does a person's voice affect how a soundwave looks? For example, if I say the letter "a" it would sound different than if you said the letter "a", but my question is if there is a pattern to this, or maybe if we are able to derive a waveform based on voice (however it would be affected by multiple other factors due to when I say "a" it is different than when I say "b").
Answer: I would view it as the following:
The letter A is the input to a system, one is your vocal chords the other one mine. Since the system response of your and my vocal chords are different, we would get different outputs.
Now, what would characterize the system response, it would be factors like, rise time/bandwidth, decay response etc. All of this would impact the tone and pitch terminologies usually used in audio/speech. These variables will vary for each user. With different input the response will then also be different . So "b" will not be same as "a"
Comment: Yes, so my question is whether it is possible/ how to get the function that turns that input into an output for a certain voice. Or perhaps to create a default "voice" that we can get a function to transform it into a certain voice.
Comment: The research of Stylianou allowed for turning the voice of a young woman into eg an elderly woman: https://www.cs.cmu.edu/~pmuthuku/mlsp_page/lectures/Stylianou_VC.pdf
Answer: Someone wrote that spectrograms were introduced to help deaf and hearing-impaired to "read" speech. Unfortunately, it is quite hard to interpret what is being said from a spectrogram, but I am told that a few people (working in speech recognition?) are able to.
Depending on the speech source, the recording quality and the parameters of the spectrogram, you should be able to clearly identify "pitched" sounds ("a", "z") by the comb-like horizontal structure of harmonics. A male speaker would typically have a deeper voice, apparent as a shift towards lower frequencies. Fricatives like "s" and "t" will appear like wide-band, unstructured "noise" with some temporal and frequency limits.
It is obvious that there is some general pattern transcending the individual: I am able to listen to you talking and comprehend what you are saying, and so is automatic speech recognition. I do believe that I am more robust with talkers that I know, or talkers that belong to "my" kind of dialect. Thus individual deviation does matter.
https://en.wikipedia.org/wiki/Spectrogram
Answer: Well in one sense Voice is the soundwave.
But I think you are asking about accent or individuals pronunciation vs the the idealized sound abstracted from accent or specific pronunciation.
So you could just compare two voices, or try to compare one voice to an abstract ideal.  Even for saying "A".
I think the signal of speech is so complicated your question can't be answered.


I sent my Bitcoin from Coinbase Wallet back to my coinbase wallet address. I basically sent it to myself but can't get access to it

Question: I tried sending my Bitcoin from my coinbase wallet address to my cash app Bitcoin account but accidentally copied and pasted the Coinbase Wallet address instead of the cash app Bitcoin account. So basically I sent back to myself. It's confirmed but I don't have access to the funds. I see it but can't touch it. Coinbase Wallet support has led me on for a month and won't help. Can someone please help me. That's my wedding money.
Comment: This is a community forum, we have no sway over any companies interactions with you. It sounds like you've done something that has potentially lost your money administratively (sending "back" to an address isn't something that happens in bitcoin), but nobody else can help you with that.
Answer: Sending Bitcoin back to your own address should just give you an error, nothing would be lost on-chain.  This is probably an internal Conbase error they should have coded their system to recognize and reject.
Conbase Support Level 1 is extremely understaffed, undertrained, likely is overloaded with requests, and probably does not understand the issue in the first place.  You need to escalate to a Level 2 or 3 rep who can dig into the Conbase system and get your Bitcoins back.  Level 1 support likely cannot assist you.  Not because they are incompetent, but because Coinbase is not properly equipping them to do their job, with low staffing levels and poor training
I highly doubt your transaction was actually posted to the Blockchain, meaning you never lost any funds. This is an internal issue to Conbase
I recommend taking the issue to social media if you are getting clogged up at Tier 1 support, a social media manager may see the bad publicity and be able to get you connected with a higher level support rep.  Try talking to some of the Coinbase competition, such as eToro, iTrustCapital, RocketCoin, or MyDigitalMoney.  They can not do anything to recover your funds, but they may (may!) smell some cheap PR, and reimburse you with some of their own Bitcoins, to prove how unreliable Conbase is, and how reliable they are, if you can provide proof that you have tried and failed for months to get anywhere with Conbase.  If I was them, that is what I would do!  Just a suggestion
Also, ALWAYS keep coins in your own hardware wallet, never leave them sitting in an exchange, for this exact reason!


Change laptop monitor aspect ratio

Question: I am trying to play Myst IV on my laptop in Windows 7 with a recommended resolution setting of 1920x1080. However, the game has a different aspect ratio, so everything is slightly "wider" than it should be. Is there any way to force either the program or windows to run with a different aspect ratio, displaying two vertical black bars on the left and right sides of my display? I've tried setting the compatibility settings to use "640x480" resolution but it still seems skewed. I noticed in the game's graphics menu, the largest setting is 1024x768, so I think that's the ratio I need. I could try a vm, but I don't have a windows install disk.
Answer: I discovered I could change the scaling and aspect ratio in my graphics card (NVIDA) Control Panel.

Change laptop monitor aspect ratio


Is there a term for when you complain about something, and then it just starts working right?

Question: I often find that when working with different forms of technology it breaks then when you have someone watch it or complain to someone it works. Is there a term for this?
Comment: The program crashes when I do [something]. Let me show you. Program does not crash. But, "It worked before"!
Answer: There's heisenbug, a pun on physicist Werner Heisenberg and the observer effect, a phenomenon whereby observing a system causes its behaviour to change.
Answer: I don't know of an existing name, but I'll make one up:
Cheshire cat bug
This comes from Lewis Caroll's character, the Cheshire cat, who disappeared and reappeared from time to time.


Why does Edinburgh Castle's one o'clock gun fire at 1pm instead of, say, noon?

Question: Curious to know if there is a specific reason they fire it at 1pm. Noon would make more sense to me!
Comment: If it was fired at Noon they would have to change the name to Noon  Gun ;)
Comment: How is this not a trivial question?
Comment: Citadel Hill in Halifax (Nova Scotia) has a Noon Gun.
Answer: Edinburgh Castle's tourist attraction, the One O'Clock Gun, originated as an audible version of the Nelson Monument time ball. The Nelson time ball has dropped at 1:00 pm ever since it was installed in 1853. Accordingly, the One O'Clock Gun also fired at 1:00 pm. Anything else would have been potentially confusing.
Time balls were important for maritime towns as a means for ships to set their clocks to the correct time. This was important for maritime navigational purposes.
In England, time balls typically dropped at 1:00pm. This seems to have begun with Greenwich, which dropped its time ball at 1:00pm from 1833 on, because its astronomers would've been busy with observations at noon.

One o'clock was chosen as the perfect moment, in order to give the astronomer time to finish his noon observations before the ball was dropped.
 -  Dibdin, Tim. Time out guide: Edinburgh, Glasgow,
  Lothian and Fife. Penguin, 2000

It would have made sense for all the port cities to pick the same time for updating clocks, so as to prevent confusion.
Comment: "Astronomers were busy at noon". Great answer.
Comment: @T.E.D. Perhaps such discussions could be moved into a chat room instead, so passerbys could still read it if they feel so inclined.
Comment: Excellent answer, could not for the life of me figure out why it was at 1pm rather than noon, clears it up nicely!
Comment: Deleted a very interesting (but OT) discussion about the creation of standard time. That might be good fodder for a question, if asked properly.


How to determine the accuracy of a multiple linear regression model?

Question: I searched a method to determine the  accuracy of a linear regression model. I found that I should calculate r-squared. Is this the only method or are there other methods?
Answer: The coefficient of determination, $R^2$, measures how well your model is fitting to the data, or the other way around. But if you want to make predictions with your model, then $R^2$ doesn't tell you much about the accuracy of the predictions.
Using (Cross) Validation is one way to measure the accuracy of such kinds of predictions. The idea is as follows: Randomly select one or more of your data points which you set aside and not use to fit the parameters of the model. Then, build your model and given the x-value of the data point(s) set aside, predict its y-value using the model. You can then calculate the prediction error and compare different models. Usually, you calculate the mean of the squared error. Cross Validation is an extension of this idea where you compute several models, say, 5, leaving out different 20% of the data points to build a model.
Other techniques to see if the model is behaving sensibly are related to the analysis of the residuals (difference between actual y-value and model's y-value) of the data points used to build the model; you can find an overview here.
Comment: cross-validation is a method of validation, I already used it in the validation(I use the weka multiple linear regression to build my model). Weka gives me as output correlation coefficient but I would like to calculate the accurucy
Answer: @Roland is right. If you were looking for a more succinct answer, you have to compute the scores from your predictions using Weka, with many different cross-validation sets, average them, and compute the standard deviation. This will give you the accuracy and +/-.


Optimizing the inverse of a symmetric matrix with 3 non consecutive diagonal terms

Question: Let $A$ be a $200x200$ matrix that is symmetric and has 3 diagonal terms.  It is like a tridiagonal matrix but the diagonals are non-consecutive. Or like a banded matrix with bandwidth 100 but with zeros in between. The shape of the matrix is more clearer when shown using spy(A) in Matlab: Shape of the matrix
I want to compute the inverse in a very efficient way since I am running a code in real-time. Performing the regular inverse (using Eigen3 library in C++) takes around 0.3s and it needs to be less than 0.1s.
$A^{-1}$ is also symmetric and has the exact same shape. This leads me to believe that there must be a property or a way to calculate the inverse more efficiently. However, it seems like $A$ does not match any standard type of matrix (not banded matrix, not tridiagonal...) apart from being symmetric. The Cholesky decomposition does not help at all.
Does anyone know if there is a standard equation or algorithm or property to calculate $A^{-1}$. Thanks so much!
Answer: After a lot of research, I found a post that answers exactly my question. Thanks anyway!
enter link description here


Unable to get 3.5 inch touchscreen to work with Pi 3B

Question: I am unable to get my Pi 3B to work with a 3.5in RPI Touchscreen LCD v3.0. I have NOOBS and the Raspbain OS Image downloaded to my micro SD Card. All it does when I set it up is turn white. What is the problem?
Comment: can you attach a photo of how you have it setup? and maybe include a link to where you bought the screen? also does the pi work when connected to a monitor?
Comment: I had the same problem, except it was with a TFT, not an LCD. Can you attach a picture of the **back** of the screen? PS. I know this isn't an answer, but I can't comment unless I have 50 rep.... (where's the logic SE?)
Answer: Depending on what LCD screen you have, the following may work. First check if the display looks like the picture here. There are many cheap clones of these available on Chinese sites. If it looks similar, first download the correct driver:
For 2016-May-10-raspbian-jessie or later:
wget http://www.waveshare.com/w/upload/2/24/LCD-show-160520.tar.gz

For older jessie versions:
wget http://www.waveshare.com/w/upload/3/37/LCD-show-151102.tar.gz

After downloading do the following:
tar xvf LCD-show-160520.tar.gz
cd LCD-show/
sudo ./LCD35-show

It will reboot and if you are lucky you might have a working display.


Memory errors and list limits?

Question: I need to produce large and big (very) matrices (Markov chains) for scientific purposes. I perform calculus that I put in a list of 20301 elements (=one row of my matrix). I need all those data in memory to proceed next Markov step but i can store them elsewhere (eg file) if needed even if it will slow my Markov chain walk-through. My computer (scientific lab): Bi-xenon 6 cores/12threads each, 12GB memory, OS: win64
  Traceback (most recent call last):
  File "my_file.py", line 247, in <module>
    ListTemp.append(calculus)
MemoryError

Example of calculus results: 9.233747520008198e-102 (yes, it's over 1/9000)
The error is raised when storing the 19766th element:
ListTemp[19766]
1.4509421012263216e-103

If I go further
Traceback (most recent call last):
  File "<pyshell#21>", line 1, in <module>
    ListTemp[19767]
IndexError: list index out of range

So this list had a memory error at the 19767 loop.
Questions:

Is there a memory limit to a list?
Is it a "by-list limit" or a
"global-per-script limit"?
How to bypass those limits?
Any possibilites in mind?
Will it help to use numpy, python64? What
are the memory limits with them? What
about other languages?
Comment: If you get an unexpected Memory Error and you think you should have plenty of RAM available, it might be because you are using a 32-bit python installation.
Comment: Large _and_ big! Wow! Good thing you've got so much memory!
Answer: First off, see  How Big can a Python Array Get? and Numpy, problem with long arrays
Second, the only real limit comes from the amount of memory you have and how your system stores memory references.  There is no per-list limit, so Python will go until it runs out of memory.  Two possibilities:

If you are running on an older OS or one that forces processes to use a limited amount of memory, you may need to increase the amount of memory the Python process has access to.
Break the list apart using chunking.  For example, do the first 1000 elements of the list, pickle and save them to disk, and then do the next 1000.  To work with them, unpickle one chunk at a time so that you don't run out of memory.  This is essentially the same technique that databases use to work with more data than will fit in RAM.
Comment: A 32-bit process has a theoretical limit of 4 GB of memory, though if your OS is also 32-bit it will obviously be less since the OS will take up some of that memory.  Chunking will slow you down, but in some cases you have to accept a slow-down just to finish processing.  What are you storing in that list?  Maybe that would help explain what's happening.
Comment: [source](http://stackoverflow.com/questions/855191/how-big-can-a-python-array-get/855455#855455) _Therefore the maximum size of a python list on a 32 bit system is 536,870,912 elements._ Okey, but in my case, I'm far this value, my memory is only of ~1.3 Gb on this process (near the limit of a python32 process?). What will be the limit in python64? How chunking will be slow my markov chain walkthrough? Thanks @ all for your answers and advices. Nice place to learn!
Answer: The MemoryError exception that you are seeing is the direct result of running out of available RAM. This could be caused by either the 2GB per program limit imposed by Windows (32bit programs), or lack of available RAM on your computer. (This link is to a previous question).
You should be able to extend the 2GB by using 64bit copy of Python, provided you are using a 64bit copy of windows.
The IndexError would be caused because Python hit the MemoryError  exception before calculating the entire array. Again this is a memory issue.
To get around this problem you could try to use a 64bit copy of Python or better still find a way to write you results to file. To this end look at numpy's memory mapped arrays.
You should be able to run you entire set of calculation into one of these arrays as the actual data will be written disk, and only a small portion of it held in memory.
Comment: Hello Thomas, I think you are right, I must overflow the 2GB per programm imposed by my python32 on my windows-7-64b. What will be the limit for a python64 programm? thanks
Comment: Significantly more than the physical memory in your machine, since you're squaring the size of the address space by moving to 64 bits :)
Comment: @ncoghlan is right. If you follow the link in the second row the limit is mentioned. Which is a whopping 8TB. If you hit that limit then your definitely doing something wrong :)
Answer: There is no memory limit imposed by Python. However, you will get a MemoryError if you run out of RAM. You say you have 20301 elements in the list. This seems too small to cause a memory error for simple data types (e.g. int), but if each element itself is an object that takes up a lot of memory, you may well be running out of memory.
The IndexError however is probably caused because your ListTemp has got only 19767 elements (indexed 0 to 19766), and you are trying to access past the last element.
It is hard to say what you can do to avoid hitting the limit without knowing exactly what it is that you are trying to do. Using numpy might help. It looks like you are storing a huge amount of data. It may be that you don't need to store all of it at every stage. But it is impossible to say without knowing.
Comment: You can also use a swap file on linux. Taken from the Arch Wiki:
`# touch /swapfile`
`# fallocate -l 512M /swapfile`
`# dd if=/dev/zero of=/swapfile bs=1M count=512`
`# chmod 600 /swapfile`
`# mkswap /swapfile`
`# swapon /swapfile`
`# echo "/swapfile none swap defaults 0 0" >> /etc/fstab`
Comment: Python, like any other program, uses the entire virtual memory, not just the physical (RAM). The poster can increase the swap memory available (which is a file in Windows and a partition in Linux).
Answer: If you want to circumvent this problem you could also use the shelve. Then you would create files that would be the size of  your machines capacity to handle, and only put them on the RAM when necessary, basically writing to the HD and pulling the information back in pieces so you can process it.
Create binary file and check if information is already in it if yes make a local variable to hold it  else write some data you deem necessary.
Data = shelve.open('File01')
   for i in range(0,100):
     Matrix_Shelve = 'Matrix' + str(i)
     if Matrix_Shelve in Data:
        Matrix_local = Data[Matrix_Shelve]
     else:
        Data[Matrix_Selve] = 'somenthingforlater'

Hope it doesn't sound too arcaic.

Memory errors and list limits?


How do you create a shallow copy of an Array in ActionScript 3

Question: var a:Array = ["a","b","c"];

var b:Array;

/* insert code here to copy 'a' and assign it to 'b'*/

Comment: You're in luck: shallow copy is trivial, it's deep copy that requires a big chunk of code thanks to Arrays not being typed collections :-)
Answer: Taken from the As3 reference guide:

The Array class has no built-in
  method for making copies of arrays.
  You can create a shallow copy of an
  array by calling either the concat()
  or slice() methods with no arguments.
  In a shallow copy, if the original
  array has elements that are objects,
  only the references to the objects are
  copied rather than the objects
  themselves. The copy points to the
  same objects as the original does. Any
  changes made to the objects are
  reflected in both arrays.

Concat would be the way to go if you choose between concat and slice since concat is faster in terms of performance.
Read more about the subject here: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ee7.html
To clarify:
    private function shallowCopy():void{
        var a:Array = ["h", "e", "l", "l", "o"];
        var b:Array = a.concat();

        trace("Shallow copy:");
        trace("Before delete: " + a);
        trace("Before delete: " + b);
        delete a[0];
        trace("After delete: " + a);
        trace("After delete: " + b);
    }

Comment: Your deepCopy() function is not doing a deep copy, you're copying nothing but the reference to the Array itself  (i.e. it's not an array copy at all). In AS3, a deep copy requires looping over the contents of the array, and manually constructing new objects of matching type and then copying their values. var b:Array = a; just creates a new reference to your Array a.
Comment: I keep forgetting that AS3 is a superset of Javascript. Thanks
Comment: Then I most have misunderstood the concept. I'll remove the code :) Thanks for pointing that out to me!
Comment: A deep copy would be one where any objects referenced in the array get cloned and the clones are referenced at the corresponding point in the new array. Because objects can--and usually do--have references to other objects, you can see how this could be fixed depth, or fully recursive. But it's a nastier problem than recursively cloning everything, because you might have two objects in your array (A and B) both referencing C. When you do the deep copy, Aclone and Bclone should reference the same Cclone, not two new clones of C. That's why I said to Gareth that he's asked the easy question :-)
Comment: You can find an implementation of a deep copy [here](http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ee7.html)
Answer: The line in question:
var b:Array = a.concat();

Answer: If the array contains just string or number values, it's enough to make a "shallow" copy, as described by Adam and rzetterberg.
If the array contains other arrays or objects/class instances, etc. then you should make a deep copy if you need all of the objects inside to be unique as well and not just references. You can achieve that with:
var ba:ByteArray = new ByteArray();
ba.writeObject(a); // Copy the original array (a) into a ByteArray instance
ba.position = 0; // Put the cursor at the beginning of the ByteArray to read it
var b:Array = ba.readObject(); // Store a copy of the array in the destination array (b)
ba.clear(); // Free memory

This is also useful for copying Objects, which don't have any concat or splice methods.


How to start with receipt OCR text detection

Question: I'm thinking about an OCR system for digitalizing receipts. On the input system would take a picture of receipt and then return classified data (total_sum = Y, date = X, etc.). My question is regarding how to start. My initial thought was that I should start with detecting classes (name of the shop, receipt id etc.) on image and splitting it, then I would send parts of image OCR. My second idea is more NLP based. I would normally pass an image to OCR system and then try to do some classification on text data. Which approach would be better?
Answer: Not sure if you tried Tesseract or pytesseract yet. I never worked on receipts but I had a different use case where I needed to segment images before I applied the tesseract for text recognition. For simple use case and especially in English, tesseract is quite powerful so I would start with the 2nd option first and see if it's good enough. Probably you may look at this answer on stackoverflow for idea.  https://stackoverflow.com/questions/55140090/pytesseract-reading-receipt