Confusion about Zarlino and his assertions about the diatessaron (perfect fourth)

Question: In Part Three of Gioseffo Zarlino's "Le Istitutioni Harmoniche", "The Art of Counterpoint", Zarlino argues that the diatessaron (or perfect fourth) is not a dissonance, as the musicians of his time had relegated it to, but a consonance. He defends this assertion (only in part, although I won't be discussing the other arguments here) by stating:

An interval that has a rational proportion between high and low pitch is consonant, as is shown in the definition of the philosopher [Aristotle] given in Chapter 12 of the second book [Posterior Analytics]. Therefore the fourth, having such a proportion, is consonant. A minor proposition is demonstrated by Philoponus, who, adding to the philospher's definition in the Second Book of the Poteriora, calls the sesquitertia (which is the true ration of the fourth) a rational number.

Zarlino verifies his second premise (that the fourth has a rational proportion) with Philoponus's statement that 4:3 (the ratio of the fourth), or the sesquitertia, is a rational number.
My first question is, is it safe to assume that by an interval with a "rational proportion", Zarlino means an interval that is a rational number, or is this a conflation on his part? If it is the case that he does mean this, what is his definition of a rational proportion/number? It cannot be synonymous with the modern definition (a number that can be made by dividing two integers), as dissonant intervals of every conventional tuning system in Europe at the time (as far as I know) would also be consonant because they are rational (albeit ugly) numbers. Can someone clear this up for me?
Answer: What Zarlino (by way of the Greeks) is talking about is proportions of small integers. The octave, for example, has a ratio of 2:1; the fifth 3:2. Zarlino is arguing that since the fourth has a ratio of 4:3, it, too, like the fifth and octave, should be considered a consonance.
So even though other intervals are "rational" in the modern mathematical sense, the concern for Zarlino (i.e., the Greeks) was ratios of small integers.
Unlike the Greeks, who put primacy on the numbers 1 - 4, Zarlino centered his harmonic theory around the numbers 1 - 6, the senario. Those digits are capable of producing all of the just-intoned consonances:

2:1 (octave)
3:2 (fifth)
4:3 (fourth)
5:4 (major third)
6:5 (minor third)

Other intervals (seconds and sevenths) could be calculated as derivations from the above.

Zarlino's whole theory of consonance, then, is related to a series of  six numbers, from one to six, or the arithmetical series 1:2:3:4:5:6....  This is really an extension of the Pythagorean system.... Zarlino calls his series the Senario. Therefore,

Delle proprieta del numero Senario et delle sue parti et come tra loro si ritroua la forma d'ogni consonanze musicale.

TRANSLATION: From the propositions of the number Six and from its parts and the relation between them is found the form of every consonance.1

1 Robert W. Wienpahl, "Zarlino, the Senario, and Tonality", Journal of the American Musicological Society Vol. 12, No. 1
(Spring, 1959), p. 30. (Accessed 26 Jan 2021.) See also Benito V. Rivera, "Theory Ruled by Practice: Zarlino's Reversal of the Classical
System of Proportions", Indiana Theory Review 16 (), pp. 145 - 170, which includes some discussion of the contemporaneous controversy, specifically with regard to "his former pupil Vincenzo Galilei"; Ross W. Duffin, "Theoretical Background" discusses the derivations of the various intervals.
Comment: It may be helpful to include the concept of *senario* here.
Comment: @MichaelCurtis Updated the post. In particular, see the footnote, which links to a paper with some discussion of the controversy.
Comment: @MassimoAsteriti Please see the current update, which includes, at Richard's suggestion, discussion of the "Senario", which explains why Zarlino didn't include 9:8.
Comment: It's not part of the OP, but why did Zarlino's contemporaries disagree with him?
Comment: I understand that Zarlino is talking about the proportions of small integers; I'm still confused about his definition of "rational proportion". What makes 2:1, 3:2, and 4:2 rational proportions, but not 9:8, for instance?
Comment: Thanks so much for the clarification! I understand now.
Comment: @Aaron, thanks for those additions. "Senario", that's very helpful.
Answer: The fourth gets a funny treatment in music theory. Acoustically, as the inversion of the fifth, it acts like a consonance. However, for some reasons that I'm not sure of, the fourth is treated as a dissonance against the bass note but a consonance between upper voices.
One explanation that I have read is that a fourth (in two-part harmony) tends to indicate a 6-4 chord. The interval of a fourth existed before the 6-4 chords were thought of as chords so that explanation seems anachronistic. More numerology suggests that the fourth obtained from the harmonic series on C is the G-C in higher harmonics. The idea is that the C (upper note of the fourth) is the root of the interval.
I prefer just to observe the treatment; a fourth against the bass is treated as a dissonance; a fourth in upper voices is treated as a consonance. This may be a culturally (or at least stylistically) determined preference.
Comment: It's mainly because the root is in the overtone series of the fourth rather than the other way around.
Comment: The minor third doesn't occur either. Riemann had an "inverse" or "negative" version of these intervals through using undertones. The fourth is still the oddball. It's the only interval which has a different treatment than its inversion does.
Comment: *Acoustically, as the inversion of the fifth, it acts like a consonance. However, for some reasons that I'm not sure of, the fourth is treated as a dissonance against the bass note but a consonance between upper voices.* Maybe this is the explanation: In the development of polyphony  history we had first the organum the parallels of fih^fths  or fourths, In this setting fourths have been considered as consonants. But when the harmony was developed from triads the fourth was conceived as a suspended third and thus as dissonant.


How to intercept uploading of email attachments with a Firefox XUL extension in outlook.com web mail

Question: I have a XUL extension which uses a native Windows DLL and js-ctypes to encrypt files inside the local file system. I have already tested a menu driven version of it and it seems to work fine.
Now I would like to do the following: When creating a new email with attachments, be able to "catch" the attachment file and process it (meaning: encrypt it) before uploading to the composed email message. I would like to do it in a transparent fashion so the user does not have to go through the menu driven process except for providing the password for encryption.
I want to do this inside the outlook.com web based email (not Office version).
I know it is a long shot, but does anybody have an idea on where to start looking? Anybody has done something like this in the past?
Thanks in advance!
Answer: A good place to start is an addon that already does what you want (in a generic way):
https://addons.mozilla.org/en-US/firefox/addon/tamper-data/
On the download page it says Use tamperdata to view and modify HTTP/HTTPS headers and post parameters. You're interested in changing 'post parameters' so that's a good place to start.

But if you just want to implement this yourself....
I've answered this out-of-order, in order to progress in the way you might build up the solution in development.
In the final extension, you'll need to:

Intercept the request
Target the correct requests(s)
Get access to the POST request body
Parse the POST request body's form data (to get the real binary file data)
Do your encryption step
Re-encode the binary file data, re-assemble the form-data, and modify the POST request headers
Replace the existing content in POST request.

Intercepting the request & replacing the existing POST content
The basics are that you need to implement an nsIObserver passing an nsIHTTPChannel as the "subject" for observation. The "notification" you wish to observe is called http-on-modify-request.
There are simple examples (1, 2) for intercepting GET requests in the documentation for http-on-modify-request, however intercepting POST requests is more complicated.
Getting at the POST request body:
There's a mozillazine forum thread that deals with this exact topic.
Kamelot9's 2nd post in that thread details how to (1) get at the post body:
var httpChannel = aSubject.QueryInterface(Ci.nsIHttpChannel);
var uploadChannel = httpChannel.QueryInterface(Ci.nsIUploadChannel);
var uploadChannelStream = uploadChannel.uploadStream;
uploadChannelStream
    .QueryInterface(Ci.nsISeekableStream)
    .seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
var stream = Cc["@mozilla.org/binaryinputstream;1"]
    .createInstance(Ci.nsIBinaryInputStream);
stream.setInputStream(uploadChannelStream);
var postBytes = stream.readByteArray(stream.available());
var poststr = String.fromCharCode.apply(null, postBytes);

where aSubject here comes as a parameter to your http-on-modify-request notification. You can then just modify poststr. Depending on the server, you might also need to modify the Content-length header (or your post may be truncated).
Replacing POST request content:
Once you've got your modified POST body, you need to (2) replace the existing content of the inputStream in the uploadChannel with your own:
var inputStream = Cc["@mozilla.org/io/string-input-stream;1"]
    .createInstance(Ci.nsIStringInputStream);
inputStream.setData(poststr, poststr.length);
uploadChannel.setUploadStream(
    inputStream,
    "application/x-www-form-urlencoded",
    -1);
// do this last - setUploadStream resets requestMethod to PUT
httpChannel.requestMethod = "POST";

Cc and Ci above are just shorthand for Components.classes and Components.interfaces respectively. These shorthand variables may already be set up, or you can define them yourself.
Parsing the form data:
I think that normally for a file upload, the Content-type: will be multipart/form-data.
To get down to the particular 'attachment' you're interested in, you'll need to:

Parse the mime envelope to get out the file attachment
Find your file attachment
Remove whatever text encoding has been used (e.g: BASE64)

In the POST headers, you'll get something like:
Content-Type: multipart/form-data; boundary=JGUOAeGT3Fjgjcdk6s35F2mPVVyTdzgR

where 'JGUOAeGT3Fjgjcdk6s35F2mPVVyTdzgR' is the MIME boundary. In the body of the POST, the content will start will be formatted like this:
--[boundary]
CONTENT-PART #1
--[boundary]
CONTENT-PART #2
--[boundary]

Each CONTENT-PART above will have some HTTP headers, a blank line, then the body of that particular CONTENT-PART.
An example from another stackoverflow question:
Content-Disposition: form-data; name="updates"; filename="update1353963418000.json"
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: binary

{"collectionType":"activities","date":"2012-11-26","ownerId":"qw12er23","ownerType":"user","subscriptionId":"112233-activities"}]

In this case, the Content-Transfer-Encoding is binary (raw, encoded) UTF8, so you wouldn't need to do any more work to be able to read the JSON in the body of the CONTENT-PART.
In your case, the browser will be sending a binary file, so it'll likely have set the Content-Transfer-Encoding to base64, which means you'll need to Base64-decode the body of the CONTENT-PART to get to your real binary file. If base64data contains the encoded content, then this will give you the raw binary data:
var rawData = atob(base64data);

At that point you can do whatever encryption you want on rawData.
Remeber, you'll have to re-encode the binary data after your encryption (using btoa), then you'll need to re-assemble the multipart envelope, before re-constructing the POST request body. (Don't forget to get .length of the final request body so that you can substitute in the Content-length in the request headers.).
targetting the request(s):
That's the basic mechanism for modifying a POST request. But you've still got to single out your particular POST requests (examine the POST request URL in the observer notification) so that you allow other POST requests to proceed as normal without invoking your modification code.


Retornar imagem por Web Service REST Server

Question: Tenho um Web Service REST rodando, esse web service faz a consulta no ERP quando o cliente solicita a requisição de um determinado dado, precisava retornar a imagem que o cliente fez a requisição e mostrar no browser.
fiz o seguinte código que retorna um stream, mas mesmo assim não tive sucesso.

Result := TFileStream.Create(sDirImagem,fmOpenRead or fmShareCompat);
Comment: Olha, não sei te dizer se é esse o seu problema, mas eu já tive problemas em trafegar imagens entre serviços. Ele simplesmente só aceitava tipos nativos A solução foi converter a imagem para base64 e trafega-lo como string.
Comment: Consegui resolver, mas preciso converter a imagem para base64 mesmo, estou testando com o Postman, para ver se ele mostra a imagem convertida em base64. Valeu
Answer: Para visualizar a imagem direito no navegador, consegui resolver do seguinte modo, usei a função GetInvocationMetaData, tenho que especificar para o navegador qual o retorno. Vou colocar um exemplo de como eu fiz:
declarar no usues Data.DBXPlatform
function CarregarImagem(const sCaminho: String): AnsiString;
var
  oFileStream : TFileStream;
begin
  oFileStream:= TFileStream.Create(sCaminho, fmOpenRead or fmShareDenyWrite);
try
 if oFileStream.Size > 0 then
 begin
   SetLength(Result, oFileStream.Size);
   oFileStream.Read(Pointer(Result)^, oFileStream.Size);
 end;
finally
  FreeAndNil(oFileStream);
end;

end;
sImagem := CarregarImagem(sDirImagem);
if (bExtPNG) then
  GetInvocationMetadata().ResponseContentType := 'image/png'
else
begin
  GetInvocationMetadata().ResponseContentType := 'image/jpeg';
  GetInvocationMetadata().ResponseCode := 200;
  GetInvocationMetadata().ResponseContent := sImagem;
  GetInvocationMetadata().CloseSession    := True;
end;


Does the integral of PDF of multi-normal distribution over quarter planes have a closed form?

Question: I am interested in finding a closed form solution (wich I suspect does not exist)  to the following integral
$$\displaystyle \int _a^{\infty }\int _b^{\infty } \frac{\exp \left(-\frac{x^2+y^2-2 c x y}{2 \left(1-c^2\right)}\right)}{2 \pi  \sqrt{1-c^2}} dy dx$$
which corresponds to the  integral of the PDF$(x,y)$ of a multiNormalDistribution (of covariance coefficient $c$) over the  quarter plane $x>a$ and $y>b$. Here $a$ and $b$ are positive and $0<c<1$ (and I know a solution exists for $a=b=0$, but this is not sufficient for my purpose).
More generally I would be interested in the $3$D generalization of this problem.
I have tried in Mathematica to no avail.
Regards,
Answer: Generically, cumulative distribution function of multivariate Gaussian vector is not expressible in terms of cdf of standard normal random variable $\Phi(x)$. The book by Alan Genz and Frank Brentz, "Computation of multivariate Normal and t Probabilities" is good reference on the subject.
For a standard 2D Gaussian vector $(X,Y)$ with correlation coefficient $-1 < \rho <1$, the probability $ \mathbb{P}(X>a,Y>b) $ can be expressed in terms of Owen's T-function.
By the way Mathematica v8 has a built-in support for multi-normal distribution with special efficient cases for 2D and 3D Gussian random vectors, see BinormalDistribution (ref-page), and MultinormalDistribution (ref-page), and OwenT (ref-page).
Comment: @AdelBibi Yes, because $F_{X,Y}\left(x,y)\right) = \Pr\left( X \leqslant x, Y \leqslant y\right) =  1 - \Pr\left(X > x\right) - \Pr\left(Y>y\right) + \Pr\left(X>x, Y>y\right) =  F_X\left(x\right) +F_Y\left(y\right) - \left(1-  \Pr\left(X>x, Y>y\right)\right)$. The latter bivariate probability can be expressed in terms of Owen's T-function as I claimed in the post.
Comment: @AdelBibi Please look at `OwenT` [ref-page](https://reference.wolfram.com/language/ref/OwenT.html), last example in the application section.
Comment: Is it correct to assume there is no generalization of the Owen's T function which would be applicable to the 3D case?
Comment: @chris Of course there is. The generalization is called the multinormal probability. Generically it does not reduce to lower-dimensional probability functions though.
Comment: Nor does its cumulative distribution reduces to any analytic form?
Comment: No, I am afraid it does not
Comment: @Sasha Hey Sasha, a quick question. Is there a closed form expression for the CDF of bivariate gaussian in terms of Owen'sT-function? Or can the integral presented by OP be written in closed form in terms of Owen's T-function?
Comment: @Sasha Thanks, Sasha. Do you by any means have any source of the last joint CDF in terms of Owen's T-function? I tried looking for it, but it is poorly documented.


Passing Point parameter to SQL Server DB as geometry type

Question: I need to pass a Point value as a parameter to SQl Server DB.
But geometry is not a member in SqlDbType enumerator.
What solution can be used here? Should I split Point.X and Point.Y and pass as floats? And retrieve as floats and restore into a Point?
Answer: Construct it as an SqlGeometry in your C# code, then pass it as a SqlDbType.Udt parameter (setting the UdtTypeName to geometry), and have it declared as a geometry parameter on the SQL side - it should all flow through correctly.
Comment: I am going to accept your answer. Why? That's just the only thing I managed to get so far. And for the sake of *working* tool, I just split the damn `Point` to take two `floats` for it's `.X` and `.Y`. So instead of having one Geometry column to record the point, I am constructing point with two columns for X, Y.


Debug Python on Kubernetes

Question: Current Architecture
On the most foundation part is Kubernetes with multiple different container images.
On top of them, we have a python library which dynamically loads our code, which we write and install on those containers after deployment.
We write stateful applications on k8, that's why this kind of architecture.
Let's call our code beta and the lib which loads it alpha
The current process testing new changes it the following:

provision of a new container with the new installed changed from the artefactory
run alpha, which loads beta, which we actively develop

What we can do/ cannot do

no ssh
all commands of kubectl
port forwards
im using OSX, with PyCharm

Now the question:

How can I start my local IDE and set a breakpoint in beta, which gets loaded after running alpha on the k8 pod -> container
Answer: For now the possible solution was to do the following:
- add a remote debugger to the code, which listens upon start
- port forward the traffic
- clone the code (install), such that the lib gets run, as soon as you run the main
- run the code
- it waits until attach
- attach to the debugger.
Voila it works.
Comment: I you want to attach to an already running pod, [I wrote an open source tool to do that](https://docs.robusta.dev/master/catalog/actions/python-troubleshooting.html#python-debugger)

Debug Python on Kubernetes


Factors of a sequence resulting from repeated exponentiation

Question: I have a sequence $a_n$: $1,2, 2^2, 2^{2^2}, 2^{2^{2^2}}, ...$
I would like to know how to factor $b_i = a_i-a_{i-1}$ where $a_0=1$
All I've been able to figure out so far is that 1 + $\sum\limits_{i=1}^nb_i = a_n$, which doesn't seem to go anywhere...
Comment: Do you mean that $a_n: 1, 2, 2^2, (2^2)^2, ((2^2)^2)^2$ or $a_n: 1, 2, 2^2, 2^{(2^2)}, 2^{(2^{(2^2)})}$?
Answer: Let $$a_i = 2^{x_i}, x_i = p_1^{p_2^{\cdots ^{p_i}}}$$
Then $b_i = a_i - a_{i-1} = a_{i-1} \cdot (2^{(x_i - x_{i-1})} - 1)$
Remove the trivial factor as:
$$\frac{b_i}{a_{i-1}} = 2^{(x_i - x_{i-1})}-1$$
Also it's divisible by $3$ since difference between exponents is even.
Comment: How would I then factor $\frac{b_i}{a_{i-1}}$ ? You've mentioned that it is divisible by 3, but how would I figure out other divisors?


Solutions to the equation $x! + y! = (p-1)^{p}$

Question: So I was messing around with equations involving factorials and I ended up with this:
Find all natural numbers $x,y,p$ where $p$ is a prime such that:
$$x! + y! = (p-1)^{p}$$
Through trial and error the only solutions I could find are $(x,y,p) = (2,3,3), (3,2,3)$ so I'm very interested to know whether or not there exist any other solutions.
Answer: Just some thoughts here:
ok if $p$ is a prime greater than $2$, then it is odd so $p-1$ must be even, that gives us that:
$$2^p|(p-1)^p$$

$$(p-1)^p=(p-1)(p-1)^{p-1}\approx(p-1)e^{p-1}(p-1)!\frac{1}{\sqrt{2\pi(p-1)}}=\sqrt{\frac{p-1}{2\pi}}e^{p-1}(p-1)!$$
where for large $p$ the $(p-1)!$ is the part that will determine the order of magnitude primarily. This shows that $x,p$ or $y,p$ must be of similar orders of magnitude.
Answer: Without loss of generality, assume that $x \geq y$. Take $q$ to be the smallest prime with the property that $q$ does not divide $p-1$, so that $q \ll \log p$. Then $q$ does not divide $(p-1)^p$ and hence $y < q$. From Stirling's formula, $x > p$ and hence the largest power of $2$ dividing $x!+y!$ is the same as the largest power of $2$ dividing $y!$, and hence bounded above by $y< q \ll \log p$. On the other hand, $2^p \mid (p-1)^p$, a contradiction for larger $p$.
Comment: Why not just say that $q \ll p$ instead of $q \ll \log p$?
Comment: Well, because such a statement would not be strong enough to make this proof work, for starters....
Comment: But where did you use the fact that $q\ll \log p$ in the proof anyway?
Comment: The power of $2$ dividing the LHS is $\ll \log p$ and $\gg p$, so that $p \ll \log p$.


HttpListener and IntegratedWindowsAuthentication across network

Question: I've created a ClickOnce service using HttpListener.  I need to authenticate the user's connection:
<code>HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://*:80/ClickOnce/");
listener.AuthenticationSChemes = AuthenticationSchemes.IntegratedWindowsAuthentication;
while (true)
{
    var context = listener.GetContext();
    var id = context.User.Identity as WindowsIdentity;
    if (id != null)
    {
        using (var impersonated = id.Impersonate())
        {
           ...
        }
    }
}
</code>
This works fine as long as the service is on the same machine as the Http client.  But if I try to connect to the service from another machine, it refuses to authenticate.
If I connect through Internet Explorer, it prompts for username/password, attempts to connect, and then goes back to the prompt.
If I connect through Chrome, it just says "This webpage is not available ERR_INVALID_AUTH_CREDENTIALS".
If I run VSTOInstaller.exe, it gives the following error:
<code> System.Deployment.Application.DeploymentDownloadException: Downloading http://.../OutlookAddin.vsto did not succeed.
 System.Net.WebException: The remote server returned an error: (401) Unauthorized.
 System.ComponentModel.Win32Exception: The target principal name is incorrect
    at System.Net.NTAuthentication.GetOutgoingBlob(Byte[] incomingBlob, Boolean throwOnError, SecurityStatus& statusCode)
 ...
</code>
If I configure anonymous authentication, it allows the requests through, but then I can't authenticate the users.
Can HttpListener authenticate over a network?  Or is there another alternative to HttpListener which supports this scenario properly?
Answer: I'm afraid it is too late, but based on your error description it can be (is) an issue with Kerberos authentication.
More specifically it is either missing SPN records or mismatch in request header. Check what was actually sent in Fiddler and verify that SPN matches record. I would also suspect specified port in you prefixes. This error frequently happens if you have non standard port in url.
Comment: It is rather late, I ported the whole thing to IIS because that was the only way I could get it to actually authenticate properly.


Show two columns from SQLite as same string in a listview in android

Question: Hi I am developing an android in which I am loading data from database and showing it in a List View.
My code is as follows
public class rel extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.refill);
    //Creating an object called mydbhelper
    Dbms mydbhelper = new Dbms(this);
    //Loading the database in writable format
    SQLiteDatabase db=mydbhelper.getWritableDatabase();
    String[] id= new String[]{"_id","medicine","hs"};
    //Cursor
    Cursor c = db.query("medicines",id,null,null,null, null,null);
    startManagingCursor(c);
    String[] from = new String[]{"medicine"};
    int[] to = new int[] { R.id.textlist1};
     // Now creating an array adapter and set it to display using my row
    SimpleCursorAdapter notes =new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
    setListAdapter(notes);

}

What i want to achieve is show a list view as "Medicine-hs" in which medicine is from one column and hs is from an another column of database. For example as
XYZ-HS1
ABC-HS2
as the listview contents
How to achieve this?
Right now I am able to get only Medicine
Please give your kind suggestions
}
Comment: That gives an error as such a field does not exist in the database.Better read the question clearly and understand how things work internally before trying to show your smartness.
Answer: I want to say replace this:
    String[] from = new String[]{"medicine"};
    int[] to = new int[] { R.id.textlist1};

with this:
    String[] from = new String[]{"medicine", "medicine-hs"};
    int[] to = new int[] { R.id.textlist1, R.id.textlist2};

You will of course need to have a R.id.textlist2 available to use in your layout.
EDIT: Reverted back to the previous revision, which solved the problem.
Comment: If you need further clarification let me know.
Comment: Hi, here medicine and hs are from different columns of a database. How can I get them into one single String? Regards ChinniKrishna kothapalli
Comment: Hi jack figured it out. Thanks for your help. Just need to add another text box as you have told and need to redefine the XML layout a bit to get it. Thank you :-)
Answer: What you could do is execute the rawQuery() method off the DBHelper class with SQL that combines the fields like so:
SELECT medicine + "-" + hs AS medicineHs FROM medicines ...

so the string array would be
String[] from = new String[]{"medicineHs"};

Comment: Oh right. So the select would be: SELECT _id, medicine + "-" + hs AS medicineHs FROM medicines ...
Comment: Wow an elegant solution but it lacks selecting the '_id' column which gives an error. Actually I am new to SQL so maybe facing problems :-)


Matplotlib and django templates

Question: I have a Django application, with charts from Googles image chart api. I want to replace the charts (they are depreciated), and start using Matplotlib.
So I have followed the example here, to get Django / Matplot to return a png:
http://wiki.scipy.org/Cookbook/Matplotlib/Django.
Now, if I want to return an HTML page, with Matplotlib images embedded, how do I go about that? I can see two options.
1: Should I set up the HTML as one view, with another view for the chart, treating these two parts separately (I guess data would be encoded in the image URL). The HTML will be rendered, and as the image tag is rendered , it makes the second call to Django, and the chart is generated. This seems easy enough to set up, but also seems like the chart data will be passed back and forward unnecessary.
2: Or can I generate the Matplot lib images at the same time as the HTML, have the png's ready and send them at the same time? I guess I would have to write the file to where static files are served from. And what would be considered best practice for a naming scheme for files / cleaning up afterwards?
Is there one method that is considered best practice over the other for this sort of thing? I assume it isn't so uncommon.
Answer: The first option would almost certainly be easier. Just map a URL to the view that calls the matplotlib code, and return the image data there.
For the second option, you could embed image data in HTML by using a data uri as the source of your image in the template, but this doesn't really seem to be necessary.

Matplotlib and django templates


TypeError: schema._preCompile is not a function MongoDb problem

Question: When I try to use a mongoose scheme I get the following error I can't find the solution.
TypeError: schema._preCompile is not a function
This is how the schema is defined.

const mongoose = require('mongoose')
const {isEmail} = require('validator')

const userSchema= new mongoose.Schema({
  email: {
    type: String,
    require: true,
    validate: [isEmail, 'invalid email'],
    createIndexes: {unique: true},
    trim:true
  },
  nickName:
  {
    type: String,
    require:true,
    createIndexes: {unique:true},
    trim:true
  },
  password: {
    type: String,
    require:true,
    trim:true
  },
  dateBorn: {
    type: Date
  },
  games:[{
    type: mongoose.Schema.Types,
    ref: 'Game'
  }],
  books:[{
    type: mongoose.Schema.Types,
    ref: 'Book'
  }],
  movies:[{
    type: mongoose.Schema.Types,
    ref: 'Movie' //referencia a things
  }],
},{
    timestamps:true,
    versionKey:false
  })
module.exports = mongoose.model('users',userSchema)

This is how I'm trying to import

const usersSchema = require('../models/user')

This is how I define the connection

const mongoose = require('mongoose')

const dbConnect = () => {
    const DB_URI= process.env.DB_URI
    const db = mongoose.connect(DB_URI,{
      useNewUrlParser:true,
      useUnifiedTopology:true
    }, (err, res) => {
      if(!err){
        console.log('CONECTION TO MONGODB SUCCESFULL')
      }else{
        console.log('CONECTION TO MONGODB ERROR')
      }
    })
  }

module.exports = { dbConnect }

enter link description here
here is the repository link for more information
Comment: The way you're declaring the types of the refs doesn't look right, you should be using a particular type such as `ObjectId`. See the docs for [SchemaTypes](https://mongoosejs.com/docs/schematypes.html).
Comment: yep was that, thank you!
Answer: games:[{
    type: mongoose.Schema.Types,
  }],
  books:[{
    type: mongoose.Schema.Types,
  }],
  movies:[{
    type: mongoose.Schema.Types,
  }],

In these lines you have to define what type of data you want to store here, like games could be a Stringalso books could a String/Array. you just can't keep like mongoose.Schema.Types and think mongoose will choose it by it's own!!
have a read in this link - https://mongoosejs.com/docs/schematypes.html


Accessing static member through invalid pointer: guaranteed to "work"?

Question: Setup
Given this user-defined type:
struct T
{
    static int x;
    int y;

    T() : y(38);
};

and the requisite definition placed somewhere useful:
int T::x = 42;

the following is the canonical way to stream the int's value to stdout:
std::cout << T::x;

Control
Meanwhile, the following is (of course) invalid due to an instance of T not existing:
T* ptr = NULL; // same if left uninitialised
std::cout << ptr->y;

Question
Now consider the horrid and evil and bad following code:
T* ptr = NULL;
std::cout << ptr->x; // remember, x is static

Dereferencing ptr is invalid, as stated above. Even though no physical memory dereference takes place here, I believe that it still counts as one, making the above code UB. Or... does it?
14882:2003 5.2.5/3 states explicitly that a->b is converted to (*(a)).b, and that:

The postfix expression before the dot or arrow is evaluated;
  This evaluation happens even if the result is unnecessary to determine the value of the entire postfix expression, for example if the id-expression denotes a static member.

But it's not clear whether "evaluation" here involves an actual dereference. In fact neither 14882:2003 nor n3035 seem to explicitly say either way whether the pointer-expression has to evaluate to a pointer to a valid instance when dealing with static members.
My question is, just how invalid is this? Is it really specifically prohibited by the standard (even though there's no physical dereference), or is it just a quirk of the language that we can probably get away with? And even if it is prohibited, to what extent might we expect GCC/MSVC/Clang to treat it safely anyway?
My g++ 4.4 appeared to produce code that never attempts to push the [invalid] this pointer onto the stack, with optimisations turned off.
BTW If T were polymorphic then that would not affect this, as static members cannot be virtual.
Comment: There's some related discussion concerning this at [When does invoking a member function on a null instance result in undefined behavior?](http://stackoverflow.com/questions/2474018/when-does-invoking-a-member-function-on-a-null-instance-result-in-undefined-behav) (Your question is about static data members; static member functions were discussed in the other question). The consensus was that it _should_ be allowable but is not; there's a closed DR that would make it allowable but that DR relies on the resolution to a still-open DR (whether that consensus was correct is open for debate :-D)
Comment: The issue is that the closed DR (CWG defect 315) says "`*p` is not an error when `p` is null unless the lvalue is converted to an rvalue." However, this relies on the concept of an "empty lvalue," which is part of the proposed resolution to the still-open [CWG Defect 232](http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#232).
Comment: @James: So we're saying that it's just another inconclusive quirk of the delicious mess that is C++? :)
Comment: Effectively, yes.  I'm almost certain that in your quote, "evaluation" means "the operator does it's thing," and the thing that `*` does is "performs indirection," so you end up performing indirection via a null pointer, which yields undefined behavior.
Comment: @James: Oh joyous. I'd accept that as an answer, btw.
Answer:
it's not clear whether "evaluation" here involves an actual dereference.

I read "evaluation" here as "the subexpression is evaluated."  That would mean that the unary * is evaluated and you perform indirection via a null pointer, yielding undefined behavior.
This issue (accessing a static member via a null pointer) is discussed in another question, When does invoking a member function on a null instance result in undefined behavior?  While it discusses member functions specifically, I don't see any reason that data members are any different in this respect.  There is some good discussion of the issue there.
There was a defect reported against the C++ Standard that asks "Is call of static member function through null pointer undefined?"  (see CWG Defect 315)  This defect is closed and its resolution states that it is valid to call a static member function via a null pointer:

p->f() is rewritten as (*p).f() according to 5.2.5 [expr.ref]. *p is not an error when p is null unless the lvalue is converted to an rvalue

However, this resolution is in fact wrong.
It presupposes the concept of an "empty lvalue," which is part of the proposed resolution for another defect, CWG defect 232, which asks the more general question, "Is indirection through a null pointer undefined behavior?"
The resolution to that defect would make certain forms of indirection through a null pointer (like calling a static member function) valid.  However, that defect is still open and its resolution has not been adopted into the C++ Standard.  Until that defect is closed and its resolution is incorporated into the C++ Standard, indirection via a null pointer (or dereferencing a null pointer, if one prefers that term) always yields undefined behavior.
Comment: Can this be generalised to non-NULL invalid pointers with the restriction that the defect resolution would not fix this for them?
Comment: @Tomalak:  Yes, because doing just about anything with an invalid pointer yields undefined behavior.  I'd have to dig into the Standard to find specific citations for that, though.
Comment: Yea, IIRC even printing the contents of an invalid pointer (and, yes, I mean the contents of the pointer) is UB, because it's "use". Though that's off the top of my head.
Comment: **Update:** As of the FDIS this [appears to still be the case](http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1102), so unfortunately it looks like we're stuck with this through C++11. :(
Answer: Concerning p->a, where p is a null pointer, and a a static data member:
§9.4/2 says "A static member may be referred to using the class member
access syntax, in which case the object-expression is evaluated."  (The
"object-expression" is the expression to the left of the . or the ->.)
Comment: Sure, it's evaluated. The question is, is the evaluated expression (0) then explicitly dereferenced?
Comment: The expression is (*ptr).x; the -> operator is defined in terms
of *.  And evaluating (*ptr) dereferences the pointer.
Comment: Where does the standard say that explicitly for this scenario? (The question has already been answered: the standard does _not_ say that unambiguously.)
Comment: @Tomalak §5.2.5/2 unambiguously defines p->x as the equivalent of
(*p).x.  And §5.3.1/1 says that "the expression to which it [the unary *
operator] is applied shall be a pointer to an object type, or a  pointer
to a function type".  `0` points to neither an object nor a function (of
any type), so `*0` is undefined behavior.
Answer: Looking from computer side onto OOP it is yet another way to calculate where data resides in memory. When data is not static - it is calculated from instance pointer, when data is static it is always calculated as fixed pointer in data segment. Template adds nothing, since resolved at compile time.
So it is rather popular technique to use NULL as start pointer (for example evaluate offset of filed in class for persisting purposes)
So code above is correct for static data.
Comment: I'd rather have some rationale about quotes from the standard than know what the popular technique is, though! Also, I'm not sure I follow you regarding people using an instance pointer to just access static data without an instance? I realise that I'm the one who posted the code, but it's fugly and should never be used in real life...
Comment: @Tomalak Geret'kal For example of usage of NULL-pointer look my answer at: http://stackoverflow.com/questions/1400660/what-is-a-common-c-c-macro-to-determine-the-size-of-a-structure-member/1400702#1400702 . Relative usage of pointer I've mean that compiler doesn't need your pointer, so it is not used at all and rejected at compile time. Even more there is WARNING (something like: usage of pointer with static data, ignoring)
Comment: @Dewfy: OK, that's fine, but I'm looking for proof as to whether or not it really is "safe" as you claim. I suspect that it's not. BTW, why aren't you using pointers-to-members there?
Comment: @Tomalak Geret'kal - sorry press enter not in time, so copying again: Relative usage of pointer I've mean that compiler doesn't need your pointer, so it is not used at all and rejected at compile time. Even more there is WARNING (something like: usage of pointer with static data, ignoring)
Comment: @Dewfy: OK, but to what extent does the _standard_ guarantee this? And which compilers will explicitly allow it? And where is this documented?
Comment: @Tomalak Geret'ka I hope that next answer shows relation with standard http://stackoverflow.com/questions/3498444/c-static-const-access-through-a-null-pointer. So you are right about POSSIBILITY of pointer evaluation.
Comment: @Dewfy: Ooh yes that looks like a dup. Good spot.


Download HP Power Protector for ESXi

Question: The HP PowerProtector user guide states that to install the HP PowerProtector client on an ESXi Host:

Download the latest version of HPPP from the HP website (http://www.hp.com/go/rackandpower).
  The ESXi Server is automatically detected, and a shutdown command script is generated.

However in typical HP fashion, after clicking through no less than 6 different links to get to the downloads page, I am presented with:
http://h18004.www1.hp.com/products/servers/proliantstorage/power-protection/software/power-protector/pp-dl.html

HP Power Protector (HPPP) - Windows
HP Power Protector (HPPP) - Linux x86
HP Power Protector (HPPP) - Linux x64
HP Power Protector (HPPP) - Linux IA64
HP Power Protector (HPPP) - HPUX

The Linux packages contain an RPM and in no way resemble what is in the HP documentation. None of these are labelled for ESXi. Does anyone know where or how to get the HP Power Protector ESXi client installed?
Answer: As with APC Powerchute UPS software, you're not supposed to install UPS management agents directly on an ESXi host. I still think VMware should build something like this into the ESXi distribution.
In practice, my small and large VMware environments do not have any provisions for graceful UPS-led shutdown. There's too much to coordinate (SAN, networking, etc.) and bigger installations have facility-level UPS and generator. Smaller sites just deal with the risk.
Anywho, for your situation, you'll need to make use of the VMware Management Assistant (vMA) virtual machine appliance. This appliance sits in your virtual infrastructure and can be used to execute scripts on your hosts.
From there, see HP's documentation here about installing the HPPP Linux RPM onto the vMA appliance and modify the execute bit on the shutdown script located at: <code>/usr/local/HP/PowerProtector/bin/virt_tools/shtdownESXi.pl</code>
The script has the typical remote execution parameters and will need to be modified to taste:

perl /usr/local/HP/PowerProtector/bin/virt_tools/shtdownESXi.pl
  --server ip_address --username root --password rootpassword
Comment: I thought it was odd for HP to be asking me to install an agent on the box itself. They don't mention in their documentation to do this on the vMA (or I didn't see it). Probably should have figured that out myself though.

Download HP Power Protector for ESXi


Derivative of x power series of exponents

Question: I want to find the derivative of an expression of the form
$$
y = x ^ { {(x+1)} ^ { {(x+2)} ^ {...} } }
$$
with respect to x. This expression has a base of x and a series of exponents that are formed by taking the previous exponent and adding 1 to it
Sorry I don't the exact term for this. There must be some easy trick to solve this. Maybe something to do with chain rule?
Comment: Is this an infinite power tower ?
Comment: I might be wrong, but I don't think this evaluates to a simple expression. I would happily like to be proven wrong, though, because the question seems interesting.
Comment: Welcome to MSE. Your question is phrased as an isolated problem, without any further information or context. This does not match [many users' quality standards](http://goo.gl/mLWc8), so it may attract downvotes, or be closed. To prevent that, please [edit] the question. [This](http://goo.gl/PlJyVQ) will help you recognize and resolve the issues. Concretely: please provide context, and include your work and thoughts on the problem. These changes can help in formulating more appropriate answers.
Comment: "of an expression of the form" is somewhat misleading in the light of the answer below, because the given power tower is either infinite or zero! I think you should provide the original expression, provided it is well-defined and takes real values everywhere. Maybe in a different question because there's already an answer.
Comment: @SarveshRavichandranIyer For $x=1$ , it is $1$.
Comment: @Peter You are correct, though the function is still too bad to differentiate
Answer: This function bumps to $\infty$ for $x> 1$ and is not well-defined in $x<0$. So, let's focus on $0\le x\le 1$. Note that this function is not differentiable in $x\in\{0,1\}$ and for $x\in(0,1)$, the quantity $(1+x)^{(2+x)^\cdots}$ tends to $\infty$, leading to the fact that $x^{(x+1)^{(x+2)^\cdots}}$ converges to 0 for $x\in(0,1)$, so do its derivatives.


Remove accounts if lastusetime is older then value

Question: Iam trying to create a task that will executed later with tasksch on the local machine, that will run everyday.
The task is, if a user has not logged in to the computer, it shall be removed from the computer.
The Thing is there is something wrong with my code and i dont know what
For now iam trying that the script shall remove testuser 1,2,3 and on testuser 4 is shall say Account is not old by using lastusetime.
System-info
OS Name: Microsoft Windows 10 Enterprise
OS Version: 10.0.17763 N/A Build 17763
Account-Info
@{Sid=S-1-5-21-3824012622-276487612-2647460976-1105; LocalPath=C:\Users\testuser4; LastUseTime=2019-05-13 19:27:57}
@{Sid=S-1-5-21-3824012622-276487612-2647460976-1109; LocalPath=C:\Users\testuser3; LastUseTime=2019-05-10 14:54:07}
@{Sid=S-1-5-21-3824012622-276487612-2647460976-1108; LocalPath=C:\Users\testuser2; LastUseTime=2019-05-10 14:54:07}
@{Sid=S-1-5-21-3824012622-276487612-2647460976-1107; LocalPath=C:\Users\testuser1; LastUseTime=2019-05-10 13:49:16}
# Start PS-Code
 $DeleteIfLastUseTimetIsOlderThen = (get-date).AddDays(-5).tostring("yyyy-MM-dd hh:mm:ss")

 $GetLocalAccounts = Get-WmiObject -ComputerName localhost -Filter "Special=False" -Class Win32_UserProfile |
 Select-Object Sid, LocalPath, @{Label='LastUseTime';Expression={$_.ConvertToDateTime($_.LastUseTime)} }

  foreach ($UserAccount in $GetLocalAccounts)
   {
    if ($GetLocalAccounts.LastUseTime -Ge $DeleteIfLastUseTimetIsOlderThen )
     { Write-host "Account is old, Remove me"}
      Else
       { Write-host "Account is not old"}
 }
# End PS-Code

The thing is that it doesn't matter if I change the value "$DeleteIfLastUseTimetIsOlderThen " to 1,2,3,4 or 55, everything seems to be old.
Comment: If you are looking for an older date, then you want to do a *less than* comparison (`-lt` or `-le`), i.e. yesterday < today.
Comment: The thing is even i use those, test account 4 should get "account is not old" in the ise console ?
Comment: Your `if` statement is incorrect. It should be `if ($UserAccount.LastUseTime -le $DeleteIfLastUseTimetIsOlderThen ) { ... }`. `$GetLocalAccounts` is a collection, and you want to compare an individual item from that collection, which is represented by `$UserAccount`.
Comment: Thank you sir, that is what iam looking for
Answer: The issue here is twofold. One is that you want to use a less than comparison when looking for an older date since a date in the past is less than a date in the future. Second, you want to compare each date in your collection ($GetLocalAccounts) with a specific fixed date ($DeleteIfLastUseTimeIsOlderThan). To do this with your code structure, you will need to check against the current object ($UserAccount) in your for loop.
# Start PS-Code
 $DeleteIfLastUseTimetIsOlderThan = (get-date).AddDays(-5).tostring("yyyy-MM-dd hh:mm:ss")

 $GetLocalAccounts = Get-WmiObject -ComputerName localhost -Filter "Special=False" -Class Win32_UserProfile |
 Select-Object Sid, LocalPath, @{Label='LastUseTime';Expression={$_.ConvertToDateTime($_.LastUseTime)} }

  foreach ($UserAccount in $GetLocalAccounts)
   {
    if ($UserAccount.LastUseTime -le $DeleteIfLastUseTimetIsOlderThan )
     { Write-host "Account is old, Remove me"}
      Else
       { Write-host "Account is not old"}
 }
# End PS-Code


How can one estimate compute requirements for Machine Learning algorithms?

Question: Has anyone developed formulas or rules of thumb for estimating CPU, memory and time requirements for running various Machine Learning algorithms (or families of algorithms), with respect to training and prediction–classification?
I realize algorithm implementations vary and a variety of parameters can be tuned, thus affecting the requirements, but I'm interested in ballpark estimates.
I'm aiming for a generalized view of the problem, e.g. constructing functions with parameters for size of the input-data, and so on.
Comment: It's impossible to give such rules of thumb, for example you can run neural network for image classification on Raspberry Pi, or for weeks on multiple TPUs. You can run linear regression in browser, or using Apache Spark MLlib in data center using multiple CPUs and hundreds of dedicated GBs of RAM.
Answer: There are too many variables to get a generic formula. Variables include:

ML method - from linear regression, through K means, to an NN
data - number of features, number of categories, etc
ML model - i.e for an NN - number of hidden layers & number of nodes per layer
metaparameters - learning rate
implementation/framework - Caffe, TensorFlow, Scikit Learn, etc

Inception 1 used "few high-end GPUs to train in a week" here, while Inception3 (if I understand correctly) uses 50 GPUs. Although training time is not given in this paper, I'd imagine it's at least a day or two.
Answer: As other users have mentioned, a formula is certainly out of the question because there are too many variables influencing training/predicting computational time. However, there are some general rules of thumb.
Data Size
Changing the size of your train/predict dataset is the most direct way to change how long your model takes to run.

More samples in your train dataset always means your model will take longer to train.
More classes in your train/predict dataset always means your model will take longer to train and predict.
More features in your train/predict dataset always means your model will take longer to train and predict.

Models train faster on data that takes up less memory.  Don't save data as a 64-bit integer if it can be represented by an 8-bit integer or save integer data as a float, etc.
Machine Learning Model
Different ML models have different computational complexities.
Where n is the number of samples in the training data, p is the number of features, t is the number of trees, and v is the number of support vectors:

KNNs are generally fastest models, requiring no training time. However, they require O(n^2) calculations, which are generally fairly fast. Their prediction time is $ O(np) $.
Nearest Centroid and Naive Bayes train at $ O(np) $ and predict at $ O(p) $, making them about equal in speed to KNNs.
Decision tree models train at $ O(n^2p) $ and predict at $ O(p)$, making them a robust, fast predictor.
Random Forest models train at $ O(n^2pt) $ and predict at $ O(pt) $.
Gradient Boosting Trees train at $ O(npt)$ and predict at $ O(pt) $.
Linear Regression models train at $ O(np^2+p^3) $ and predict at $ O(p) $.
Kernel SVM models train at $ O(n^3+n^2p) $ and predict at $ O(vp) $.

Source.
Metaparameters
Metaparameters are values you input to your ML algorithm that tell it how to behave (thereby influencing the training/predicting time of your algorithm). Not all models have the same metaparameters.

Learning Rate (eta): As your learning rate increases, the computational time of your model decreases.
Number of Features: As the number of features in your model increases, the computational time of your model also increases. (In XGB, this can be number of trees, max_depth; in NNs, this can be number of layers; in KNNs, the value of k; etc.)
Number of Rounds/Epochs: This rule is strict: if you increase the number of rounds or epochs for a machine learning model, it will take longer to train (but the prediction time is the same).
Objective: Some ML models are adaptable for different objectives (ie XGBoost has reg:logistic, bin:logistic, count:poisson, etc).  Different objectives have different train and prediction times (usually regression is longer than binary is longer than count).
Early Stopping: Some ML implementations allow you to stop training your model early (automatically) if your model performs well enough on a validation dataset. Adding this early-stopping functionality will never hurt run time.
Others: Every ML model has different metaparameters which can influence training time that must be attended to.

Hardware
Changing the hardware your model runs on is an expensive though simple way to make your model run faster.  There are three main processing units: CPUs, GPUs, and TPUs:

As a 99% accurate rule of the thumb: TPU > GPU > CPU
Tensor Processing Units (TPUs) are proprietary property of Google that can be accessed through Google Cloud and are constantly being improved. They run blazingly fast for neural networks.  They are the chosen processing unit of DeepMind.
TPUs have higher input/output operations per Joule than any existing GPU.
GPUs are faster than CPUs.
If you increase the number of processing units your model runs on, your model will train and predict faster.
Most image recognition algorithms run especially fast on GPUs.
Some GANs for image generation only run on GPUs (thanks Nvidia...)

Framework
ML models can be run on a variety of frameworks, all of which run at different speeds. The most popular are Keras, TensorFlow, Caffe, Apache, AWS, Theano, Microsoft CNTK, PyTorch, and scikit-learn.  Each framework is different from the next and was created to suit different needs. In my experience, TensorFlow, Keras and Theano run neural networks very fast, AWS is generally robust, and scikit-learn is best for tabular data.  Some frameworks allow you to pay to get faster results.
Language
I've worked with Python, R, Java, Julia, and Scala (briefly) for ML. Python is, in my experience, the fastest. The rest are mostly equal.
Comment: KNN does not require training, but it requires calculating a large number of distances between points, and that takes time. Brute force KNN would calculate $n(n+1)/2$ distances.


How do I preserve file permissions after compressing and moving as tarball?

Question: I seem to be frequently encountering a situation when I compress files of a Drupal site as a tarball from a production server to the public_html folder of my  local machine.
The permissions seem to get messed up and I usually end up with a filesystem not readable error and  deleting a few files in the sites/default/files directory during the process of changing the permissions.
How can I preserve these permissions when the folder is compressed and copied to a new folder or is it an issue with the permissions of the destination folder?
Answer: I move sites as tarballs between servers fairly often when I can't deploy with rsync or git.
According to the man page:

-p, --preserve-permissions extract information about file permissions (default for superuser)

is the proper option to use.  However, this never works well for me.
Typically, I will just use normal tar options, and then run a script after the fact to fix things up.
The Securing file permissions and ownership article has a very good script.  As that gets adjusted from time to time, I am not going to reproduce it here.  It essentially does some find/chown/chmods on the tree to fix things up.
I would use this script as a starting point for your needs.  One thing that it doesn't address is having the private:// filesystem outside of docroot, which I always use.  I will also use 2775 as the permission for the public:// path, as well as a separate use for core/contrib and the site specific code.


Slow page loads - unable to determine the cause

Question: I am experiencing ~ 6 second page loads on every page of my Drupal 7 site. All of my scripts are loading from cache and relatively quickly except one, which will take 5.6-5.9 seconds to load (I am using FireBug to monitor):

Originally it looked to be the overlay.js javascript file, so I disabled the module. Then it was contextual.js with the exact same load time with everything else being quick. When I disabled that module it was yet another js library taking the same amount of time. This leads me to believe it has nothing to do with the libraries and is some other issue with the pages / rendering. I tried aggregating the JS and CSS, but the same issue was happening. All the queries showing up in my MySQL logs are executing relatively quickly (total of all query execution time is less than .5 seconds).
I am honestly at a loss for what to try. I suspect there is some problem here unrelated to loading any of the js files and that firebug is just reporting the delay as part of the last loaded file. This happens on both my custom pages and core drupal pages (like the modules and people screens). Is there any way to tell what is causing the long delay if it is not the javascript library?
EDIT: Details from the header for the script:
<code>Request Headersview source
Accept  */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Connection  keep-alive
Cookie  Drupal.toolbar.collapsed=0; __utma=163199651.1343774579.1355785168.1378243005.1379453429.30; __utmz=163199651.1378243005.29.5.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); _ga=GA1.2.360149903.1357234390; SESSb5e5274d127f94079db0dc72d78d2200=AnQQv9Tp-NQT-b3YcVfOKzEnVSL-3cBexxbp2jY70D0; has_js=1
DNT 1
Host    example.com
If-Modified-Since   Wed, 03 Apr 2013 21:29:52 GMT
If-None-Match   "bcc-4d97b8dea7400"
Referer http://example.com/drupal/?q=peopleace/form/14172
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0

Response Headers From Cache
Accept-Ranges   bytes
Content-Length  3020
Content-Type    application/javascript
Date    Wed, 02 Oct 2013 19:26:36 GMT
Etag    "bcc-4d97b8dea7400"
Last-Modified   Wed, 03 Apr 2013 21:29:52 GMT
Server  Apache
</code>
Comment: Do you have the same problem in other browsers or on other machines?
Comment: Click on the plus sign for that script, and take a screenshot of that and post it. Or tell us what it says.
Comment: @Clive It is the same delay on all browsers and on other machines.
Comment: @Steven I posted the details.
Answer: If a 304 is taking 5+ seconds that means you webserver (most likely Apache) is being very slow. The ONLY other thing that could be causing this is if you have Far-Future enabled with the CDN module (and that's a stretch). Aggregating should help, as this will reduce the # of requests hitting Apache.
What web server are you using? Also noticed that Clean-URLs is disabled so I would bet that the webserver needs to be configured.
Comment: I increased `MaxRequestWorkers` and now it shows the page / php script I wrote as being the delay and not falsely assigning it to loading of other scripts/css. This makes much more sense! Thanks for the shove in the right direction.


system information to workspace

Question: How to return to a variable the information of the system command, like:
a=system("cat /proc/cpuinfo | grep 'model name' | uniq")
return a=0

or
b=system("xrandr | grep 'current'")
Screen 0: minimum 320 x 200, current 1366 x 768, maximum 16384 x 16384
ans = 0

Answer: As documented in Octave, you can get the result in a variable if this one is the second output.
Example: with
[s, r] = system("ls")

you get in r the expected list of file names.

system information to workspace


CSS Unknown Distortions happening only on iOS in Angular Application

Question: A several month mystery has yet to be solved and I am hoping someone has seen this before and knows how to fix it. Using the Angular framework to build a PWA, I am encountering an issue with how CSS images and CSS transformations are causing distortions and apparitions which effectively means the app can't be released for iOS devices until this is corrected.
It is very inconsistent and happens randomly from one to several images at a time. It only happens within iOS. Tested and reproduced on the following devices:

iPhone 6 (iOS 12.1.4) Safari & Chrome & in PWA Standalone
iPhone 6s (iOS 12.1.4) Safari & Chrome & in PWA Standalone
iPhone 6+ (iOS 12.1.4) Safari & Chrome & in PWA Standalone
iPhone x (iOS 12.2) Safari & Chrome & in PWA Standalone
iPad Pro (iOS 12.2) Safari & Chrome & in PWA Standalone

It does not happen on any Android devices going back as far as the Galaxy S4 and the Galaxy Tab A, and as current as the Pixel 3... nor does it occur in Chrome, Safari or Firefox on desktop machines.
There are also cases where a single icon will be duplicated across the entire set of icons, like on the tab bar for instance.

Members

.nav-tab-section-a {
    grid-area: nav-tab-section-a;
}
.nav-tab-active, .nav-tab-inactive {
    margin: 0 auto;
    align-content: center;
    text-align: center;
}
.nav-tab-inactive {
    -webkit-filter: brightness(110%);
    filter: brightness(110%);
}
.nav-tab-image {
    height: 3.25rem;
}
.text-no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

As you can see, the problem occurs with both inline style and Style Sheet methods as well as using HTML native  tag and as a div background.
For a while I thought it could have been an Angular Lifecycle hooks issue where elements were being redrawn, but this has since been corrected and the images are not being re-rendered with every DOM change.
Has anyone ever encountered and solved this before?
Answer: I would immediately suspect this to be a PNG encoding issue. Have all of your PNG assets re-saved using a different software product, and try to track down the origin of who created the PNGs and what software did they use.
You need to completely regenerate the PNG files. So I would first save to another format like TIFF and then resave again as PNG. To ensure that the image editor is forced to regenerate all of the PNG color data, headers and encoding.
You can use a free open source editor to do this:
https://www.gimp.org/
The Safari web browser has a history of distorting images. Graphic files while popular and commonly used contain a wide range of inner coding standards. While the file extension might consistently be something like PNG, JPG or TIFF. The version of the coding, format and contents can vary greatly. Using up to date image software, and making sure your PNG files are generated correctly is an important step.
References to Safari image problems:
https://discussions.apple.com/thread/6680826
https://discussions.apple.com/thread/7648947
Comment: Thanks for the response. Each icon is mastered and edited as a vector graphic in Illustrator and exported as a PNG. Originally all of the icons were SVGs which is when the problem was first encountered, thinking SVGs were the cause, they were switched for PNGs just to have the same result. I will follow up on some of your suggestions and keep digging.
Answer: I started to have this issue in iOS Safari when I added filters to images. Just guessing that it could be a pixel density issue, or performance issue.
Currently looking for a solution, other than turn it off for iOS users. Here are some answers that I found that I will try out:
Why is filter(drop-shadow) causing my SVG to disappear in Safari?
Slow CSS Filters on iPhone?
The last solution will probably drain more battery, however.


Log out of Documentum Server

Question: I have an Windows application that uses Documentum APIs to checkin/checkout documents into Documentum Content Server 6.5.1.
I use DFS 6.5.1 to interact with the server.
Now I need to logout of the session. How is that possible?
Answer: I don't understand your question, what do you mean by log out of the session.
You don't log out sessions, you release them to a session manager (if you are using one) or disconnect them directly.
Comment: and finally that is what I did..Thanks

Log out of Documentum Server


Wrap parentheses

Question: I'm trying to wrap parentheses around string in ruby, only if it isn't wrapped yet:
"my string (to_wrap)" => "my string (to_wrap)"
"my string to_wrap" => "my string (to_wrap)"

I've tried something like:
to_wrap = 'to_wrap'
regexp = Regexp.new "(?!\()#{to_wrap}(?!\))"
string.sub(regexp, "(#{to_wrap})")

but it does not work.
Thanks in advance!
Answer: You are very close. Your first negative lookaround is a lookahead, though. So it looks at the first character of to_wrap. Just make that a lookbehind:
"(?<!\()#{to_wrap}(?!\))"

And just to present you with an alternative option to escape parentheses (it's really a matter of taste which on to use, but I find it more easily readable):
"(?<![(])#{to_wrap}(?![)])"

Comment: @FUT `it's really a matter of taste which on to use, but I find it more easily readable` ;)
Comment: Exactly what I need, thanks. Also thanks for the [)] syntax. :)
Comment: @erik1001 in fact it's abusing character classes, by creating a single-character character class (and most meta-characters don't have to be escaped in character classes). I tend to use it for almost everything (especially `[.]`, `[*]` and stuff like that) except for square brackets themselves.
Comment: @m.buettner why did not you just escape parentheses? Is it better in some way?
`"(?<!\()#{to_wrap}(?!\))"`
Comment: @FUT no. as I said, it's a matter of taste. I personally find `[(]` more readable than `\(` especially as there are unescaped parentheses right next to it.
Comment: Does it mean it's a bit slower using character class than escaped character? If it is, it matters only for very long regex, anyway I find it more readable too.
Comment: @erik1001 I would hope that the regex engine treats a single-character character class exactly the same as a single character. But I guess you'd have to do a proper profiling to ensure that for a specific engine.
Comment: @erik1001 No, it doesn't matter for very long RegExes. It matters if your RegExes are an identified performance problem and you get a boost by not using character classes.
Comment: @phant0m if the engine works by creating an FSM, then both versions should lead to exactly the same FSM. but in general I agree with you. no premature optimization unless it turns out to be the bottleneck.

Wrap parentheses


Estou com dúvida sobre atualizar um Jframe, Help plz

Question: Estou tentando fazer um Quiz. Então gostaria de atualizar a mesma "tela" ou frame - como queiram - ou seja, tem a primeira pergunta, o usuario responde e o frame atualiza com nova pergunta e assim por diante. Minha ideia era de fazer tudo na mesma tela, porém aceito sugestões, caso recomendem eu criar outros frames(o que seria o mais fácil, porem mais trabalhoso).
Segue o código:
String[] perguntas = new String[3];
        perguntas[0] = "Pergunta 1 ?";
        perguntas1 = "Pergunta 2 ?";
        perguntas[2] = "Pergunta 3 ?";
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 600, 471);
    contentPane = new JPanel();
    contentPane.setBackground(new Color(255, 153, 0));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JPanel panel = new JPanel();
    panel.setBounds(0, 167, 616, 265);
    panel.setBackground(new Color(0, 0, 128));
    contentPane.add(panel);
    panel.setLayout(null);

    rdA = new JRadioButton(" A");
    rdA.setBackground(new Color(0, 0, 128));
    rdA.setForeground(Color.WHITE);
    rdA.setFont(new Font("Tahoma", Font.PLAIN, 12));
    rdA.setBounds(24, 53, 48, 23);
    panel.add(rdA);

    rdB = new JRadioButton(" B");
    rdB.setForeground(Color.WHITE);
    rdB.setFont(new Font("Tahoma", Font.PLAIN, 12));
    rdB.setBackground(new Color(0, 0, 128));
    rdB.setBounds(24, 94, 48, 23);
    panel.add(rdB);

    rdC = new JRadioButton(" C");
    rdC.setForeground(Color.WHITE);
    rdC.setFont(new Font("Tahoma", Font.PLAIN, 12));
    rdC.setBackground(new Color(0, 0, 128));
    rdC.setBounds(24, 140, 48, 23);
    panel.add(rdC);

    rdD = new JRadioButton(" D");
    rdD.setForeground(Color.WHITE);
    rdD.setFont(new Font("Tahoma", Font.PLAIN, 12));
    rdD.setBackground(new Color(0, 0, 128));
    rdD.setBounds(24, 186, 48, 23);
    panel.add(rdD);

    alternativas = new ButtonGroup ();
    alternativas.add(rdA);
    alternativas.add(rdB);
    alternativas.add(rdC);
    alternativas.add(rdD);

    JButton btnAvan = new JButton("Avan\u00E7ar");
    btnAvan.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {

        }
    });
    btnAvan.setBounds(292, 231, 89, 23);
    panel.add(btnAvan);
    }
}

Answer: Acredito eu, que a maneira mais eficaz que tenha (até onde saiba) para fazer isso, é criar um objeto, Panel ou Canvas, com tudo organizado, ou chamar uma função que reorganiza da maneira que quiser, assim, basta fazer uma simples manipulação de variáveis, colocando alguns parâmetros no método construtor do objeto (ou função), pois assim torna-se mais fácil instanciar esse objeto da maneira que quiser.
Um EXEMPLO de como seria instanciado:
PainelPergunta novaPergunta = new PainelPergunta(pergunta, alternativa1, alternativa2, alternativa3, alternativa4, resposta);

Basta organizar seu objeto com alguns algoritmos simples, então no exemplo acima, você pode criar um novo objeto, passando os parâmetros necessários.
Ou também, pode manter sempre o mesmo objeto, e reorganizar os itens e opções contidas nele através de uma função:
NovaPergunta(pergunta, alternativa1, alternativa2, alternativa3, alternativa4, resposta);


Immersion of the manifold in the Flowout Theorem

Question: I am reading John Lee "Introduction to Smooth Manifolds." Flowout theorem states (Theorem $9.20$, Flowout Theorem):
Suppose $M$ is a smooth manifold, $S\subset M$ is and embedded $k$-dimensional sumbanifold,and $V$ is a smooth vector field that is nowhere tangent to $S$. Let $\theta:D\rightarrow M$ be the flow of V, let $O = (\mathbb{R} \times S) \cap D$ and let $\Phi = \theta|_O$ then there exist positive function $\delta: S \rightarrow \mathbb{R}$ such that the restriction of $\Phi$ to $\{(t,p)\in O:|t|<\delta(p)\}$ is injective. In particular $\Phi(\{(t,p)\in O:|t|<\delta(p)\})$ is an immersed sumbanifold.
My question is: why does it not an embedded one? It seems to be an embedded manifold for the case when $S$ has codimension $1$. I was trying to come up with an example but failed.
Comment: Does he require $S$ to be closed? If he doesn't, I guess this is it.
Comment: @AmitaiYuval no he doesn't. What is your idea?
Comment: @AmitaiYuval Oh! I actually see now, thanks
Comment: @AmitaiYuval Do you have an example? Mine turns out to be wrong
Answer: One can use Example 4.20 to show that there exist flowouts (where more generally the domain is an open subset of $\mathbb R \times S$ containing $\{0\} \times S$), which are not embedded:
As in the book, let
$$M:= \mathbb{T}^2 = \left\{ \left( z_1, z_2 \right) \in \mathbb {C}^2
\middle\vert \, \left\lvert z_1 \right\rvert  = \left\lvert z_2 \right\rvert  =1  \right\}$$ be the torus and $\alpha$ be an irrational number. By identifying the tangent bundle of $\mathbb{C}^2$ with $\mathbb C^4$ in the obvious manner, we may consider the vector field
$$\mathbb{C}^2 \to \mathbb{C^4} \quad\colon \quad \left( z_1, z_2\right)
\to \left( z_1, z_2, 2 \pi i \, z_1, 2 \pi i \alpha \, z_2 \right) \, ,$$
which restricts to a smooth vector field $V$ on $M$. The set $S:= \{ (1,1)\}$ is a $0$-dimensional embedded submanifold of $M$. Any non-zero vector at the point is nowhere tangent to $S$ and so is $V$. Now check that
$$\gamma \colon \quad \mathbb R \to M \quad\colon \quad t \to
\left( e^{2 \pi i \, t},  e^{2 \pi i \alpha \, t}\right)$$
is an integral curve of $V$ and defines a flowout from $S$ along $V$ in the sense that $\gamma$, considered as a map defined on $\mathbb R \times S$, is an immersed submanifold. However, $\gamma$ is not a topological embedding, as its image is dense in $M$.
Yet if you restrict its domain to say $(-1,1) \times S$, then it is indeed an embedded submanifold.
My intuition tells me that, even in the general case, making the neighborhood around S 'small enough' (i.e. choosing a different function $\delta'$ on $S$ with $0< \delta' \leq \delta$) should yield embeddedness, but I have not been able to turn this into a rigorous argument yet. The idea behind this is that embeddedness tends to fail either because of similar issues as in the example above or when the manifold `touches itself in the wrong way' (see figure 4.3 in the book).
Comment: Thank you for your answer, but I am a bit confused. You've said that "one can use Example 4.20 to show that there exist flowouts which are not embedded," yet in the second paragraph you claim that it is an embedded submanifold. Are you trying to say that Example 4.20 and Figure 4.3 might be good places to start? I tried those and I can't really come up with an example.
Comment: I said that the above flowout $(\mathbb R \times S, \gamma)$, where $\gamma$ is considered as a map on $\mathbb R \times S$, is an immersed submanifold, but not an embedded one.
Example 4.20 and Figure 4.3 are good illustrations of what may prevent submanifolds from being embedded in general.
However, using the constant rank theorem, one can show that every (immersed) submanifold $N$ of some manifold $M$ is "locally embedded" in the sense that every point $p \in N$ admits an open neighborhood $U$ in $N$ such that $U$ (together with the inclusion mapping) is an embedded submanifold of $M$.
Comment: While I feel honored that you marked the question as answered, I kindly urge you to reconsider. I did give you a counterexample to the claim that all flowouts are embedded. However, the conjecture that there always exist embedded flowouts is still out there - waiting for a proof or a counterexample. I tried proving it, but failed, and I would also be very much interested in a resolution of the issue.


how arrays are treated by gcc [ question related to C programing ]

Question: This compiles in gcc with no errors or warnings even with -Wall option
meaning that array bounds are checked at run-time and hence compiler can't detect the error
#include<stdio.h>

int main()
{
      int a[2][3][4];

      a[1][2][100] = 4 ;

      return 0;
}

However,
#include<stdio.h>

int main()
{
      int a[2][3];

      a[1][2][100] = 4 ;

      return 0;
}

this generates an error while compiling as :
$ gcc sample.c -Wall
sample.c: In function 'main':
sample.c:7: error: subscripted value is neither array nor pointer

Why is this so ? in both the two codes a[1][2][100] is invalid . Still how can the compiler detect this is code2 and not in code1.
Specially when every compiler flattens all multidimensional array into corresponding single dimension arrays, then how can the compiler be selectively aware of this flaw in the code.
Explanation or mention of some book or article where the proper explanation resides will be gratefully accepted :)
Answer: First, array bounds are not checked at runtime or at compile time.  Be careful out there.
Second, your second case gives an error because you have a mismatch in array dimension - you're using three subscript operators ([]) on a 2D array.  Just because the array happens to be laid out in memory as an array of arrays doesn't mean there is any actual type changing going on with the variable.
Array subscripting is described in the C standard section 18.104.22.168 Array subscripting.
Comment: If all arrays are flattened by the compiler how can it discriminate between 2D or 3D arrays.
Comment: @S..K, there's no special case.  You can have arrays of any type. "3D" arrays are just arrays of "2D" arrays, etc.  All indexing is based on pointer arithmetic, which takes into account the size of the object (which again, may be an array).
Comment: The compiler must know the the shape of the array.  All dimensions except the last must be declared.  ex. arr[5][6][].  That's necessary and sufficient to interpret the array.
Comment: The internal implementation details of the array have nothing to do with the type of the variable.  You are trying to treat a 2D array like a 3D array, and that won't work.  You could do some funky typecasting to hack around it, but that's definitely not recommended.  As you noticed, the compiler doesn't care about you accessing memory outside of the array, but it does care about types, and that's where your problem is in example 2.
Answer: The difference is the types. C does no bounds checking but it does do (static) type checking. The type of a in your first example is int[][][] but the type in the second example is int[][].
The "flattening" that you refer to happens in code generation, which is (conceptually, at least) after type checking.
Comment: No. It's because you can subscript an int[] with an int, but you can't subscript an int with an int. If you subscript an int[][][] with an int you get an int[][]. If you subscript that with an int you get an int[]. If you subscript that with an int you get an int.  If you subscript that with an int you get a type error.
Comment: As an aside, the reason I keep saying "with an int" is because you actually can subscript an int with an array. There's no real reason to ever do this, though, so best not to think about it... ;-)
Comment: Is this because int [][] is actually int** and int [][][] is int*** ?
Comment: @SK `int*` and `int[]` are slightly different. Former implies static allocation (data segment, etc) while latter implies dynamic allocation (heap).
Answer: Given
int a[2][3];

the compiler will determine that a[1][2] is of type int. Therefore, accessing element [100] of this is equivalent to:
int x;
x[100] = 4;

This would give you the same error about the subscripted value.


What am I modeling with R vs. SPSS mixed model?

Question: I am trying to model a 3-way repeated measures experiment, FixedFactorA * FixedFactorB * Time[days]. There are no missing observations, but my groups (FactorA * FactorB) are unequal (close, but not completely balanced). From reading online, the best way to model a repeated measures experiment in which observation order matters (due to the response mean and variance changing in a time-dependent way) and for unequal groups is to use a mixed model and specify an appropriate covariance structure.  However, I am new to the idea of mixed models and I am confused as to whether I am using the correct syntax to model what I am trying to model.
I would like to do a full factorial analysis, such that I could detect significant time * factor interactions.  For example, for subjects with FactorA = 1, their responses over time might have a different slope and/or intercept than subjects with FactorA =2.  I also want to be able to check whether certain combinations of FactorA and FactorB have significantly different responses over time (hence the full three-way interaction term).
From reading online, it seems like AR1 is a reasonable covariance structure for longitudinal-like data, so I decided to try that.  Also, I saw that one is supposed to use ML if one plans to compare two different models, so I chose that approach in anticipation of needing to fine-tune the model.  It is also my understanding that the goal is to minimize the AIC during model selection.
This is the code in the log for what I tried in SPSS (for long-form data), which yielded an AIC of 2471:
<code>MIXED RESPONSE BY FactorA FactorB Day
  /CRITERIA=CIN(95) MXITER(100) MXSTEP(10) SCORING(1) SINGULAR(0.000000000001) HCONVERGE(0,
ABSOLUTE) LCONVERGE(0, ABSOLUTE) PCONVERGE(0.000001, ABSOLUTE)
  /FIXED=FactorA FactorB Day FactorA*FactorB FactorA*Day FactorB*Day FactorA*FactorB*Day | SSTYPE(3)
  /METHOD=ML
  /PRINT=SOLUTION TESTCOV
  /REPEATED=Day | SUBJECT(Subject_ID) COVTYPE(AR1)
</code>
This is what I tried in R, which yielded an AIC of 2156:
<code>    require(nlme)

    #output error fix: https://stats.stackexchange.com/questions/40647/lme-error-iteration-limit-reached

    ctrl <- lmeControl(opt='optim')

    fit1 <- lme(RESPONSE ~ Day*FactorA*FactorB, random = ~ Day|Subject_ID, control=ctrl,
        correlation=corAR1(form=~Day), data, method="ML")

    summary(fit1)
</code>
These are my questions:

The SPSS code above yielded a model with AIC = 2471, while the R code yielded a model with AIC = 2156.  What is it about the codes that makes the models different?
From what I described above, are either of these models appropriate for what I am trying to test? If not, what would be a better way, and how would I do it in both programs to get the same results?
What is the appropriate way to compare models in both R and SPSS, such that the comparison tests are the same regardless of the software being used? For example, how do you do something like anova.lme() in SPSS?

Edits
Another thing to note is that I didn't dummy-code my factors.  I don't know if this is a problem for either software, or if the built-in coding is different in SPSS vs R.  I also don't know if this will be a problem for my three-way interaction term.
Also, when I say "factor", I mean an unchanging group or characteristic (like "sex").
Comment: Check the final model coefficients. Are they the same in SPSS as in R?
Comment: _"What is it about the codes that makes the models different?"_: a programming question, but AIC includes a term which is constant across models; many ommit this term.
Comment: I'm not completely sure about model coefficients (as nothing is labeled as such in the output), but the fixed-effects "values" column in the R output and the estimates of fixed effects "estimates" column in the SPSS output do not match
Comment: You cannot compare AIC between different software unless you know exactly what formula they both use. Even then it is best used to compare models within software.
Answer: Normally, CrossValidated is not for programming questions. That would be Stack Overflow, but it looks like your SPSS syntax does not include a random component nor have you specified a covariance structure, which would yield different AIC values.
For longitudinal analysis using multi-level modelling (also called hierarchical level modelling), you first should create an"unconditional model," such that
$Level 1:$
$y=\beta_0+\beta_1(time_{j})+e_{j}$
$Level 2:$
$\beta_0=\gamma_{00}+U_0$
$\beta_1=\gamma_{10}+U_1$
Where $Var(e_{j})=\sigma^2$, $Var(U_0)=\tau_{00})$, $Var(U_1)=\tau_{11}$, and $Cov(U_1,U_2)=\tau_{01}$, or in matrix notation:
\begin{equation*}
\begin{bmatrix}
\ \tau_{00} & \tau_{01} \\
\ \tau_{10} & \tau_{11}
\end{bmatrix}
\end{equation*}
Now, construct a "conditional model," with a control group ($group_{j2}$)
$Level 1:$
$y=\beta_0+\beta_1(time_{j1})+\beta_2(group_{j2})+e_{j}$
$Level 2:$
$\beta_0=\gamma_{00}+U_0$
$\beta_1=\gamma_{10}+U_1$
$\beta_2=\gamma_{20}+U_2$
Where $Var(e_{j})=\sigma^2$, but the $\tau$ matrix now has an added element, such that:
\begin{equation*}
\begin{bmatrix}
\ \tau_{00} & \tau_{01} &\tau_{02}\\
\ \tau_{10} & \tau_{11} & \tau_{12}\\
\ \tau_{20} & \tau_{21} & \tau_{22}
\end{bmatrix}
\end{equation*}
Further, you can add two time-variant predictors (which you call factors and I notate as $factor_ij$). Thus, observations over $time_j$ are nested in factors, such that:
$Level 1:$
$y=\beta_0+\beta_1(time_{j1})+\beta_2(group_{j2})+e_{ij}$
$Level 2:$
$\beta_0=\gamma_{00}+\gamma_{01}(factor_{ij})+U_0$
$\beta_1=\gamma_{10}+\gamma_{11}(factor_{ij})+U_1$
$\beta_2=\gamma_{20}+\gamma_{21}(factor_{ij})+U_2$
Where Where $Var(e_{j})=\sigma^2$, and the $\tau$ matrix is:
\begin{equation*}
\begin{bmatrix}
\ \tau_{00} & \tau_{01} &\tau_{02}\\
\ \tau_{10} & \tau_{11} & \tau_{12}\\
\ \tau_{20} & \tau_{21} & \tau_{22}
\end{bmatrix}
\end{equation*}
Then, repeat each of these models, but where $Var(e_{ij})=AR(1)$, with rows and columns equal to $j$
\begin{equation*}
\begin{bmatrix}
\ 1 & \rho & \dots & \rho^{j-1}\\
\ \rho & 1 & \dots & \rho^{j-2}\\
\ \vdots & \vdots &\ddots & \vdots\\
\ \rho^{j-1} & \dots & \dots & 1
\end{bmatrix}
\end{equation*}
Each of these six models yields an AIC. You can compare using a $\chi^2$ difference test, where the AIC is your test statistic and the number of estimated parameters is your $df$.
For more information, see Raudenbush & Bryk (2002).
Comment: I thought that I took care of the subject effect using the "repeated" part; in that part of the spss code, I specified the covariance structure based on the instructions from the help website.   Is this not appropriate?  What is the difference between /REPEATED and /RANDOM?
Comment: Stack Overflow is better suited to continue your question about SPSS syntax. I only use SPSS if absolutely necessary because I pRefeR R. I justknow it doesn't match my template for longitudinal mixed models, but there's more than one way to skin() a print.cat().
Comment: Also, factor A and Factor B are constant.  They do not vary over time.  For example, "Sex" could be one of the factors.
Comment: Ah! If Factor A and Factor B are constant, they would be "time-invariant" and would go on the level-1 of the hierarchical linear model.
Comment: Since you are an R user: how does the R code I had for fit1 compare to the fancy equations in your answer?  `fit1 <- lme(RESPONSE ~ Day*FactorA*FactorB, random = ~ Day|Subject_ID, control=lmeControl(opt='optim'),
        correlation=corAR1(form=~Day), data, method="ML")`  Or should I re-ask this question on stackoverflow?
Comment: I recommend Stack Overflow. I do recommend getting a pencil and some paper and finding the "mixed model," which is where you plug in the $\beta$ equations into $Level 1$. There, you'll see that the fixed effects have gamma coefficients and the random effects are distributed on the $U$ terms. I've never used the `control` command in `lme` because I think a grouping variable in level 1 makes more sense.
Comment: While the above is good information, I am not sure the decomposed notation from raudenbush & Bryk will help when using R. lme4 and other packages use coding schemes that translate well into non-decomposed model statements. Decomposes notation does not really help all that much. And for what its worth, I feel that Raudenbush & Bryk (2002)'s technique is great for organizational research but is not nearly as intuitive for longitudinal research. Further, I feel they dont really handle model effect sizes well. But I know that researchers in education seem to love the text. I prefer Faraway (2014).
Comment: I must admit that I am struggling to understand the notation and how it relates to the syntax for R.  Also, I used the control command because otherwise I get an error...I don't really understand what it is.
Comment: I have [re-posted on stackoverflow](https://stackoverflow.com/questions/47722731/r-vs-spss-mixed-model-repeated-measures-code-from-cross-validated) as well


Piano Technique when coming from an organ

Question: I've been playing the organ for over 10 years, and for the past year I've started learning piano.
The fact I came with a background made it much easier for me, since I didn't need to start from scratch, considering theory, harmony, reading notes and so on.
But on the other hand, I'm totally bad in technique: soft voices and etc. My teacher thinks it's probably because I've been playing the organ for so many years. Most of the lesson goes on learning the correct position ,relaxation   which causes me much frustration, since their is a progress but it's slow.
Do you any advice for me? Recommended Exercises?
Thanks
Comment: I would recommend to take drum lessons (just hands, no sticks), since the movement of your hands is very similar in my opinion.
Answer: Your basic problem is that your organ technique will "get you by" on the piano in the sense that you can play the right notes at the right time, but the techniques of the two instruments are really very different.
Probably the quickest way in the long run is to put most of your effort into technical exercises that force you to use "piano technique" rather than "organ technique". Most exercises for beginners on the piano are intended to develop finger independence and dexterity, and you (probably) already have those skills. I would suggest starting with more advanced studies on topics like octave playing, which will force you out of "organist mode" and into "piano mode".
These might get you started:
http://imslp.org/wiki/6_Exercises_in_Octaves,Op.553(Czerny,_Carl)
or the second part of
http://imslp.org/wiki/Die_Schule_des_Octavenspiels,Op.48(Kullak,_Theodor)
or these (not limited to octave playing!) http://imslp.org/wiki/51_Exercises,_WoO_6_(Brahms,_Johannes)
Control of dynamics on the piano will probably develop naturally, once you break the "organist mode" habit of only using finger action to play the notes.
Comment: Don't stop!  Why throw away that technique?  Would a clarinetist of ten years' experience risk getting rusty there while picking up the baritone sax?
Comment: Thanks. Should I stop playing the organ for the meantime, until  I get into the "piano mode"?
Answer: The frustration may come from a vague expectation of being able to quickly progress to advanced repertoire.  As you've seen, you can play advanced pieces but with nonpianistic technique, and it's drudgery to have to revert to musical pablum like Czerny.
So try to find pride in the pablum.  A nonmusical analogy:  I've flown radio-control sailplanes for fifteen years.  This summer I started flying an agile micro rc helicopter.  Although their thumb motions correspond, my heli "technique" is zilch.  Over the past two weeks I've had to enjoy the progression from hopping off the ground for a few seconds, to sustaining a hover for thirty seconds without wandering into the trees.  Eventually I'll be able to maneuver it as precisely as how my sailplane can nail a thermal signalled by a circling hawk, but for now...
Answer: Relaxation, both physically and mentally, and not expecting too much too soon, are probably the key aspects.
What degrees of dexterity or difficulty in specific aspects of piano playing could be expected, considering you are an experienced organist, is debatable. But what's certain is that anxiety and over expectations will only add to the (presumed) problem.
I don't think any specific exercises are necessary than what would be normal when starting to learn the instrument, regarding dynamics. Playing soft, playing loud, very soft, very loud, doing a crescendo, doing a diminuendo. Playing short and easy pieces, from any piano method book, that work out these aspects. Start with book 1 if you have too, I'm sure you will do better than any 8 or 10 year old (I don't mean to be sarcastic, I just want to show that there is certainly no inherent problem with you).
Just don't skip over levels of difficulty in that particular aspect, just because you are more advanced in other aspects. Most of all, relax (without frustration, I hope) and enjoy the pleasure of learning a new instrument.
Answer: Old post, but I saw it get recent activity. So, I thought I could add something too.
These question seems to be about touch. Piano has that aspect, but organ doesn't.
Finger independence exercises probably are thought of as coordination of fingers for beginners only. But I think they are also about evenness of touch. Even if that is old hat on the organ, it might be worth revisiting on piano with attention to even touch.
Also I think some repeated note exercises are about developing good touch. Mason, Touch and Technic seems like one good source to look at in that regard. It has a whole series of repeated note scales where the goal is to develop good touch.


Minimum area of a triangle

Question: In triangle inscribed circle with radius $r = 1$ and one of it sides $a=3$. Find the minimum area of triangle? Ans = 5.4
My reasonings:

$BC = a$, $AC = b$, $AB = c$
$AD=AF=x$
$FC=CE=y$
$BD=BE=z$
$a=z+y$, $b=x+y$, $c=x+z$
The radius of the incircle is $$r =\frac{A_{ABC}}{s}$$ where $s = \frac{a+b+c}{2} =  x + y+ z$. By condition $z+y=3$ so $s=x+3$
By Heron's formula, the area of the triangle is $A=\sqrt{s(s-a)(s-b)(s-c)}$
In other side $A=sr = x+3$.
What is next? I think that I should get a fucntion for which I will can find a minimum, but I don't know how.
Comment: If you can prove that the least area occurs when side $a$ is the base of an isosceles triangle then you are done.
Comment: @RicardoCruz Isnt that case for the maximum area?
Answer: You were on the right track.
Using your notation, $A = \sqrt{s(s - a)(s - b)(s - c)} = \sqrt{(x + 3)xyz}$, but also $A = x + 3$. So
$$\begin{align}
\sqrt{(x + 3)xyz} &= x + 3, \\
xyz &= x + 3, \\
x &= \frac{3}{yz - 1}.
\end{align}$$
Substituting that into $A$ we get
$$A = \sqrt{\left(\frac{3}{yz - 1} + 3\right)\frac{3}{yz - 1}yz} = \sqrt{\frac{3yz}{yz - 1}\cdot\frac{3}{yz - 1}yz} = \frac{3yz}{yz - 1} = \frac{3}{yz - 1} + 3.$$
Finally, by AM-GM we get lower bound:
$$A = \frac{3}{yz - 1} + 3 \geqslant \frac{3}{\frac{(y + z)^2}{4} - 1} + 3 = \frac{3}{\frac{9}{4} - 1} + 3 = \frac{12}{5} + 3 = \frac{27}{5} = 5.4$$
Because it is AM-GM, equality is reached when $y = z = 1.5$

P.S. You may wonder, why for some values of $y$ and $z$ expression $\frac{3}{yz - 1}$ may become infinite or negative. Isn't it strange? Besides, I myself silently assumed that it is positive. And there's a reason for that.
Positive values of $\frac{3}{yz - 1}$ correspond to the situation you describe: a circle inscribe in a triangle.
When it becomes infinite two sides $AB$ and $AC$ become parallel.
And finally, when it's negative, your circle is no longer an incircle, it becomes excircle.
Comment: @AlexanderSide AM-GM looks like $\sqrt{yz} \leqslant \frac{y+z}{2}$. Starting from there we get
$$\begin{align}
yz &\leqslant \left(\frac{y+z}{2}\right)^2 = \frac{(y+z)^2}{4}, \\
yz-1 &\leqslant \frac{(y+z)^2}{4} -1, \\
\frac{3}{yz-1} &\geqslant \frac{3}{\frac{(y+z)^2}{4} - 1}.
\end{align}$$
Comment: Thank you. But can you explain last part yours solving? How do you get $\frac{(y+z)^2}{4} - 1$ in right side in denominator?
Answer: Trigonometric approach:
In your notation,
$AD=AF=x$, $FC=CE=y$, $BD=BE=z$,
denote in addition
$\alpha=\angle OAF=\angle OAD$,
$~~~\beta=\angle OCF=\angle OCE$,
$~~~\gamma=\angle OBE=\angle OBD$.
So, if $r=1$, then
$x=\dfrac{1}{\tan\alpha}$,
$~~~y=\dfrac{1}{\tan\beta}$,
$~~~z=\dfrac{1}{\tan\gamma}$.
Then, as you said,
$$
A=r(x+y+z)=r(x+3)=x+3.
$$
$$
x = \dfrac{1}{\tan(90^\circ - \beta-\gamma)} = \tan(\beta+\gamma) = \dfrac{\tan\beta+\tan\gamma}{1-\tan\beta\tan\gamma}.
$$
Dividing numerator and denominator by $(\tan\beta\tan\gamma)$, we get:
$$
x=\frac{z+y}{yz-1}=\frac{3}{yz-1}.
$$
$$
A=x+3=\frac{3}{yz-1}+3.
$$
Further thoughts - as in answer of ElThor.

Minimum area of a triangle


Finite coloring of an interval

Question: Two real functions, $f$ and $g$, are defined on the interval $[-1,1]$. Each point $x$ in the interval is colored in one of 3 colors:

Red - if $f(x)>g(x)$
Blue - if $f(x)=g(x)$
Green - if $f(x)<g(x)$

Let $N(f,g)$ be the number of intervals of different colors. I.e., if $f(x)=x$ and $g(x)=0$ then there are 3 intervals: green $[-1,0)$, blue $[0,0]$, red $(0,1]$.
What conditions on the functions $f$ and $g$ are necessary and sufficient to guarantee that $N(f,g)$ is finite?
Answer: If the number of crossings $f(x)= g(x) $ is finite we could still have a pathological function such that such as $f=1$ for $x$ rational and $f = -1$ for $x$ irrational and $g = -f,$ in which case there are only finitely many points of equality but infinitely many changes of color.
On the other hand if we require finitely many changes of sign for $f-g$ and include $f-g=0$ to $f-g\neq 0$ as a change of sign (as well as $f<g$ to $f>g$) then this assures finitely many changes of color (hence finitely many different colored intervals).
A more basic way to avoid infinitely many intervals is to require $f,g$ be monotone and continuous. Continuity by itself is not sufficient. Monotonicity seems excessive in light of the above but I can't think of milder restrictions that don't invite counter-examples.
Comment: I have assumed "the number of intervals of different colors" counts red/blue/green/red as 4 intervals.
Comment: Is there a more basic property / term that describes such functions?
Comment: @ErelSegalHalevi: The restriction of the second paragraph we might as well call the "avoid having infinite intervals" property. Maybe something like continuity plus (?) in the third paragraph could work although monotonicity seems excessive. This is a nice question and I hope you get other responses. The problem with basic answers is that there are a collection of pathological functions that can defeat desired properties in surprising ways. The challenge is to find something both suff. and necc.

Finite coloring of an interval