How to find the complexity of a program to find the length of the largest sub string?

Question: I wrote a sample javascript program to find the length of the largest sub string of a given string and it works. I am not able to calculate its time complexity. Can someone help me?
I do understand that a program with two loops is quadratic complexity, that with three loops has cubic complexity and so on. Is this always true?
This program has two loops. Can I say that its complexity is O(n^2)?
function AllSubStrings()
{
    var myString = prompt("Enter the string");
    var arr = myString.split("");
    var tempArr = [];
    var maxLength = 0;

    for(var i = 0; i<arr.length; i++)
    {
        temp = null;

        for(var j = i; j<arr.length; j++)
        {
            if(j === i)
            {
                tempArr.push(arr[j])
                temp = arr[j];
            }
            else
            {
                temp = temp + arr[j];
                if(temp.length > maxLength)
                {
                    maxLength = temp.length;
                }
                tempArr.push(temp);
            }
        }
    }
    document.write("All SubStrings are: "+tempArr+"
");
    document.write("Length of the largest substring is: "+maxLength);
}

Answer: You have two nested loops of order n (where n is the length of string), so is O(n*n) = O(n2).
There are some other operations which are not important in calculating big O, e.g Split, takes O(n), but compare to O(n2) is not important, or push and pop, ... in each for loop takes O(1), but it's not important if we have multiple O(1) operations.
For elaboration: We know that the first loop runs n times, but about the second loop, it will run O(n-i) time, so total running time is:
Σ(n-i) = Σ n - Σ i = n2 - n(n-1)/2 = O(n^2).
Comment: Can you elaborate please. I do understand that the first loop will run n times (where n is length) but the second loop depends on i. So how do I do it?
Answer: As you have two loops of order N, complexity is O(N2).
Answer: Simple answer : As you have two nested loops each running in order of n, the total runtime is O(n*n).
Little more detailed one: first loop runs from 0 till n-1, second one runs from i till n-1.
so for each i inner loop runs for n+n-1+n-2+...1 = n*(n+1)/2= O(n*n)


Pagina de login utilizando mysqli_fetch_row

Question: Estou criando uma página bastante simples de login onde o usuário digite o seu nome e senha, o sistema faz varredura no banco de dados(mysql) e valida sua entrada, porém, quando eu entro com os valores corretamente o sistema retorna null.
Segue o código html

UP Consultoria

Faça seu login

        <form  method="post" action="teste.php"  id="searchform">
          <input  type="text" name="name">
          <input  type="text" name="password">
          <input  type="submit" name="submit" value="Entrar">
        </form>

     `

Segue o código php:

    <?php
      if(empty($_POST['name']) or empty($_POST['password'])){
        echo "Digite valores válidos";
      }else{
      $nome=$_POST['name'];
      $senha=$_POST['password'];
      $link = mysqli_connect('localhost', 'root', '','Upconsul') or die (mysql_error());
      if($resultado = mysqli_query($link,"SELECT nome FROM usuarios WHERE nome=$nome",MYSQLI_USE_RESULT)){
        while($row = mysqli_fetch_row($resultado)){
            printf ("%s/n" ,$row[0]);
        }
        mysqli_free_result($resultado);
        }
    mysqli_close($link);
    }
?>

Tenho certeza que é alguma coisa bem banal, se puderem me ajudar fico grato. Estou usando phpmyadmin para simular o servidor.
Answer: Utilize prepared statements, para evitar sql injections e não armaze senhas como texto puro.
Ao usar passa os valores diretamente na consulta os valores string(varchar e outros do tipo texto) necessecitam de aspas simples.
mysqli_query($link,"SELECT nome FROM usuarios WHERE nome = '$nome'")

Leitura recomendada:
Select com prepared statements MySQLi


Updating Contact causing wrong values to be written

Question: I am trying to display the name, phone number and email of a contact and letting the user update any of the values. For some reason, the value of email is overwritten on all three fields when my code is executed. There's got to be a glitch in the logic here, but I cannot figure it out.
Here's my method which updates the Contacts URI.
<code>private void updateContact() {
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    ops.add(ContentProviderOperation.newUpdate(ContactsContract.RawContacts.CONTENT_URI)
            .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, name)
            .build());
    ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name)
            .withValue(ContactsContract.Data.MIMETYPE,
                        ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
            .build());
    ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phoneNumber)
            .withValue(ContactsContract.Data.MIMETYPE,
                    ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
            .build());
    ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE,
                            ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
            .build());

    try {
        getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
        // Display update
        Context ctx = getApplicationContext();
        CharSequence txt = "Contact Updated";
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(ctx, txt, duration);
        toast.show();

    } catch (Exception e) {
        // Display warning
        Context ctx = getApplicationContext();
        CharSequence txt = "Update Failed";
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(ctx, txt, duration);
        toast.show();

    }
}
</code>
Answer: see this link:
http://comments.gmane.org/gmane.comp.handhelds.android.devel/92848
" you shouldn't specify the mime type in an update statement - it is not updatable."
"Your query says: "update all data rows for this contact, setting one of the fields to "John" and another to "Abraham".  Data rows include phone numbers, emails, photos, you-name-it.  What you need to do is find a specific data row you want to update and then use its _id in the selection (or, more commonly, in the URI itself)."
"The data structure for contacts is based on three separate tables:  Contacts, RawContacts and Data.  A Contact can have multiple RawContacts, which can have multiple Data rows.  Each data row has a mime type that specifies what kind of data is stored in that row.  Contact name is stored in a row with the mime type StructuredName.CONTENT_TYPE.
So, in order to change the contact name you first need to find the Data row that contains the name and then update that Data row.  The provider will take care of the rest (e.g. promoting the name to the level of RawContact and then Contact)."
Answer: Also see
http://www.eoeandroid.com/sdk/api/reference/android/provider/ContactsContract.Data.html
must get the dataId first :
ArrayList ops = Lists.newArrayList();
 ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
          .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)})
          .withValue(Email.DATA, "firstname.lastname@example.com")
          .build());
 getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);


Using sapp() to apply terra::focal to each layer of a SpatRaster

Question: I have recently started using terra and must commend the devs, it has made my life so much easier whilst working with many large rasters in R. However, I've stumbled into a minor issue, I am attempting use sapp to apply a focal function to each layer in a SpatRater as focal can only be applied to one layer at a time.
With a small reproducible RasterSpat I can run the following as an example of the desired output:
library(terra)
packageVersion("terra")
>[1] '1.2.10'

s <- rast(system.file("ex/logo.tif", package="terra"))
s <- ifel(s == 255, 1, NA)

r1 <- terra::focal(s[[1]], w=3, fun = "any", na.only=TRUE)
r2 <- terra::focal(s[[2]], w=3, fun = "any", na.only=TRUE)
r3 <- terra::focal(s[[3]], w=3, fun = "any", na.only=TRUE)
r <- c(r1,r2,r3)
r

#class       : SpatRaster
#dimensions  : 77, 101, 3  (nrow, ncol, nlyr)
#resolution  : 1, 1  (x, y)
#extent      : 0, 101, 0, 77  (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
#sources     : memory
#              memory
#              memory
#names       : red, green, blue
#min values  :   0,     0,    0
#max values  :   1,     1,    1

When I run sapp for the above reproducible data using the same grammar as sapply:
f1 <- sapp(s, fun = function(x){terra::focal(x = x, w = 3, fun = "any", na.only = TRUE)})

I get:

Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'rast': unused argument (wopt = wopt)

If I try:
f <- sapp(s,  terra::focal, c(w= 3, fun = "any", na.only = TRUE))
f

I get the following:
#class       : SpatRaster
#dimensions  : 77, 101, 3  (nrow, ncol, nlyr)
#resolution  : 1, 1  (x, y)
#extent      : 0, 101, 0, 77  (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
#source      : memory
#names       : red, green, blue
#min values  :   0,     0,    0
#max values  :   9,     9,    9

Notice the max values of the layers. How can I adjust my code to get sapp to work as desired?
I can get the desired result with sapply, but I assume sapp would be far more efficient for larger data if I can get it to work.
f2 <- sapply(as.list(s), function(x){terra::focal(x = x, w= 3, fun = "any", na.only = TRUE)})
f2 <- rast(f2)
f2
#class       : SpatRaster
#dimensions  : 77, 101, 3  (nrow, ncol, nlyr)
#resolution  : 1, 1  (x, y)
#extent      : 0, 101, 0, 77  (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
#sources     : memory
               memory
               memory
#names       : red, green, blue
#min values  :   0,     0,    0
#max values  :   1,     1,    1

If anybody can provide some assistance, it would be greatly appreciated :)
Answer: I have solved my issue.
Turns out you need to include the ... argument to the function sent to fun like so:
s <- sapp(s, fun = function(x, ...) {focal(x, fun = "any", w = 3)})

Then it works
As it turns out sapp calls sapply internaly and hasn't implemented parallelization yet and multiple core can't be allocated, so there is not much of a speed improvement as compared to app which implements parallelization vs apply.
Here are some benchmarks if any body is interested...
terra::terraOptions(todisk = TRUE)
s <- rast(system.file("ex/logo.tif", package="terra"))
s <- terra::extend(s, c(500, 500))
s <- disaggregate(s, 10)
s <- terra::ifel(s == 255, 1, 0)

a <- function() {
    s <- sapply(as.list(s), function(x){terra::focal(x = x, w= 3, fun = "any")})
    s <- rast(s)}

b <- function(){
    s <- sapp(s, fun = function(x,...) {focal(x, fun = "any", w = 3)})}

race <- microbenchmark::microbenchmark(
    a(),
    b(),
    times = 5)

Results:
race
Unit: seconds
 expr      min       lq     mean   median       uq      max neval cld
  a() 63.32553 63.93399 65.03783 65.61699 65.73256 66.58011     5   a
  b() 62.88114 63.85961 64.34571 64.16861 65.22703 65.59215     5   a


Adding two binary arrays in C++

Question: How can I add two binary arrays(8 bits) and store the result in a third binary array in visual studio 2010 - C++ .
Example : A=00100011   B=11011100   the result_array=11111111
I tried doing that using this to convert B (have decimal value) into binary:
std::string binary2 = std::bitset<8>(B).to_string();
but when I added the two binary array and storing them into third integer array ,the third array didn't take any value results from the adding operation and still having the default value (which is 00000000)
Thanks in advance!
Comment: Please show your code.
Comment: If the inputs were both 00000001 what output would you expect?
Answer: If your desired result is bitwise manipulation (as in):
 10101011
+11011100
=11111111

Then you need to use bitwise or (|)
uint8_t a = 0x23;
uint8_t b = 0xDC;

uint8_t c = a | b;

If you want to do simple addition, such as:
 00000001
+00000011
=00000100

Then that is just addition.
uint8_t a = 1;
uint8_t b = 2;

uint8_t c = a + b;

Comment: 00100011 & 11011100 is 00000000. Should be `|` (bitwise or) to obtain 11111111
Comment: It's not clear whether the OP wants `0x01 + 0x01` to be `0x01` or `0x10`. If the latter, then your suggestion won't work.
Comment: Two good comments.  In the OP's question he states that the desired output is `0xFF` (Which isn't actually addition, but bitwise or).
Comment: @Chad - it might be addition, the example is unclear
Comment: You're right.  Jumped the gun on the answer in this case.  So I've just given examples of both.
Answer: Call the binary arrays boolean arrays and work from the back:
    #include <iostream>

    int main(int argc, char* argv[])
    {
        bool a[8]={0,0,1,0,0,0,1,1};
        bool b[8]={1,1,0,1,1,1,0,0};
        bool c[8];

        bool remainder=false;
        for(int x=7;x>=0;x--)
        {
            unsigned sum=0;
            if(remainder)++sum;
            if(a[x])++sum;
            if(b[x])++sum;
            if(sum%2==1)c[x]=true;
            else c[x]=false;
            if(sum>1)remainder=true;
            else remainder=false;
        }
        for(unsigned x=0;x<8;++x)
        {
            std::cout << c[x];
            if(x!=7)std::cout << ",";
        }
        std::cout << std::endl;

        return 0;
    }

Adding two binary arrays in C++


How to create path for taxonomy term pages with parent terms if they exist

Question: I have a taxonomy vocabulary which will only ever contain 2 level deep hierarchy.
I need the url to be just [vocabulary]/[term] for any parent term.
But for a child term I need it to be the following
[vocabulary]/[parent_term]/[term]
Is this possible with a pathauto token? If not, is there another solution to this?
Answer: You can use pathauto token like this.
<code> [term:vocabulary]/[term:parents:join-path]/[term:name]
</code>
Comment: You missed a "/" above
Comment: Thanks, what will happen if the parent does not exist?
Comment: If parent does not exist then vocabulary/term name
Comment: Sorry But I added screenshot.
Comment: I just wanted to say because for future people might get confused. Thanks


while loop to insert data into table in sql

Question:  declare @temp int,
@temp1 int,
@temp2 int,
@temp3 int,
@temp4 int,
@temp5 int,
@modid int,
@supid int,
@sid varchar(50)
begin tran
select * from StudentSupervisor;

select @temp = count(*) from Students s where s.IsLockedOut = '0' and s.IsGraduated = '0';
select @temp1 = count(*)  from staffs st where st.IsLockedOut ='0';

set @temp5 = round(@temp/@temp1,0);

WHILE (select count(*) from students s where s.IsLockedOut ='0' and s.StudentId not in (select ss.StudentId from StudentSupervisor ss where s.StudentId = ss.StudentId and ss.IsApproved = 1)) != 0

BEGIN

select top 1 @sid = s.studentid from students s, StudentSupervisor ss where s.IsLockedOut ='0' and s.StudentId not in (select s.StudentId where s.StudentId = ss.StudentId and ss.IsApproved = 1);

select top 1 @supid = st.Staffid, @modid = st.moderatorid from Staffs st where st.IsLockedOut =0 and Quota <=@temp5;

        insert into StudentSupervisor
        (StudentId,SupervisorId,ModeratorId,IsApproved)
    values
        (@sid,@supid,@modid,1)
        update Staffs set quota +=1 where staffs.StaffID = @supid;

END

select * from StudentSupervisor;

ROLLBACK  tran

Hi all, i am quite stuck on this logic and i did search for solution but i get nothing after overnight work, let me clear with my situation now, first i would like to take count of student that not in studentsupervisor table or in studentsupervisor table but isapproved !=1, then i take the count of staff that quota is not more than total student / total staff,after that i would like to pump student together with staff into studentsupervisor table while they still available.. please let me know what wrong with my dynamic query, thanks
Comment: why not use a loop in your business logic, not in your stored proc as much as possible
Answer: I am having trouble understanding your question.  I think your loop condition should be:
WHILE (SELECT COUNT(*) from students WHERE StudentID NOT IN (SELECT StudentID FROM StudentSupervisor WHERE IsAppoved = 1)) <> 0

Depending on what you are trying to do in the loop, it will probably be possible to remove the loop.  If you can update your question with more detail on what is happening in the loop and an example I will try to provide a more complete answer.
Update:
In that case I would also update the first line in the loop to:
select top 1 @sid = studentid from students WHERE IsLockedOut = 0 and StudentId NOT IN (SELECT StudentID FROM StudentSupervisor WHERE IsAppoved = 1);

Update2 Table variable option:
declare @temp int,
    @temp1 int,
    @temp2 int,
    @temp5 int,
    @PairCount int,                         --The number of students paired with a staff member.
    @modid int,
    @supid int,
    @StaffQuotaNeed int,                    --The number of students the staff needs to be paired with to meet quota.
    @sid varchar(50)
DECLARE @StaffToPair table
    (
        StaffID int NOT NULL,
        ModeratorID int NOT NULL,
        QuotaNeed int NOT NULL          --The number of students the staff needs to be paired with to meet quota.
    );
DECLARE @StudentsToPair table (StudentID int NOT NULL);
DECLARE @StudentsPaired table (StudentID int NOT NULL);

begin tran
select * from StudentSupervisor;

select @temp = count(*) from Students where IsLockedOut = '0' and IsGraduated = '0';
select @temp1 = count(*)  from staffs where IsLockedOut ='0';
set @temp5 = round(@temp/@temp1 + .5, 0);                   --Round Up

INSERT INTO @StaffToPair (StaffID, ModeratorID, QuotaNeed)
                    SELECT StaffID, ModeratorID, @temp5 - Quota FROM Staffs WHERE IsLockedOut =0 AND Quota <@temp5;
INSERT INTO @StudentsToPair (StudentID)
                    SELECT StudentID from students WHERE IsLockedOut = 0 AND StudentId NOT IN (SELECT StudentID FROM StudentSupervisor WHERE IsAppoved = 1);

WHILE (SELECT COUNT(*) from @StudentsToPair) > 0 AND (SELECT COUNT(*) from @StaffToPair) > 0
BEGIN
    SELECT TOP 1 @supid = Staffid, @modid = ModeratorID, @StaffQuotaNeed = QuotaNeed FROM @StaffToPair;

    INSERT INTO StudentSupervisor   (StudentID, SupervisorId, ModeratorId, IsApproved)
        OUTPUT INSERTED.StudentID INTO @StudentsPaired(StudentID)
        SELECT TOP (@StaffQuotaNeed) StudentID,     @supid,     @modid,         1 FROM @StudentsToPair;

    DELETE FROM @StudentsToPair WHERE StudentID IN (SELECT StudentID FROM @StudentsPaired); --Delete paired students from table variable.
    DELETE FROM @StaffToPair WHERE StaffID = @supid;                                        --Delete paired staff from table variable.

    SELECT @PairCount = COUNT(*)  FROM @StudentsPaired;
    UPDATE Staffs set Quota += @PairCount where staffs.StaffID = @supid;
END

select * from StudentSupervisor;

ROLLBACK  tran

If the above does not work then please update your question to contain the table schema's so I can test it on my system.
Comment: ops! thanks for pointing out... i have tables name staffs, student, studentsupervisor, and i want to do some kind of autoassign to put my student and staff into studentsupervisor table while staff have not reach the quota..
Comment: @user1824745 I have updated my answer.  Add a comment if you want an example of the option I am suggesting.


What determines the cost function / how to find the cost function to use

Question: I'm starting to learn a bit about gradient descent, and that method attempts to minimize the cost function. I've seen examples using linear regression, and the corresponding cost function, but now I'm wondering, given an arbitrary function $g(x)$ which computes an output $y$, will the cost function to use for gradient decent always be:
$$y_{k} - g(x_{k})$$
resulting in the gradient descent of
$$y_{k+1} = y_{k} - {d \over dx}  g(x_{k})$$
Answer: Commonly used cost functions are:

Squared error cost function
Negative log likelihood

Regardless of what cost function you use the gradient descent rule is always applicable. The gradient is normally calculated analytically, which depends on the cost function used.


Compress data before transfer between Spring application and MongoDB server

Question: A list of big documents need to be transferred between my Spring Boot application and MongoDB server. How to config the MongoDB server and the Spring application to compress the data before the transmission?
MongoDB version is 4.2
Answer: MongoDB Storage engine does support different configuration for compression, for more information follow below link.
https://www.mongodb.com/blog/post/coming-in-42-compression-key-rotation-and-configuration
But there is no such configuration to compress the document before transmission.
Not sure with your use case but from SpringBoot application you can compress the data and store it as a compressed document in MongoDB and uncompress in application after reading from MongoDB.


What is the Area vector for polar co-ordinates?

Question: I know the Surface area element for polar co-ordinates is:
dA = r dr d(theta/phi)
whereas... what is the area vector?
I know the area vector is perpendicular to the to the surface plane but between x, y, r and theta/phi
which vector matches that description? I assumed the position vector/radial vector as being the "direction" for the area vector.. but i have nowhere to confirm this.
Comment: so what is dA ⃗
Comment: $dxdy=rdrd\theta$ in $\mathbb{R}^2$ so what do you mean by surface area?  Perpendicular to the plane in $\mathbb{R}^2$ would either "into" or "out of" the screen/paper.
Comment: my reason being some refer to them as being area elements while others say surface area elements.
Comment: I mean are you actually working in $\mathbb{R}^2$ or are you secretly using cylindrical coordinates or something?
Comment: I am not restricted to R2 only that polar co-ordinates are 2-dimensional. So i am assuming an area vector wouldn't exist in R2
Answer: Polar coordinates consist of three "directions":  $r,\varphi, z$ as opposed to spheric coordinates, which are two angles and one radius, $r,\varphi,\theta$.
So your Area vector is as you said perpendicular to the area, so you have $$d \vec{A}=d A \cdot \vec{e}_z=r\cdot dr \thinspace d\varphi\cdot \vec{e}_z$$
Comment: i didn't think of adding the 3rd dimension z for some reason as i wanted to stay in a 2-dimension real field but it is definitely the only logical answer.


"Keep me informed" module

Question: It is good practice when starting a new web project to begin with an alpha version. I like to add a "Keep me informed" e-mail field for the visitors. I may use the contact module and vary, but maybe there is such a module ?
I will need only field e-mail, a checkbox to accept conditions and a first confirmation mail.
Answer: The way I would do this is with a Notification module.  There is a page at Drupal.org that lists the notification modules that exist.  You may want to look at that page to find a module that suits you.
One particular module I would like to suggest (since I maintain it :-) is the one named Notify.

The notify module allows users to subscribe to periodic emails which include all new or revised content and/or comments of specific content types, much like the daily news letters sent by some websites.

You can set it up so that users become automatically subscribed to notifications when they register at the site.  You may notify about all new content or only specific content types.  I.e. you can create a special content type named "Site updates" and use that to post site updates about your alpha site. Then, all your subscribed users will receive an e-mail update update whenever you post new content of the type "Site updates".

"Keep me informed" module


MIDI-Keyboards with integrated audio?

Question: I'm looking for a MIDI keyboard with integrated audio interface so I can play without plugging in to the computer. There were few products like M-Audio ProKeys and M-Audio Keystation 49i but these products are discontinued.
Is there any reason why they were discontinued? Are there any other products available now?
Thanks :)
Comment: Do you want a keyboard that can act both as a MIDI input device and also synth on itself?  If so, you can use any digital piano, e. g. Yamaha P-105
Comment: @MischaArefiev The ProKeys does not have an audio interface, so what is meant is a synthesizer.
Comment: @CL. ProKeys Sono 61 and 88 does have built in audio (about 10 instruments), and I'm basically looking for a MIDI keyboard not a synthesizer.
Comment: @flopr: The Sono 61 and 88 actually have built in 128 General MIDI range of instruments plus 46 drum sounds. The 5 or 10 high quality instruments have dedicated buttons but you can access the others. The Sonos incorporate MIDI-keyboard, sound synthesis and a basic audio mixer (e.g. for guitar and mic). You only need external monitors. As in CLs answer, stage-piano is a useful term for this class of devices.
Comment: There's an enormous range of integrated keyboard synthesizers; what's your budget? What range of sounds do you need? Do you need sequencing capability on the keyboard itself?
Answer: Except at the "toy" end of the market, almost any synthesiser or electric piano you can buy today will have MIDI in and out.
Reading between the lines, I suppose the challenge you have is that you want a good keyboard, with budget sounds. That may be difficult to find.
I would recommend shopping around and basing your shortlist on the mechanical aspects of the instrument -- if you want it to feel like a piano, look at digital pianos; if you want it to feel like an organ, look at more "synthy" keyboards.
Then ensure that MIDI in and out is supported. Just for futureproofing, you should check:

that you can use the keyboard to control other sound modules.
that you can control the sound module from another MIDI source (like a sequencer)

It's an unusual keyboard that doesn't meet these requirements -- but you should check just in case.
... and finally, when you are trying out the instruments in the shop, use the sounds it makes as a deciding criterion.
Answer: Only M-Audio knows why they were discontinued.
(I'd guess that they were not able to keep updating their drivers, which were needed because they were using a non-standard protocol.)
There are many MIDI keyboards with integrated synthesizer; they are called stage pianos.
Comment: From what I recall, the special drivers were for low-latency. In situations where latency was not an issue, you can use standard USB-MIDI drivers.
Comment: In my world, there are many MIDI keyboards with integrated synthesizer; they're called synthesizers or keyboard synthesizers.
Comment: @RedGrittyBrick The protocol itself has exactly the same latency as that defined in the USB audio specification. Early Windows drivers were inefficient; the M-Audio protocol is deliberately incompatible to prevent the Windows driver from being used, and it's not possible to use the standard driver with those M-Audio devices. Later M-Audio devices are using the standard protocol. (Roland built some devices where you could choose between standard and custom drivers.)
Answer: The reason he may need this is that with built-in audio interface you can hook up your laptop with your controller keyboard via USB and play vst-s or au-s live without having to use the tiny mini plug output on your laptop to get your sound into the stage box. A guess, but this is what I would do.

MIDI-Keyboards with integrated audio?


What is the alternative to drupal_realpath()?

Question: I use drupal_realpath() to do includes for some code samples I have:
 require_once(drupal_realpath('public://php_includes/functions.php'));

This gives the real path C:\www\sites\mysite\files\php_includes\functions.php.
What is the command to get the HTTP path http://mysite.com/sites/files/php_includes/functions.php?
The api documentation says "RealPath is deprecated"... if it's deprecated, what is supposed to replace it to get the same path (either C:\... or http://...)?
Answer: To get the HTTP path of a file, you need to use file_create_url($uri).
file_create_url('public://php_includes/functions.php');

This will output http://mysite.com/sites/files/php_includes/functions.php.
Regarding the fact that drupal_realpath() is deprecated, I think it's to warn developers to avoid relying on file system path and instead use wrappers.
Comment: Does it works well with S3FS module?


Create EB env with limited IAM Role User

Question: I'm trying to create a limited access IAM user that will be only allowed to manage an environment under a specific EB application.
Meaning, under EB app named X the user will be able to create/delete/modify any environment that exists.
This fails. The IAM user can log in, create the environment, but at the setup stage I get the following error (The picture is from the environment dashboard logs) -

Currently the IAM Policy for the users looks like this -
<code>{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "iam:GetRole",
                "iam:PassRole",
                "iam:ListAttachedRolePolicies",
                "ec2:*",
                "cloudformation:*",
                "elasticbeanstalk:CheckDNSAvailability",
                "iam:ListRolePolicies",
                "autoscaling:*",
                "iam:GetRolePolicy",
                "elasticbeanstalk:ListPlatformVersions"
            ],
            "Resource": "*"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::elasticbeanstalk-*/*"
        },
        {
            "Sid": "VisualEditor2",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObjectAcl",
                "s3:PutBucketPolicy",
                "s3:CreateBucket",
                "s3:ListBucket",
                "s3:DeleteObject",
                "s3:GetBucketPolicy",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::elasticbeanstalk-[aws-area]-[root-user-id]",
                "arn:aws:s3:::elasticbeanstalk-[aws-area]-[root-user-id]/*"
            ]
        },
        {
            "Sid": "VisualEditor3",
            "Effect": "Allow",
            "Action": "elasticbeanstalk:*",
            "Resource": [
                "arn:aws:elasticbeanstalk:*:*:configurationtemplate/[app-name]/*",
                "arn:aws:elasticbeanstalk:[aws-area]:[root-user-id]:environment/[app-name]/*",
                "arn:aws:elasticbeanstalk:[aws-area]:[root-user-id]:applicationversion/[app-name]/*",
                "arn:aws:elasticbeanstalk:[aws-area]:[root-user-id]:application/[app-name]",
                "arn:aws:elasticbeanstalk:*::solutionstack/*"
            ]
        }
    ]
}
</code>
Is there a way around this? How can I associate a profile? It seems like some permission is missing and AWS can't attach an instance profile or something
Answer: Here's the policy I've came up with after not being able to work with the posted policy. I'm sure that this could be tweaked more in order to make it more precise and etc.
The specific policy below will allow a user to interact with a single EB application. Do note that EB requires complete access for some AWS services like EC2, S3, Cloudformation and etc.
As said on Amazon's docs -

While you can restrict how a user interacts with Elastic Beanstalk
  APIs, there is not currently an effective way to prevent users who
  have permission to create the necessary underlying resources from
  creating other resources in Amazon EC2 and other services.

The Policy -
<code>{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "CreateEnvironment",
      "Effect": "Allow",
      "Action": "elasticbeanstalk:CreateEnvironment",
      "Resource": [
        "arn:aws:elasticbeanstalk:[zone]:[user-id]:environment/[eb-app-name]/*",
        "arn:aws:elasticbeanstalk:[zone]:[user-id]:application/[eb-app-name]/*"
      ]
    },
    {
      "Sid": "GlobalUnspecificResources",
      "Effect": "Allow",
      "Action": [
        "sns:*",
        "iam:List*",
        "s3:*",
        "cloudwatch:*",
        "ecs:*",
        "ec2:*",
        "cloudformation:*",
        "sqs:*",
        "autoscaling:*",
        "elasticloadbalancing:*",
        "elasticbeanstalk:DescribePlatformVersion",
        "elasticbeanstalk:DescribeConfigurationSettings",
        "elasticbeanstalk:CheckDNSAvailability",
        "elasticbeanstalk:ListAvailableSolutionStacks",
        "elasticbeanstalk:ListPlatformVersions",
        "elasticbeanstalk:DescribeConfigurationOptions",
      ],
      "Resource": "*"
    },
    {
        "Sid": "IAMActions",
        "Effect": "Allow",
        "Action": [
            "iam:CreateInstanceProfile",
            "iam:Get*",
            "iam:PassRole",
            "iam:CreateRole",
            "iam:AddRoleToInstanceProfile"
        ],
        "Resource": [
          "*"
        ]
      },
    {
      "Sid": "VisualEditor2",
      "Effect": "Allow",
      "Action": [
        "elasticbeanstalk:ComposeEnvironments",
        "elasticbeanstalk:AbortEnvironmentUpdate",
        "elasticbeanstalk:TerminateEnvironment",
        "elasticbeanstalk:DescribeEnvironmentManagedActionHistory",
        "elasticbeanstalk:ValidateConfigurationSettings",
        "elasticbeanstalk:DescribeEnvironmentResources",
        "elasticbeanstalk:RequestEnvironmentInfo",
        "elasticbeanstalk:RebuildEnvironment",
        "elasticbeanstalk:UpdateApplicationVersion",
        "elasticbeanstalk:DescribeEnvironments",
        "elasticbeanstalk:DescribeInstancesHealth",
        "elasticbeanstalk:DescribeApplicationVersions",
        "elasticbeanstalk:DescribeEnvironmentHealth",
        "elasticbeanstalk:DescribeApplications",
        "elasticbeanstalk:DeleteConfigurationTemplate",
        "elasticbeanstalk:RestartAppServer",
        "elasticbeanstalk:CreateConfigurationTemplate",
        "elasticbeanstalk:UpdateConfigurationTemplate",
        "elasticbeanstalk:UpdateApplication",
        "elasticbeanstalk:DescribeEnvironmentManagedActions",
        "elasticbeanstalk:DescribeConfigurationOptions",
        "elasticbeanstalk:ApplyEnvironmentManagedAction",
        "elasticbeanstalk:DescribeEvents",
        "elasticbeanstalk:CreateEnvironment",
        "elasticbeanstalk:DeleteEnvironmentConfiguration",
        "elasticbeanstalk:UpdateEnvironment",
        "elasticbeanstalk:RetrieveEnvironmentInfo"
      ],
      "Resource": [
        "arn:aws:elasticbeanstalk:[zone]:[user-id]:application/[eb-app-name]",
        "arn:aws:elasticbeanstalk:[zone]:[user-id]:application/[eb-app-name]/*",
        "arn:aws:elasticbeanstalk:*:*:environment/*/*",
        "arn:aws:elasticbeanstalk:*:*:applicationversion/*/*",
        "arn:aws:elasticbeanstalk:*:*:configurationtemplate/*/*"
      ]
    }
  ]
}
</code>
Replace zone with the zone you work with, user id with the main account user id and etc.
Resources used:

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.iam.managed-policies.html
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.iam.policies.actions.html
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.iam.policies.arn.html
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts-roles-user.html
https://gist.github.com/magnetikonline/5034bdbb049181a96ac9


How to determine the 'significance' of a new observation based on previous observations

Question: Problem: I have carried out a series of biological experiments where the output of the experiment is a N x N matrix of counts. I then created a custom distance metric that takes in two rows of counts and calculates the 'difference' between them (I will call this difference metric D). I calculated D for all pairwise comparisons and now have an array of difference metrics D called D_array.
My assumption based on biology is that the majority of D in D_array represent that there is no significant difference between the two rows of counts and only the >= 95% interval of D metrics actually represent real differences between two rows of counts. Let us assume that this is true, even if it doesn't make sense.
So this means if D_array = [0, 1, 2, 3, 4 ... 99] (100 metrics) then only a D score of 95-99 are actually representative of a real difference between two rows of counts.
Note: D_array is not representative of my data. My actual data actually has a distribution of values like this (black line represents the mean): https://i.stack.imgur.com/XFFY4.jpg
Given D_array I want to be able to determine whether a newly calculated distance value D' is "significant" based on my previous data: the distribution of my D_array. Ideally, I would like to provide some sort of metric of 'significance' such as a p-value. By significance I mean the probability / significance of having gotten a result as extreme as D'.
After a bit of reading, I found that I can use bootstrapping to calculate a 95% confidence interval for D_array, and then essentially ask if D' is outside of the 95% CI range. However, I am unsure if there is a way to determine how significant having obtained a value of D' is based on D_array.
My questions are:

Does asking if D' is outside of the 95% CI of bootstrapped D_array in order to determine whether D' represents a 'real' difference between two rows of counts make sense?

Given D' and D_array how can I determine the significance of having gotten a value as extreme as D' as a result. I have seen bootstrapping used to calculate P-values, but this usually requires the mean of two different distributions which I do not have in this case.

Is there a better way to determine whether a new observation is 'significantly' different from my prior distribution of 'null' (D_array) data. If so, how?
Comment: Is the newly calculated D using any row from original NxN matrix?
Comment: @Dayne No the newly calculated D is calculated from the output of a completely different biological experiment so it does not use any row from the original N x N matrix
Answer:
Given D_array I want to be able to determine whether a newly calculated distance value D' is "significant" based on my previous data: the distribution of my D_array. Ideally, I would like to provide some sort of metric of 'significance' such as a p-value. By significance I mean the probability / significance of having gotten a result as extreme as D'.

To what might be a good enough approximation, you already have what you need. You display an empirical distribution of D values. If you think that an observation in the top 5% of that distribution is "significant," you could simply use the 95th percentile of the empirical cumulative distribution function as your cutoff.

I found that I can use bootstrapping to calculate a 95% confidence interval for D_array, and then essentially ask if D' is outside of the 95% CI range.

Bootstrapping can be a useful way to get the sampling distribution of a statistic calculated from a data sample. Bootstrapping doesn't really give you a 95% confidence interval (CI) for the entire D_array. As you do bootstrap sampling with replacement, the average distribution among the bootstrap samples should be the same as the original D_array. You get the confidence interval for a statistic by doing multiple bootstrap samples, calculating the statistic on each of them, and examining the distribution of the statistic among the bootstrap samples. This answer discusses relative advantages of different ways to do that.
Perhaps you are interested in a 95% confidence interval for the 95th percentile of the population distribution from which you sampled your D_array. Bootstrapping probably won't help much with that. Quoting from that answer:

The first, general, issue is how well the empirical distribution $\hat F$ represents the population distribution $F$. If it doesn't, then no bootstrapping method will be reliable. In particular, bootstrapping to determine anything close to extreme values of a distribution can be unreliable. This issue is discussed elsewhere on this site, for example here and here. The few, discrete, values available in the tails of $\hat F$ for any particular sample might not represent the tails of a continuous $F$ very well.

One way to proceed would be to base your analysis on an model of the distribution of your D_array. Your data look like they might be from a log-normal distribution, which sometimes works well for calculations based on count data. If a log-normal distribution is appropriate, you might be better off fitting such a distribution to your data and basing your cutoff on the upper 5% tail of the fitted distribution.
Finally, I fear that you are putting too much emphasis on "statistical significance" rather than practical significance. What is significant for your application? How will you be using the cases that you identify as "significant" versus "non-significant"? Are you more interested in avoiding false-positive or false-negative findings?* For example, using a cutoff based on the upper 95% CI of the 95th percentile of the distribution would tend to put that tradeoff far toward the side of avoiding false positives. Is that what you really want? Those questions must be answered based on understanding of the subject matter. Once you answer those fundamental questions, statistical analysis can point the way to meeting your objectives reliably.

*Large-scale biological studies like RNA-seq typically control the false-discovery rate rather than the false-positive (Type I error) rate.
Comment: This was incredibly helpful in orienting me in a useful direction. Thank you!


How to get coloured file listing in windows cmd shell?

Question: A few older ones in here will probably remember a cute little proggie from DOS days, hdir it was called. Did nothing special, except show the file and directory listing in colour.
(there were others that did the same thing, but I used this one, so remember its name).
Are there any such today which work under XP (long file names ?) ?
I know ls has a --color option, but the one I'm using from unixkit-tiny has some problems working under my shell, it just displays rubbish, i.e. I haven't been able to get it to work.
Example of rubbish:
←[0m←[01;34mafter←[0m  ←[01;34mcolors←[0m  ←[0mdiff.vim←[0m  ←[01;34mdoc←[0m    ←[01;34mftplugin←[0m  ←[01;34mplugin←
[0m  ←[0mprogram.f90←[0m
←[m"

Not sure whether this should've been posted here or on SO. Not sure who it concerns more.
Answer: That rubbish is ANSI escape codes.  I believe you can still load ansi.sys for the command.com shell.
Comment: +1 for rubbish recognition. Although the process in the link works, command.com under XP doesn't seem to supoort long file names, and ls doesn't seem to work under command.com at all. If I try to reproduce the abovementioned process for cmd.exe, the "Programs" tab doesn't show.

Although the process in the link works, the ls doesn't work under command.com, and even if it did, it doesn't look like command.com has the support for long file names.
Comment: (don't mind that last part, it's late and I'm repeating myself)
Comment: +A for rubbish recognition, which later described why this is not possible anymore under cmd.
Comment: yah, you don't want to use the 16-bit command.com a 32bit/64bit operating system. it runs like a pig, and is severely limited. it's just there for compatibility.
Answer: You may want to check out NDIR.
Comment: Excellent ! Works like a charm under XP.
Answer: The way I do this is to use Cygwin's ls.  It's more heavy-weight than you're talking about, but there are other benefits, such as the availability of the UNIX find utility.
Comment: I prefer windows native versions of unix tools. Regarding the find utility, windows has one of their own.
Comment: The Windows native "find.exe" command is very different from the UNIX find command.  There is no comparison, unless you're talking about a 3rd party native Windows find program.
Comment: @Eddie - I'm sorry. Yes, that came out wrong. What I ment is, Windows has "find" of their own, but I prefer "find" in native version, ie unxutils version.
Comment: @Idigas: Ah, I've not used the unixutils myself, so I didn't think of that.  Good point.
Answer: I stopped using cmd.exe a long time ago and switched to 4NT (recently renamed to TCC - Take Command Console) - back when I switched command.com didn't have command completion, etc.
Has good color support, arithmetic in scripts, etc. Recommended.
Answer: A long time ago I used HDIR.COM and was motivated to write my own version in Turbo Pascal, which I called CDIR (ColorDIR).   I lost my source code to it in a hard drive crash around 1995, but a few years ago I found an old 3.5" floppy disk that contained one of my last builds of it as an EXE.  It has a few more features (pause between long list and scales large sized files into an easier to read unit).   No ANSI was involved, DOS had interrupts to adjust colors.
A friend of mine did a similar project and went one step further: he had command line options that would self-modify the program EXE itself.  This way, you could configure what colors you wanted for which extension types -- and didn't have to carry around an external CFG file (like show DOC as WHITE or BAT as RED).  Your settings would get patched directly into the EXE (I don't think you could add new supported extension types - it just knew what offset to patch).  In those days, there was essentially no line between code and data :D
To anyone interested, I have my CDIR.EXE (and other assorted MS-DOS 16-bit real mode tools) archived here:
https://github.com/voidstar78/VUC4DOS


Statistical analysis on confidence intervals

Question: I have a data set where the data, when plotted, is not normal. Log-transforming the data makes it normal. Should confidence intervals for the population mean and hypotheses testing about the population mean, be conducted using the data on the original or on the log-transformed scale?
Answer: Where there are data, there usually is a research question. Let's say you have data on healthcare costs in the past month for a random sample of 100 migraine patients. Your research question is: What is the true average healthcare cost for all migraine patients represented by the random sample of 100 patients?
When you plot the healthcare costs data for the 100 sample patients via a histogram, you notice they have a right-skewed distribution. However, when you plot the log-transformed healthcare costs, you notice they have an approximately normal distribution.  Thus, you decide to use the log-transformed data to estimate the true average healthcare cost.  Note that transforming/changing the data did NOT change your research question. The research question should NOT be altered after seeing the data. The reason we collected the data in the first place was to answer the original research question.
As whuber pointed out, when you analyze the log-transformed data, you end up estimating the true average value of the log-transformed healthcare costs. How do you go from this quantity to the true average value of the (untransformed) healthcare costs?
One way to deal with this is to proceed as follows:

Draw a large number B of bootstrap samples (with replacement) of size n = 100 from the original sample;
For each bootstrap sample, fit an intercept-only simple linear regression model of the form:
log(healthcare cost) = beta0 + error
and use the fitted model to obtain an estimate b0 of beta0 and an estimate s of the standard deviation sigma of the model errors.
For each bootstrap sample, compute the quantity exp(b0 + 0.5s^2), where s^2 represents the squared value of s. This quantity estimates the true average healthcare costs with the help of a so-called smearing factor. See, for instance, https://www.annualreviews.org/doi/pdf/10.1146/annurev.publhealth.28.082206.094100.
Use the appropriate quantiles of the bootstrap distribution of exp(b0 + 0.5s^2) to construct the desired 95% confidence interval for the true average healthcare cost.
Comment: Just to clarify: This is Duan's smearing estimator right? (+1 obviously)
Comment: Yes, that's what it is!


Finding a basis for unification of two subsets

Question: I have this problem :
$U,W \subseteq R^4$
Base of $W = \{w1 = (1,2,2,-2), w2 = (0,1,2,-1)\}$
Base of $U = \{u1 = (1,1,0,-1),u2 = (0,1,3,1)\}$
Find a basis for $U \cap W$.
My solution
for any $v \in U \cap W$, $v \in W$ and $v \in U$
I need to find $\lambda_1...\lambda_4$ that appiles:
$\lambda_1u1+\lambda_2u2=\lambda_3w1+\lambda_4w2$
Hence (put the vectors as colums),
$\left[\begin{array}{cccc}
1 & 0 & -1 & 0       \\
2 & 1 & -1 & -1       \\
2 & 2 & 0 & -3       \\
-2 & -1 & 1 & -1
\end{array}\right]$
After elementary operations:
EDIT:
$\left[\begin{array}{cccc}
1 & 0 & -1 & 0       \\
0 & 1 & 1 & 0       \\
0 & 0 & 0 & 1      \\
0 & 0 & 0 & 0
\end{array}\right]$
Therefore :
$\lambda_1=\lambda_3$
$\lambda_2=-\lambda_3$
$\lambda_3=arbitrary$
$\lambda_4=0$
Therefore basis of $U \cap W=Sp\{(1,-1,1,0)\}$
For some reason I don't get the same results as the book.
Any help will be appreciated, thanks.
Answer: Check first
that the answer you have got is the scalar multiple of your answer not.. If it is not then your answer is wrong because your elementary row operation it is clear that $dim(U \cap W)=1$[ if you haven't done any calculation mistake!!]
Another simple method you can do, just take that matrix & do elementary column operation [don't interchange any column just]. The columns you will get non vanishing atlast. Put the corresponding original basis as the basis of $V \cup W$ [explain why??]. You know basis of $U$ & $W$. rest is upto you.
Comment: You'r right, I calculated it wrong, thanks:)
Comment: I re-calculated but the solution is still not like the one shown in the book, can you please take a look?


How should I tune a 12 string acoustic guitar?

Question: I've bought an Ibanez 12 string acoustic brand new online.
Do I tune the 12 string guitar like all the 6 string guitars I have.
Comment: @Tim they're quite often detuned (much lower than playing tension) for delivery, especially if there's air transit involved. Extreme changes in atmospheric pressure and temperature can cause the strings to tighten, potentially warping the neck, or strings to break and maybe taking some of the veneer with it. Not what you want with a new guitar.
Comment: Did it not come already strung?
Answer: Twelve string guitars have basic tuning the same as a 6 string (EADGBE) but the pairs are arranged a little differently:
For the thickest 4 pairs (EADG) the thinner string of each pair should be an octave higher than the thicker string
For the thinnest two pairs (BE) each string of the pair should be tuned in unison.
There is a handy tuner online at get-tuned.com - and they describe the tuning as:

eE aA dD gG BB EE

where lowercase is an octave higher than its counterpart.
Comment: Perfect explanation.  Clear and concise!
Comment: Just to add, in practical terms, when tuning each pair,  either by hear or with an electronic tuner, be careful, when tuning one string of the pair, not letting  the other string vibrate. It may vibrate by simpathy, even if not mechanically poked, and make the tuning more difficult. An easy way to avoid this is using a pick, strike the string that's being tuned immediately resting the pick on the other string, thus stopping any vibration from this second string.
Comment: Actually, I use the resonation to make it easier to tune in unison
Answer: I agree The 12 string Must be tuned 2 notes lower, i have proved the strain on my 12 strings when toned to concert E. The sound is also improved as is the action. using heavy strings and tuning down also does not help the guitar as the tension is too high resulting in eventual neck bend and high action as well as bridge lift. on gibson B 45 s with tailpiece and floating bridge it can cause the top of the guitar to warp inwards.its worth tuning down and transposing.
Comment: This is just incorrect Jonathan. If you have a 12 string designed for D then sure, tune it in D, but the majority are designed for standard tuning
Answer: 12 string tuning should be D G C F A D or you'll eventually split the top and also make the instrument difficult to play. Try it. Relieve the tension, save your guitar from over tuning. Make it sound better. Don't reply until you try
Comment: You will not "split the top" if you use standard tuning.


É necessário usar as tags ul e li no flexslider?

Question: Estou querendo saber se tem como trocar as ul e li por div ? Pq eu acho mais complicado mexer com ul e li do que com divs !!
Comment: É so trocar o [selector dele](http://www.woothemes.com/flexslider/): `selector: ".slides > li", `.
Comment: Esta ainda dificil de entender, a tag ul no css seria `ul {}` e no div `div {}`, no li seria `ul > li {}` e no div `div > div {}`, so muda os nomes. Seu problema parece coisa, isto nao tem nada haver com o ordenamento que voce citou anteriormente, a ordem nao e influenciada por divs ou lis ou uls. Poderia ser mais claro?
Comment: Desculpe a pergunta, mas o que tem de dificil em usar ``? Pense no  como o div pai e nos ``s como divs filhas. Poderia explicar a dificuldade? Acredito que nao tem como trocar.
Comment: é que não consigo colocar a ordem no css !!ex: slide li{} ou slide ul{} ou quando usar slide ul li{}
Comment: não entendi ? bruno.
Comment: @BrunoWego Faz sentido, formule uma resposta, com um exemplo um pouco mais completo. Otima dica (apesar de nao ter testado ainda).
Comment: @GilmarSantos que ordem? Poderia explicar **editando** a pergunta? Nao entendo o que mudar pra div ira melhorar no uso da ordem.
Comment: é que não consigo mexer com a tag ul e li. no html eu sei mexer, mas, no css não consigo.
Comment: vlw vou estudar mais sobre as tags li e ul !! ainda sou muito leigo em linguagens web !!
Answer: Segundo a documentação do flexslider, basta alterar o parâmetro selector:

Isso se torna possível pois o flexslider utiliza classes em seus elementos filhos e não a seleção pelo elemento li.
Comment: a entendi é so eu mudar esse selector: ".slides > li" para selector: ".slides > div"


Timeout problem in PopupNotification JavaScript XUL

Question: This code working for me to display the door-hanger popup. But, when I want to use the time-out under the options it wont show up the pop-up notification.
Syntax:
Notification show(browser,id,message,anchorID,mainAction,secondaryActions,options);

My code:
PopupNotifications.show(gBrowser.selectedBrowser, "PDE-popup",
"Hi, there!, You can Build a PaDE by clicking on the PDE button!!",
null, /* anchor ID */
{
  label: "Build PDE",
  accessKey: "D",

  callback: function() {
                if(nodeSRC!=null) pde.emptyNodeSRC(nodeSRC);

     window.openDialog("chrome://PDE/content/PDEBuilder.xul", "hello", "chrome,width=400,height=360",userContent, nodeSRC);

  }
},null, { timeout: Date.now() + 10000,
                            persistWhileVisible: false });

1.What's wrong with this code?
2. How can I place this door hanger popup to be displayed on my tool bar button?
This is the tool bar button
    <toolbarbutton id="pde-toolbar-button" label="Detect"/>

I want to disappear the pop-up notification in 10Seconds! Thank u guys.
I have no secondary options so, I made it null but the time-out is not functioning.
http://scenari-platform.org/svn/dev-core/trunk/Lib_XulRunner/Darwin/modules/PopupNotifications.jsm
https://developer.mozilla.org/en/JavaScript_code_modules/PopupNotifications.jsm#Notification_events
Answer: Components.utils.import('resource://app/modules/PopupNotifications.jsm');
var notify  = new PopupNotifications(gBrowser,
                                       document.getElementById("notification-popup"),
                                       document.getElementById("notification-popup-box"));

var notification =  notify.show(
gBrowser.selectedBrowser,  /*browser*/
"PDES-popup", /*id*/
"Hi, there!, You can Build a PDE by clicking on the PDE button!!",/*message*/
null, /* anchor ID */
/* mainAction */
{
          label: "Build PDE",
          accessKey: "D",

          callback: function() {
                      if(nodeSRC!=null) pde.emptyNodeSRC(nodeSRC);

              window.openDialog("chrome://PDE/content/PDESBuilder.xul", "hello", "chrome,width=400,height=360",userContent, nodeSRC);

          }
        },
null, /* secondaryActions*/

{ blablal:'options'}

);

setTimeout(function(){
notification.remove();
}, 900);

The above code works fine, finally got a clear explanation from other forum for my problem.


Is Undersampling or oversampling for unbalanced classification data?

Question: I am trying to train a Random Forest classifier on a binary classification problem but with a highly imbalanced dataset where the positive class is much smaller than the negative class . I have undersampled my dataset so that both classes have equal proportions and did 10 fold cross validation over this dataset.
However I am having bad results (averaged over the 10 folds):

recall : 46%
precision : 54%
accuracy : 53%

I was wondering if oversampling the positive class would yield better results. What would be the benefits of undersamling versus oversampling?
Comment: Did you have a look at the confusion matrix of your model's predictions?
Comment: How many training samples do you have after undersampling?
Answer: Undersampling at the data-collection phase can make sense, as you might be able to do more efficient data-collection. This is the topic of that King and Zeng paper discussed in the link.
However, once you have the data, unless you have computational constraints (cannot fit a huge dataset into memory, modeling is too slow even if you can, etc), undersampling makes no sense to me. I have my qualms with oversampling, too, but undersampling discards precious data. Since it turns out that class imbalance is rarely a problem for proper statistical methods, with those rare exceptions being outside the usual sense in many machine learning circles about why imbalance is a problem, discarding precious data to fix a non-problem seems like the worst idea of all.
Regarding oversampling, there probably is no need to do this. Proper statistical methods handle class imbalance just fine in most cases. However, at least you aren't wasting data solving a non-problem when you oversample.


SCCM 2007 PXE boot stuck at contacting server

Question: We have an sccm 2007 server on windows 2008 r2 sp1. It has been handling pxe boot until yesterday. Clients get DHCP and is reffered to the correct server, but is gets stuck on contacting server.....
Server has been rebooted. Twice. WDS service is running. Tried deleting the computer accounts, alas it makes no difference.
Not able to find anything interesting in pxecontrol log. What could be the cause or where can i look further to debug this?
Answer: smspxe.log shows the clients as accepted and keeps repeating the same statement that the client is accepted, however the client will not boot.
Check to see if both the 32 and 64 bit boot images exist in SCCM. Even when only using the 32 bit boot image, SCCM requires the 64 bit image. Add the 64 bit image and distribute it to the DP's and yo can boot clients again.
Answer: Did the networking team, or server team member, change any firewalls?  Are the correct UDP ports still open to support PXE?
Answer: In our environment on the dell laptop the boot order has to be in the correct order for the pxe boot to working correctly. The hard drive has to be the first one on the list.
I would look at the desktop first and verify it is working correctly.


Is using DATE in SELECT query on a DATETIME indexed column in mysql correct with respect to optimization?

Question: I have a very huge table (425+ million rows).
CREATE TABLE `DummyTab` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(48) NOT NULL,
  `BeginDate` datetime DEFAULT NULL,
  `EndDate` datetime NOT NULL,
  ......
  ......
  KEY `BeginDate_index` (`dBegDate`),
  KEY `id` (`id`),
) ENGINE=MyISAM

Selects are done based on "BeginDate" and other criteria on this table
select * from DummyTab where Name like "%dummyname%" and BeginDate>= 20141101

Now in this case only the date field is being provided out of datetime (although it'll be used as 2014-11-01 00:00:00).
Question is DOES THE OPTIMIZER MAKE USE OF DATETIME INDEX PROPERLY EVEN WHEN JUST DATE IS PROVIDED IN THIS CASE ? or should the index be set on a "date" field to be used more effectively rather than a "datetime"
Answer: Yes, BeginDate_index can still be used when the query is specified with a DATE-only filter (also applying additional criteria on Name won't disqualify the index either).
If you look at this SqlFiddle of random data, and expand the Execution plan at the bottom, you'll see something like:
ID   SELECT_TYPE  TABLE  TYPE     POSSIBLE_KEYS    KEY             KEY_LEN   REF    ROWS   FILTERED                EXTRA
1    SIMPLE       DummyTab range  BeginDate_index  BeginDate_index 6         17190  100    Using index condition;  Using where

(Specifically KEY is BeginDate_index).
Note however that use of the index is not guaranteed, e.g. if you execute the same query against a wider range of date criteria, that a different plan may be used (e.g. if you run the same fiddle for > 20140101,  the BeginDate_index is no longer used, since it does not offer sufficient selectivity).
Edit, Re: Comment on Exactness
Since BeginDate is a datetime, the literal 20141101 will be also be converted to a Datetime (once). From the docs:

If one of the arguments is a TIMESTAMP or DATETIME column and the other argument is a constant, the constant is converted to a timestamp before the comparison is performed.

So again, yes, as per your last paragraph, the literal in the filter BeginDate >= 20141101 will be converted to the exact date time 20141101000000 (2014-11-01 00:00:00) and any eligible indexes will be considered (but again, never guaranteed).
A common issue where indexes cannot be used is because the filter predicates are NOT sargable is when a function is applied to a column in a filter, as the engine would need to evaluate the function on all remaining rows in the query. Some examples here.
So altering your example a bit, the below queries do the same thing, but the second one is much slower. This query is sargable:
SELECT * FROM DummyTab
WHERE BeginDate < 20140101;  -- Good

Whereas this is NOT:
SELECT * FROM DummyTab
WHERE YEAR(BeginDate) < 2014; -- Bad

Updated SqlFiddle here - again, look at the Execution Plans at the bottom to see the difference.
Comment: so is the index calculated for DATETIME = 20141101 same/similar as DATETIME - 20141101 12:12:59, or mysql figures it out that this is a close one ? Is the exactness of the 'time' from given DATETIME immaterial when using indexes?


IE11 ignoring cookie 'delete'

Question: I'm trying to delete a cookie, as detailed here
It works fine in Chrome, FF, but in IE11 it has no affect -i.e. subsequent requests to this domain send the vp_token cookie with the value that existed prior to this response.
Question: why does this response fail to 'delete' the vp_token cookie?
Note that it's a 302 response.
Comment: Have you tried setting the cookie expiration date further back in time than only 24 hours?
Comment: Also does the 302 redirect to a different domain?
Comment: The 302 is to the same domain. I'll try setting it back more than 24 hours, but seems like a weird possibility
Comment: I tried 10 days, made no difference.
Comment: Would you be able to provide more information on the request you are making? Instead of using IE dev tools, use [Fiddler](http://www.telerik.com/fiddler) to capture request. It would be good to see the original request with all headers, the 302 response as above, and the subsequent requests/responses that show that the cookie is still there.
Comment: I have also noticed that you're using an older version of IE 11. Microsoft [changed the developer tools back in Dec 14](http://blogs.msdn.com/b/ie/archive/2014/12/09/announcing-the-redesigned-f12-developer-tools-interface.aspx).  If it's possible for you to update, it would be interesting to see if the issue still occurs.
Answer: The server in this case was a testing environment, for which I have a self-signed SSL cert. The problem is not reproducible on our production environment, which uses a Digicert SSL cert.
So I'm going to tentatively conclude that this is a bug in IE related to self-signed SSL certs. Happy to change that assumption if anyone can shed more light on it!
Comment: That is interesting. Have you tried adding the self-signed SSL cert to your local certificate store so that it is trusted and then see if the bug still occurs?
Comment: Actually, it's already in the Windows certificate store, so I dont get any SSL errors. I should have mentioned the before.. It says, amongst other things "The connection to this server is encrypted"

IE11 ignoring cookie 'delete'


What do non-chord tones do in a melody?

Question: In the book that I am reading, I came across this passage (picture below).
But the author just tells the reader to 'consider the difference', and passes on to the next subject without explaining much.
So what do non-chord tones do exactly here?
Like unstable tones, do they drive the listener farther away from a home feeling, providing a momentum?
Comment: If the book doesn't explain, your best course of action may be to choose a different book.
Comment: It would be helpful to know what is the book, is it a theory book or practical tutorial and is it focused on classical music or not really
Comment: There's a whole different way to view this. A melody can be its own justification where every note is equal. When a harmony is added, the harmony doesn't have to change with every melody note. That means some melody notes are heard over harmonies that are not closely suited to those melody notes. The point being that in cases where the melody comes first, "non-chord" tones have the exact same purpose as all other melody notes: to create a compelling melody. The fact that the harmony isn't changing with each melody note is a harmonic, not melodic, decision.
Comment: Why is there a vote to close? This is a good question.
Comment: @Peter_Mortensen If you're using a tool to edit posts then you need to review these results manually. Your edit has made several improvements, but it's also made a couple of bad changes.
Comment: If you harmonize the E note with a C chord, does the E become a chord tone? How about Fmaj7?
Comment: Incidentally, Randy Newman keeps it even simpler: https://youtu.be/aJbmVCgpJGA
Comment: I think it's the _implication_ behind the question that needs discussing — that non-chord tones need some sort of justification, that they're somehow less valid or less desirable than chord tones.  (And therefore, as Todd Wilcox mentions, that the melody is subservient to the harmony.)  All of which are disputable!
Comment: @Peter_Mortensen in particular, it is generally incorrect to separate a restrictive relative clause from the noun phrase it restricts.  Many other languages require commas for that purpose, but English abandoned them (I learned just yesterday) a few hundred years ago.
Comment: @phoog I'll go ahead and disagree. If I'm reading something that's nominally trying to teach about an art form such as music, I would greatly prefer it to encourage me to *consume examples of the artwork* (in this case, *listen*) so that I can appreciate subjective qualities (whether or not I can express them in language), rather than being told the author's impression of everything. Theory can only go so far. No matter how much you know about acoustics, it doesn't tell you what the sound *is*.
Comment: @KarlKnechtel it seems to me that the author here is telling us of his impression that non-chord tones create interest.  Maybe he could make that point with more examples, but the excerpt we've been given is singularly unsatisfying.  Examples by themselves also can only go so far.
Comment: Hm, fair enough.
Comment: IDK about tones, but when you double the number of notes, it either sounds like it should, or you get asked to stop overplaying it. I can syncopate the notes given, or *go nuts*. Usually the request is, *just play it straight*. The difference is one of those is fun to play, and the other is fun to listen to. Reminds me of the measure that I'll pick to overplay just so everyone knows I could be doing that the whole time, but they're making me go *boom-pop* over and over again. The trick is getting into a grove for it to seem like *silence* is playing those notes when you're not.
Answer: I'll give a short, easy answer that fits into the spirit of the quote, and a longer one that challenges it.
The easy answer is that non-chord tones either "smooth things out," connecting melody notes to "fill in" intervallic gaps, OR "jazz things up," providing "interesting" dissonances which resolve into consonances. The book's example is in the latter category. The B in the first measure is not a member of a C chord, and clashes with any C pitch that's being played. But since the next note is a C, the dissonance resolves. We feel the dissonance all the more strongly since it was placed on a beat. The book is suggesting that a brief dose of aesthetic "unpleasantness" makes things more engaging or fun, as a bit of lemon juice or cayenne make food more interesting even though they mildly irritate our tissues.
For "smoothing things out," consider that without non-chord tones, we can only play arpeggios. A passage from Bach's C major solo violin sonata, with its implied chords, goes like this:

If we removed all non-chord tones—everything from the C measure that isn't either a C, E, or G, and everything from the G7 measure that isn't a G, B, D, or F, we'd be left with this:

This arpeggiated version feels "bumpy," instead of the fluid, "flowing" "smoothness" of the scalar version. Nothing wrong with this per se, though; sticking to arpeggiation of chordal tones works just fine for this other famous opening, working with the same "I V7," though in a different key:

Now, the longer version: In fairness, the book isn't trying to do a deep dive or make a very strong point. But it makes it seem as if tonality languished in chordal boredom until finally somebody invented non-chord tones, and that's not the historical case. We might appreciate non-chord tones by imagining life without them, but we had scalar movement in monophonic chant, long before we had any "chords" for any of the notes to be outside of. They're just a concept that evolved along with polyphony. Also, in the compositional process, not all non-chord tones are "garnishes," added in as afterthoughts to enliven dull melodies. This notion is more apt for some than others. I doubt that Bach started with the "bumpy," arpeggiated version, and thought "I'd like it smoother" and then filled in the gaps with passing tones. But some non-chord tones, like appoggiaturas, are regularly used as ornaments that the composer (or the performer!) can consciously add to a melody, to "make it more interesting," like maybe as it repeats for a second time.
Comment: +1 for this answer, especially the "longer version" (which is quite a bit shorter than the "short answer"....)
Comment: There's still an A note lurking in the 2nd example! But the F notes in  the G7 bar are fine. ( Not reflected in the text above).
Comment: @Tim Thanks, good catch
Comment: My pleasure - upvoted, too!
Comment: "Nothing wrong with this per se": indeed, but it's an entirely different experience.  So the trivial answer is that non-chord tones can turn one melody into a different (though perhaps similar) melody.  This still leaves room for an analysis of how and why.  @Tim wouldn't a jazz musician call it a G9 chord anyway on account of the A?  I think the most important point here, though, is in the second section: melody precedes harmony historically and in many compositional practices.  The idea that you start with a chord progression and fit a melody to it became prominent maybe 60 or 70 years ago.
Comment: @phoog - if you refer to the G7  chord - G13 would be an even more apposite chord!
Comment: I'm being picky here, but, "without non-chord tones we can only play arpeggios" if the melody is moving fast than the harmonic rhythm. If the two are going at the same pace, like in many hymns, or SATB styles, the lines can move by scale steps and leaps to all chord tones.
Answer: In this particular example both non-chord tones are leading notes that strongly push for resolution on the chord tone, so they provide a bit of tension before the resolution. The second note so E into F can be also interpreted as retardation as it is approached by the same note, happens on the strong beat and a chord change and resolves half step up.
There is this nice and logical classification of non chord notes scenarios based on how the note is approached and left.

Source: https://musictheory.pugetsound.edu/mt21c/NonChordTonesIntroduction.html
The first non chord note from the example is interesting though as it doesn't fall easily into any of these categories even though it is not anything unusual. Appoggiatura could be the closest but that might be controversial as there seem to be different contextual definitions of appoggiatura.
Answer: One other use of non chord tones has (fairly recently) come to be known as the "melodic-harmonic-divorce".
A good analysis can be found in this 2007 paper by David Temperley:
The melodic-harmonic 'divorce'
in rock (from the author's website)
A key point from the abstract of the article:

A good indicator of melodic-harmonic divorce is
cases where non-chord-tones in the melody do not resolve by step.

It tends to occur in blues, rock, and other blues-influenced music, and most often with a pentatonic melody.  It also tends to be used to contrast different passages (e.g. verse against chorus).
Comment: I saw "melodic harmonic divorce" and I immediately thought of James Taylor and Carly Simon.
Answer: They're passing notes. I like to see them as 'stepping stones', there to get from one probably more important note to another, filling the gap, if you like. Almost an embellishment, but not really. Adding an extra bit of colour, even though the passing notes may be diatonic (chromatic notes are the real colourful ones).
Answer: Yes, non-chord tones provide unstable dissonance to a melody which through movement to consonant chord tones provides forward momentum to music. Also, there is a general harmonic aesthetic which considers all chord tone music bland consonance and good harmony should provide a balance of consonance and dissonance. That idea is often explained with an analogy to spice in cooking. Non-chord tones would contribute to that as well. Those are two conceptions of dissonance, momentum and spice, which aren't exactly the same thing.
But there is something else very fundamental in music which has not already been addressed in other answers. Non-chord tones contribute to the rhythm of a line. Consider the second example, ex. 15.19b, if it were given with all chord tones...

If that line were performed without good performance articulation, it could have an effect like this...

One way to mitigate against that and get each tone clearly articulated could be with explicit breaks between repeated notes...

But another way to clearly articulate the different notes it to contrast them by pitch...

...which is one of the things the non-chord tones do in the example.
Another way to make the point about non-chord tones and their importance to rhythm is by comparing ex. 15.19a and 15.19b. The first one is almost all on the beat rhythms, but the second places the non-chord tones in accented, on the beat positions, which displaces the chord tones off the beat, and that creates the rhythmic effect of syncopation in the second example. The two lines are very similar in terms of pitch contour, but very different in terms of rhythm. I think you could make an strong case that the rhythmic change is much greater than the added dissonance.
Rhythm is very important in making a unique melody so the important rhythmic contribution non-chord tones make to a melody should not be overlooked.
Answer: The effect of non chord tones is explaned by their function as ornamentation and embellishment of the melody.
Comment: Hm, this seems little more than the book's "Just look and see what they do" approach. I think the OP was looking for more explanation.
Answer: Non-chord notes make the melody interesting. It gives it color, that is why it is called Chromaticisms, Chroma means color. It is like the painter with his palette of paint colors, the non-chordal notes are all ways in which the composer gives color to his/her music or in other words how it is made interesting. The moment you use non-chordal notes in a chord progression the passage starts to sound like music.
Comment: Non-chord tones are not necessarily chromatic, as seen in the example given by the OP.

What do non-chord tones do in a melody?


ThemeKey: Use main theme for Node/edit and user/edit

Question: By default, Drupal uses the "main theme" for the main site, and the "admin theme" for the admin pages.
I want to use my "main theme" for the user/edit pages and node/edit & node/add pages of the "journal" content type only.
For all other administration pages (including the node/edit & node/add pages of other content types) , I want to use the "admin theme".
How can I do this? In Theme Key there doesn't seem to be options to select node/edit & node add pages of a particular content type (or options to select user/edit pages).
Answer: you will need to create a hierarchical set up:

In this example set up, it checks for user:1 (admin), that the node type (content type) is article, and that the path meets the relevant criteria. You will need to adjust accordingly. Simply drag and drop the sub-elements into place.
Comment: thats a lot of questions... you may need to install Themekey Comptability Module and manually override the admin users themeìng - never had a reason to do it, so I don`t know the exact settings you will need, you need to play around with it. For user pages, it is the same process, only with the relevant url(s)
Comment: Do I disable the admin theme at admin/appearance?

If I do, then how do I get the admin theme (Seven) to apply to the admin pages (with the exception of journal and users)?

If I do not turn it off, then do I uncheck the box for "Use the administration theme when editing or creating content".

How do I get theme key to target the user pages? I have tried using wildcard path user/# but it doesn't seem to work.

Also, is `path_is_admin = True` used for the admin pages? It seems to target all admin sections including `user/edit` and `node/edit`, which doesn't have "admin" in the path.


The radius of convergence of a square-summability sequence

Question: Suppose $\sum_{n=0}^{\infty}|a_n|^2<\infty$.
How to prove that $\limsup_{n\rightarrow\infty}|a_n|^{\frac{1}{n}}\leq1$?
Comment: Please read [How to ask a good question](https://math.meta.stackexchange.com/q/9959/148510).  It is better to ask a question that provides context and evidence of your own work.
Answer: Hints:
$1).\ \limsup_{n\rightarrow\infty}|a_n|^{\frac{2}{n}}\le 1$ since otherwise the series doesn't converge.
$2).\ \limsup_{n\rightarrow\infty}|a_n|^{\frac{2}{n}}=\underset{k\to \infty}\lim\sup_{n\ge k}|a_n|^{\frac{2}{n}}.\ $ So if $k$ is large enough, $\sup_{n\ge k}|a_n|^{\frac{2}{n}}< 1+\epsilon.$
$3).\ |a_n|^{\frac{1}{n}}=\sqrt {|a_n|^{\frac{2}{n}}}.$
Answer: Hint: Suppose $\limsup |a_n|^{1/n}=r>1$. By definition of $\limsup$ (the supremum of the set of all subsequential limits), choose $\epsilon>0$ so that $r>r-\epsilon>1$. Then $r-\epsilon$ is not an upper bound for the set of subsequential limits so there exists a convergent subsequence with $r-\epsilon<|a_{n_k}|^{1/n_k}$ for all $k$ sufficiently large. What's the problem with this (square the inequality to use $|a_n|^2$? What do you know about the tail of convergent sequences?


The tonal function of a bar in minuet by krieger

Question: This is Minuet by J.Krieger

If I look at the 6-7-8 bars, there is the following chord progression:
E - E(7) - Am
With a trill in the 7th bar. I feel like the 6 bar does a kind of "teasing" in a tonal sense i.e from the dominant E you want to go straight to the tonic but the trill in the 7th prolongs the tension.
Is my analysis correct? and is there a name for this "structure"?
Comment: You are correct as to the chords inferred, assuming you want to count the last beat of the sixth measure and the first beat of the second measure merely as passing tones, but I regret that I don't know of a name for the prolonged dominant seventh trill here.
Comment: The tonic is A.
Answer: The analysis is correct.  This piece is in A minor.  The chord progression that you've spelled out (E-E7-Am or V-V7-I) is called a cadence.  If you wanted to put a name on the structure you've noted it would be a cadential extension.  Usually this term is applied to a longer delay in the return to the tonic (Am) chord but any place where the Dominant (V or E in this key) function chord is continued past the expected point of resolution could be considered a cadential extension.
You can find some more in depth information about the larger musical theoretical structures in Common Practice music in the book "A Practical Approach to Form in Music" by Peter Spencer.


Getting feature weights with permutation_test_score()

Question: I am using sklearn to fit a SVM to some data. Since I wanted to use cross-validation and evaluate my classification accuracy using permutations, I am using the permutation_test_score() function (https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.permutation_test_score.html#sklearn.model_selection.permutation_test_score)
I have implemented my SVM like this:
svc = SVC(kernel='linear', verbose=True)
nr_perm = 100
cv = StratifiedKFold(n_splits=5)
score, pscores, pvalue = permutation_test_score(svc, X, y, scoring="accuracy", cv=cv, n_permutations=nr_perm)

According to the documentation, this function fits and evaluates the model using cross-validation. However, even after using permutation_test_score I cannot use coef_ to get the weights of the features of my model. I get the following error message:
AttributeError: 'SVC' object has no attribute 'dual_coef_'

If I use svc.fit(X, y), I can then use svc.coef_ to access them:
svc = SVC(kernel='linear', verbose=True)
svc.fit(X,y)
coefs = svc.coef_

I have encountered the same problem when using other functions from sklearn.model_selection.
Does anyone know how I can access the feature weights?
Answer: When you call a model with model.fit(X,y), you can get its weights because they're fitted on a single dataset. However, in cross validation or permutation tests, the same model is fitted several times using portions (or modified versions) of the training data and several models are outputted. So, the weights you seek for is not unique, which explains the lack of weights for your call.
Comment: You can plot an image of trials x feature weights, i.e. $T\times F$. But, you need to get the weights for each run first by either writing a derived Model class for SVC, and save the weights (e.g. to files) after each fit operation or doing the permutation test yourself.
Comment: Yeah, that's what I was expecting. I have always used the feature weights for nice visualisation though, do you know of an alternative?


How to use Kullback–Leibler divergence to help me choose the best distribution function?

Question: I am now using Exponential distribution to model the the time intervals of a sequence of random events.Since I can choose several different lamdas for this model , I want to find out which lamda of them  is fitting the training data best. I find  Kullback–Leibler divergence from some paper is used to do this , but :

I don't know if this way is suitable
I don't know how to operate either

I am new to machine learning . Anyone can help me ?
Answer: it sounds like you just want to pick the lambda that fits the model best...as in estimate lambda (assuming the model is exponential). Using Kullback-Leibler you could assess the fit of the exponential distribution (with the appropriately estimated lambda) and compare it to say another distribution (e.g. gamma).
Of course if you are considering gamma you might as well just do this in the context of a hypothesis test because exponential is just a special case of gamma.


Two distinct dice, expected value

Question: We have two distinct dice. $X$ will be the number of pips showing on the top face of the die after the toss. $Y$ is the same for the second die.
What is the expected value $$Z_2 = greatest\; common\; divisor(X,Y) $$
Can anyone help me how to solve that please?
I just know the expected value of $X$, which is $3.5$ and $Y$ is also $3.5$ But I don't know what to do in case of the greatest common divisor.
Comment: There are only a few possible values of the greatest common divisor. Find all the ways each one can occur, and from that find the probability of each value. Then use the definition of expected value.
Comment: I just know the expected value of X, which is 3.5 and Y is also 3.5 But I don't know what to do in case of the greatest common divisor.
Comment: Can you give me an example for one possiblity, so that I can understand the problem.
Comment: Do you know what the greatest common divisor is? Do you know how to compute the greatest common divisor of $4$ and $6$, for example? If not, you probably need to go and study that first.
Answer: You can make a table. This is mostly a good idea in cases of two dice. The first column and row are the possible outcomes of the two dice each. For each combination the $gcd$ has been inserted. Please check the entries.
$$ \begin{array}[ht]{|p{2cm}|||p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|}  \hline \text{ d1/d2 } 1 & 1 &2 &3 &4 &5 &6  \\ \hline \hline \hline 1 &1 &1 &1 &1 &1 &1 \\  \hline  2& 1 & 2 &1 &2 &1&2  \\ \hline 3& 1 &1 &3 &1 &1&3\\ \hline 4 &1 &2 &1&4&1&2 \\ \hline  5 &1 &1&1&1&5&1 \\ \hline  6&1&2&3&2&1&6  \\ \hline \end{array}$$
Each outcome has a probability of $\frac1{36}$. Now it is not difficult to calculate $E(Z_2)$.
Comment: Mouse/mice; die/dice. $\nexists$ _dices._
Comment: @BruceET Now I know that. Thanks for this information and your edit.
Answer: Make a $6 \times 6$ table, in which each of the 36 cells shows the GCD. I've
filled in the first three rows. (This is before morning coffee for me, so better check!) Can you finish?
<code>X\Y:   1  2  3  4  5  6
1      1  1  1  1  1  1
2      1  2  1  2  1  2
3      1  1  3  1  1  3
...
</code>
Then count to find numerators of
fractions of which denominators are 36.
Comment: Thank you very much. In Europe, it is 7 pm:D good morning.

Two distinct dice, expected value


Can I filter Event Viewer for a determined Exception message?

Question: O/S: Windows Server 2003. IIS 6.0. There is no SQL-Server.
I'm looking for filtering all events that have this Exception message: "Connection request timed out". Would it be possible?
Answer: Heres my powershell one-liner.
This will output a table with the the Date and Time of each occurrence on the error.
get-eventlog -LogName Application | Select TimeGenerated, Message, Source | where {($_.Message -like "*Connection request timed out*") -and ($_.Source -like "ASP*")}

Answer: Not natively in 2003, but with some scripting it can be done.
Natively, you're restricted to the filter categories in the screenshot (right click the Event Log in question, View -> Filter...), but with a script you can basically copy out only the events containing certain text to a .evt (Event Log) file and open that up.
Comment: Could I export all event logs to a txt file? Having that, then I could load it to a sql table and filter.
Comment: @user316687 You can.  Right click the log, `Save As...` and you can save it as a tab delimited text file, a `.csv` or a `.evt`.  I might suggest trying to filter by "warning" first, since it seems that those are all warnings.  Could make life easier, depending on what you're trying to do with the logs.
Comment: It's not possible to filter natively in the way I need. Is there any free tool to be recommend?
Comment: @user316687 Not that I know of.  Like I said, I do this with [PowerShell] scripts.  Parse the event log for the events I want, copy them to a new event log, open that.


Is it possible to merge two broadband connections?

Question: I have installed a hotspot for our local harbor. The hotspot is mainly for Russian ships to use. The installation is a single network setup with several wireless links and access points, so all the harbor is online.
When we started, the norm was one ship at the time. Now, there is a constant stream of Russian ships seeking our local harbor, because of the free Internet access. This is good, because that's the point of the hotspot. There is one problem though: Our ISP in the Faroe Islands only offers 20/1 broadband connections at astronomical prices and a 20/1 connection isn't any good if there are 50 users all expecting a fast connection.
Is it possible to merge two or three 20/1 connections into the same network? Is there any hardware on the market, made for the job?
My hotspot is capable of 100Mb+ connection (long range), so merging three connections will not exceed the hotspot's capabilities and it would save me a lot of trouble of setting up a new complex network.
Answer: Yes there are a lot of load balancers for ISP redundancy on hardware ammpliances. In fact most of the Firewalls have this feature.
Thought you can do it by software in a standard machine.
With Microsoft Forefront TMG 2010 you can enable the feature ISP Redundancy.
On Windows you can do not a really network balancer but something similar, this is called Distributed Network Sessions. It is that if you have two NICS with two gateways windows can random the send of the packets from one interface and other and due this happen very quickly in practice you get the addition of the both bandwiths.
For do that you need to change the registry value RandomAdapter in

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netbt\Parameters

and restart the computer as this Microsoft article says: TCP/IP: Load Balancing vs. Distributed Network Sessions
On Linux you can accomplis this task using IPTables, as you can see in this Server Fault question: Load balancing & NAT-ing multiple ISP connections on Linux.
Answer: Mikrotik allows for bonding of multiple lines with their Router OS and Routerboard series hardware. We run this in a satellite office to improve upload speeds where "business" internet doesn't necessarily exist (at least, at a reasonable price).
More information can be found here
Answer: You're going to need to place a device, most likely a router in front of your hotspot to load balance the connections, preferably a device that will do a round-robin load balance for you. A low-end sonicwall firewall can do this very easily, and provide you a little more protection at the same time.
Comment: I have a firewall, and I also have traffic shaping up and running. But is it possible to merge several broad bands into one network?
Comment: IIRC, round robin "merges" the connections by rotating connections through the broadband connections. Its about the closest thing you can get to merging connections
Comment: Correct, and ideally the sessions will be "sticky" so that for each source IP it sticks with that broadband link per session so things like FTP don't complain.
Answer: I believe that what you are looking for is channel bonding but this will require configuration from your ISP side. If they are open to it, you can always approach them to help with it. This can be done if all your down-link connections come from the same ISP.
Otherwise, the next best thing would be round-robin or some other neat routing trick. This can work even if your down-links are from different ISPs.
However, you must also realise that most of the bandwidth advertised by ISPs are best effort meaning that you may not get the linear increase in bandwidth that you may expect.
Answer: Yes. There are several devices on the market, currently in use in trains etc. You need to place a concentrator in some datacenter that will merge the datastreams. I have built such software too (Linux), it has been in use for several months. Contact me if you want to try/use it.


Derivation of energy integral - harmonic functions

Question: I am following the solution of the following problem on the topic of the energy integral of a surface.

For a real-valued continuously differentiable function $u(x,y)$ on a closed domain $D$, the energy integral is defined as follows. $$E(u)=\iint_D \left( \left(\frac{\partial u}{\partial x}\right)^2+\left(\frac{\partial u}{\partial y}\right)^2\right) dxdy.$$ If on $B$, the boundary of $D$, the function $u$ achieves the specific values of some function $f$, how can $E(u)$ be minimized within $D$ over all functions $u$, given the described boundary-constraint?

Here is how the author goes about finding out how to minimize the energy integral.

Suppose that the function $u_0$ produces this minimum: $$E(u_0)\leq E(u),\,\,\,\textrm{ for all functions }u\textrm{ with }u=f \textrm{ on } B$$
  Let $v$ be any continuously differentiable function on $D$ that is zero on $B$. Then $u_0+\epsilon v$ equals $f$ on $B$ for any number $\epsilon$, and because $u_0$ has the minimum energy integral, $$\begin{align*}
E(u_0)&\leq E(u_0+\epsilon v)\\
&= E(u_0) + 2\epsilon \iint_D \left(\frac{\partial u_0}{\partial x}\frac{\partial v}{\partial x}+\frac{\partial u_0}{\partial y}\frac{\partial v}{\partial y}\right)dxdy + \epsilon^2 E(v)
\end{align*}$$

The last part is what I don't understand. Where did that expansion of $E(u_0+\epsilon v)$ come from? Could anybody explain what each term in that expansion is there for?
Answer: Using the simpler ($\LaTeX$-wise) notation
$u_{,x} = \dfrac{\partial u}{\partial x}, \tag{1}$
we have
$(u_0 + \epsilon v)_{,x} = u_{0,x} + \epsilon v_{,x}, \tag{2}$
whence
$((u_0 + \epsilon v)_{,x})^2 = (u_{0,x})^2 + 2\epsilon u_{0,x} v_{,x} + \epsilon^2 (v_{,x})^2; \tag{3}$
similarly
$((u_0 + \epsilon v)_{,y})^2 = (u_{0,y})^2 + 2 \epsilon u_{0,y} v_{,y} + \epsilon^2 (v_{,y})^2; \tag{4}$
when (3) and(4) are used in the expression for $E(u_0 + \epsilon v)$, the stated formula easily follows.
Hope this helps.  Good Yule Season,
and as ever,
Fiat Lux!!!


Google Sheets Ifs Statement: Only Counting One Logical Expression

Question: I'm trying to set up a database and set up different alerts/flags if data is not entered in certain cells. For instance, if data is entered in cell one but not in cell two, I want one alert but if data is not entered in either, a different alert.
At the moment, I have tried to use this:
<code>=IFS(C2="*", "Plant", E2="","Support")
</code>
Support is showing up correctly, but Plant is not.  Any thoughts?
Answer: try like this:
<code>=IF((A2<>"")*(B2<>""), "all good",
 IF((A2="") *(B2=""),  "both values missing",
 IF( A2="",            "A value missing",
 IF( B2="",            "B value missing", ))))
</code>


Translated terms are not searchable with Search API

Question: While using Search API it does not index the translated/localized terms.
So does it mean translated terms are not searchable with Search API?
any clue?
thanks
Answer: I think that this is core issue that the search index does not add the localized term to the index, I solved that by implementing hook_node_update_index($node) and fetching the localized term name by querying it from database because I don't know why i18n_taxonomy_localize_terms function doesn't load the term properly. my code is below:
<code>function mymodule_node_update_index($node) {
  $text = '';
  $tid = key($node->your_taxonomy['und'][0]['tid']);
  if($tid != 0) {
    $query = db_select('locales_target', 'lt');
    $query->addExpression('CONVERT(translation USING UTF8)', 'translation');
    $query->join('locales_source', 'ls', 'ls.lid = lt.lid');
    $query->condition('context', 'term:'.$tid.':name');
   $text = $query->execute()->fetchColumn();
  }

  return $text;
}
</code>
Note: in my case the text is Arabic so I converted the field character set from blob to utf8.
Comment: Great work @Omar , i ended up with having two different taxonomy terms instead of localizing. My localized taxonomy term was also in Arabic.Any how hopefully some one will make use of your code.