Interpretive limits in Debussy's Arabesque #1

Question: In Debussy's Arabesque #1, mm. 6–7 (among others) are scored as triplets against eighth notes (quavers):

(Image Source: IMSLP, first edition)
I've always interpreted this rhythm literally, and that is what I've heard in recordings and performances.
However, I came across Debussy's own recording (below), and, short of a painstaking transcription, it sounds more like "right hand as written; left hand arpeggio ad lib." I was left with the impression that Debussy intended this to sound more improvisational, and just notated the "impression" (for lack of a better term) of the sound he imagined.
I'm interested in what scholarship has to say about Debussy's attitude in this regard (literal interpretation vs. improvisation), either specific to this piece or regarding his compositions in general.
Can an improvisational approach to Arabesque #1 specifically, or Debussy generally, be justified by what is known about Debussy's attitudes toward the piece, his music, and/or music generally?
Comment: If you don't already know it, have a listen to what I think is the definitive (!) version, by Isao Tomita. A few decades old now, but still fresh as a daisy.
Comment: @Tim I just listened to about 20 seconds. I can't tell if you're joking or not.
Comment: Certainly not joking. There's a whole album dedicated to Debussy, all translated for electronic instruments, quite new at the time. Followed up by a (banned) Holst Planets set, which sister Imogen hated, thus banned. I don't care much for the latter, but the former is, in my opinion, an excellent interpretation. It is, after all, from the Romantic era. Thus lends itself really well, imo. Maybe a Marmite thing...
Comment: Interesting, like the opposite of "Left-hand-strict-right-hand-rubato" Chopin. I've definitely noticed other pieces in which a quirk of performance becomes established as "that's the way everybody does it," but the composer's original recordings differ. Bartok/Szeryng's "Roumanian Folk Dances," Copland's very brusque and jazzy Rhapsody in Blue, etc.
Comment: @AndyBonner - isn't Rhapsody in Blue Gershwin, not Copland?
Comment: @Tim Lol, yes, slip of the tongue. That would be a very different piece. (As would Gershwin's "Fanfare for the common man"—swung?)
Comment: @AndyBonner https://www.youtube.com/watch?v=ocGNcTzYTtQ&t=52
Answer: First, note that this is not a recording in the modern sense, but a piano roll. Accomplished pianists are highly adaptive to nuances of tone colour, clarity, attack, balance between different registers, etc, which can vary widely between different instruments. Pedalling effects are even more of a minefield. As a result, many details of the performance may come across differently from how the player originally experienced and intended them.
But also it seems highly doubtful that the performer on this particular track was Debussy himself. Debussy did create some piano rolls, which have been recorded on a restored player-piano and released under the title "Claude Debussy: The Composer as Pianist" on the Pierian label in 2000.
The track you referred to is from a release of more murky provenance on the Favourite Classics label, entitled "Claude Debussy Plays His Finest Works". It appears that several of the tracks on that recording are in fact not performed by Debussy himself. The correct attributions may be the ones listed here, in which case the original performer for the first Arabesque on your track is Lev Pouishnoff.
See the following links for more discussion. It would be nice if someone could clear all this up more authoritatively!:
https://www.reddit.com/r/classicalmusic/comments/ba6559/debussy_plays_debussy_all_known_recordings_or_not/
http://www.stevepur.com/music/debussy_plays.html
https://www.talkclassical.com/threads/debussy-plays-debussy-all-known-recordings-or-not.60763/


Rosegarden - can't get it to produce any sound

Question: With zero experience of Linux, I installed Ubuntu on an old laptop and then Rosegarden. However, I've never been able to get any sound to be produced by the software - not even a metronome. I've Googled it for hours on end but to no avail. I know there are various external packages needed ("Jack"?) and I've followed all of the suggestions I've found everywhere.
Can anyone suggest some obvious reasons why a fresh install of Rosegarden would have this problem - and how can I fix it?
If you can point me to a decent tutorial I'm happy to do the necessary reading. I found the Rosegarden tutorials less than helpful in this area.
Would a reinstall do it? Did I select the wrong option at Installation and need to start again? If so, how do I uninstall and reinstall?
For info, the laptop is an HP Probook but about 7 years old, quite powerful but with, I assume, a standard sound card. It has no problem producing sound from other sources like web pages and Youtube.
Any help would be most appreciated.
Answer: In the terminal, enter:
aplay -l

to view a list of all available sound cards.
In Rosegarden go to the "Settings" menu, and select "Manage MIDI Devices". Make sure the correct sound card is selected.
In the terminal:
 jack_lsp

to view a list of available Jack connections. If Jack is not installed, install it by running sudo apt-get install jackd2 in the terminal.
If Jack is installed:
ps -ef | grep jackd

to view a list of all Jack processes. If Jack is not running:
jackd -d alsa

If this doesn't work, uninstall Rosegarden:
sudo apt-get remove rosegarden

And reinstall:
sudo apt-get install rosegarden

Comment: Thanks for this answer - personally I gave-up on Rosegarden when I couldn't get it to work, but hopefully this will be helpful to someone down the line.


Synchronized method blocks execution

Question: I'm implementing a dummy program with three classes to have a more visual reference of how Futures work. My problem is that sometimes the program will get locked at the synchronized method and it won't go on. And I can't find a reason why. Can someone spot the reason why none of the fighters will print the "I won" line?
My current output when it blocks:

Fighter1
Fighter1 has entered the sync method
Fighter2
Fighter2 has entered the sync method

The code is as follows.
Main class:
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class TmpTest {
private static final ExecutorService executorService =
  Executors.newFixedThreadPool(2);

  public static void main(final String... args) {

    final Fighter fighter1 = new Fighter("Fighter1");
    final Fighter fighter2 = new Fighter("Fighter2");

    final Future<String> submitFighter1 = executorService.submit(fighter1);
    final Future<String> submitFighter2 = executorService.submit(fighter2);

    while (!submitFighter1.isDone() || !submitFighter2.isDone()) {
        if (submitFighter1.isDone()) {
            System.out.println("Fighter 1 wins!");
            submitFighter2.cancel(true);
            executorService.shutdown();
        } else if (submitFighter2.isDone()) {
            submitFighter1.cancel(true);
            System.out.println("Fighter 2 wins!");
            executorService.shutdown();
        }
    }
  }
}

Fighter class:
class Fighter implements Callable<String> {

  private final String fighterName;
  private final ClassWithSyncMethod classWithSyncMethod;

  public Fighter(final String fighterName) {
    this.fighterName = fighterName;
    classWithSyncMethod = new ClassWithSyncMethod(fighterName);
  }

  @Override
  public String call() throws Exception {
    return classWithSyncMethod.syncMethod();
  }
}

Dummy class with synchronized method:
class ClassWithSyncMethod {

  private final String fighterName;

  public ClassWithSyncMethod(final String fighterName) {
    this.fighterName = fighterName;
  }

  public synchronized String syncMethod() {
    System.out.println(fighterName + " has entered the sync method");
    try {
        Thread.sleep(1000);
    } catch (final InterruptedException e) {
        System.out.println("Exception trying to sleep the fighter " + fighterName + ";" + e);
    }
    return fighterName + " shouts: I won!";
  }
}

Answer: This has nothing to do with synchronization. Each fighter synchronizes on a different object, so they don't interfere with each other.
The reason you don't see the "I won" line is much simpler - you never print it.
The ClassWithSyncMethod#syncMethod() method (which is returned by Fighter#call()) doesn't print anything, it just returns a value. If you want to print it, you'd have to do so yourself from your main.
E.g.:
while (!submitFighter1.isDone() || !submitFighter2.isDone()) {
    if (submitFighter1.isDone()) {
        System.out.println("Fighter 1 wins!");
        System.out.println(submitFighter1.get()); // Here!
        submitFighter2.cancel(true);
        executorService.shutdown();
    } else if (submitFighter2.isDone()) {
        submitFighter1.cancel(true);
        System.out.println("Fighter 2 wins!");
        System.out.println(submitFighter2.get()); // And here!
        executorService.shutdown();
    }
}

Comment: Right key point `Each fighter synchronizes on a different object`, +1 for you

Synchronized method blocks execution


Displaying individual data from a count query(mySQL/php)

Question: I have a database called 'Telcel' and a table called 'calls'
columns in my table are id,call_from,call_to,date_time,duration,network,cost,status
I have the following code:
        $conn = mysqli_connect("localhost", "daven", "H3x^g0n", "Telcel");
        $query = "SELECT id, COUNT(id), call_from,ROUND(SUM(cost), 2) FROM calls GROUP BY call_from ORDER BY COUNT(id) DESC;";
        $result = mysqli_query($conn, $query);

        while($row = mysqli_fetch_assoc($result))
        {
            echo '

                        '. $row['call_from'] .'
                        '. $row['COUNT(id)'] .'
                        '. $row['ROUND(SUM(cost), 2)'] .'

                 ';
        }

which returns for example:
Call From   Calls   Cost
Shannon     10      50.2
Tom         3       7.6

I'd like when a name is selected to display all the calls, duration for each call and cost of each call made by the selected caller on the next page,So if Tom is selected display all the relevant information for Tom only, and if Shannon is selected same thing etc. Thank you.
Answer: You can sent GET requrest with url like total.php?call_from=Tom
So, you need to generate a href link with call from name :
while($row = mysqli_fetch_assoc($result)) {
    '. $row['call_from'] .'
    ...
}

And total.php use $_GET["call_from"] for receiving id from url to use in query  :
$call_from = $_GET["call_from"];
$query = "SELECT * FROM calls WHERE call_from = ". $call_from;
... //Display the table

Hope this help :)


Can a template function taking class object instantiate that object with it's constructors arguments?

Question: Let's say I have a template function taking a class object:
template<class T>
void Foo(T obj);

and a class definition as follows:
class Bar
{
public:
    Bar(int a, bool b): _a(a), _b(b) {}
private:
    int _a;
    bool _b;
};

Is there a way to make the following code compile?
Foo<Bar>(5,false);
Foo<Bar>({5,false}); // i know this works, just wondering if i can remove the brackets somehow.

Comment: `Foo` takes a single argument and in `Foo(5,false);` you're passing two arguments.
Comment: Seems like a good case for a variadic template
Comment: @john You can forward the arguments, but only in the function body. It needs either another function, or some specialization where the arguments can be forwarded
Answer: Yes, this can be done with variadic templates and forwarding, and has many standard examples, like std::make_unique.
In your case it would be:
template<class T, class ...Args>
void Foo(Args &&...args)
{
    T obj { std::forward<Args>(args)... };
    // use obj
}


Has there been an "eventless" English Premier League game?

Question: Has there ever been a game in the English Premier League during which no goals were scored and no cards were shown?
Answer: You can use the BBC list of match reports for this. Arsenal v. Sunderland was one such example.
http://www.bbc.co.uk/sport/0/football/19221271
Comment: If a card is drawn, an icon is shown next to the players name. See here, for example, where Huth and Wilkinson were both booked. http://www.bbc.co.uk/sport/0/football/19310426
Comment: I might have missed it, but where in that article does it say that no cards were drawn?


How to get the same reference given same arguments for equality test

Question: I build a map given tuples of string and number.
I want to cache this map, so when I want to create another map with the same given tuples, I get the same map. How can I do this?
export type Board = Map<string, number>

let boards: Array<Board> = []

function makeBoard(res: Array<[string, number]>): Board {
    let b = new Map();
    res.forEach(([str, num]) => {
        b.set(str, num);
    });
    return b;
}

let a1 = ['hello', 1]
let a2 = ['world', 2]

let b1 = makeBoard([a1, a2]);
let b2 = makeBoard(([a1, a2]));
let b3 = makeBoard((([a2, a1])));
let b4 = makeBoard(([a1]));

console.log('I want both to be true');
console.log(b1 === b2, b2 === b3);
console.log('I want this to be false');
console.log(b1 === b4);

I think I should hash the values, and put it in a map, then check the value of the map to match given input if it already exists return otherwise create a new result and put it in the map. I want this to be generic.
I thought this approach would make things easier for equality testing but maybe it's not necessary?
Comment: Do you use the maps for any other purpose?
Comment: No I don't mutate the map ever again. Just for lookups.
Answer:
I think I should hash the values, and put it in a map, then check the value of the map to match given input if it already exists return otherwise create a new result and put it in the map.

Yes, that is what I would suggest. You can first sort the array you get, and then stringify it (e.g. as JSON), and use that as key in a map of maps:
Note that in your existing code, you can use the Map constructor to build the map from those pairs in one go.

let superMap = new Map;

function makeBoard(res) {
    res.sort((a, b) => a[0].localeCompare(b[0]) || a - b);
    let key = JSON.stringify(res);
    let b = superMap.get(key);
    if (b === undefined) {
        b = new Map(res);
        superMap.set(key, b);
    }
    return b;
}

let b1 = makeBoard([["hello", 1], ["world", 2]]);
let b2 = makeBoard([["hello", 1], ["world", 2]]);
let b3 = makeBoard([["world", 2], ["hello", 1]]);
let b4 = makeBoard([["hello", 1]]);

console.log('I want both to be true');
console.log(b1 === b2, b2 === b3);
console.log('I want this to be false');
console.log(b1 === b4);
Comment: I forgot to mention that possible pairs are reference equal to each other would that help in a way to use a different approach?
Comment: Yes, then you could create yet another Map to map those pairs to unique integers (incremental). The more you know about the data, the better solution you can make. If for instance those strings are within a closed set, maybe a coordinate, then you could map those to a range of integers... If these ranges are limited, then you could use bitmaps... It all depends on your real data.
Answer: Try using some kind of cache with a hash of the arguments. something like this: (didn't test the code)
let boards: Array<Board> = []
const cache: {[args:string]:Board}= {};
function makeBoard(res: Array<[string, number]>): Board {
    const hash = JSON.stringify(res.sort((a:[string,number],b:[string,number])=>(a[0]+a[1] > b[0]+b[1])?1:-1));
    if (cache[hash]!==undefined)
    return cache[hash]
    let b = new Map();
    res.forEach(([str, num]) => {
        b.set(str, num);
    });
    return b;
}


Can't add contextual Filter (taxonomy term ID (with depth)) to a View (User)

Question: please help me out here:
I can't find a contextual filter by taxonomy term with depth on a view of users and/or profiles. When I make a view of content it can be chosen.
I'd like to provide a filter for Regions, so Filter for Europe should result in a List of Users from all over Europe and so on.
The users are associated with a taxonomy term.
Thanks for your help or any suggestions.
Christian
Comment: As far as I remember this filter uses old `taxonomy_index` table, and it only indexes nodes. And only published ones. It was already reported in Views issue queue, I remember posting in this issue, but I cannot find it now. Solution is to use relations.
Comment: Hi Molot could you give me a further hint for your mentioned solution?
Comment: If I could, I would post an answer, not just comment. If I'll find the issue, I'll post it. Or maybe my comment would guide someone else to a correct answer?
Comment: http://drupal.stackexchange.com/q/36217/16495 this question might help, not exactly the same but contains not bad hints.
Answer: In D7, you can only do that with the node table (the content).
If you want to have a working solution for every entity of your system, you have to use this module.
Once installed, don't forget to rebuild the index of your entities, then, in views, you'll have the possibility to add a new relationship ('Taxonomy Entity Index: Taxonomy terms on User') and a filter with depth ('Taxonomy Entity Index: Has taxonomy terms on User (with depth and indexed in taxonomy_entity_index)').


Methods to prevent malicious crawlers/scrapers and DDoS Attacks

Question: From last couple of weeks I have been experiencing bot attacks on my site. Basically crawlers are running on the site at a high frequency rate resulting in load increase. This results in bandwidth consumption and thus poor user experience for rest of the people. I would like to know how sites like google, amazon and e-bay prevent these things:

How do they differentiate between useful crawlers(google/yahoo/msn) and malicious ones which do not follow robots.txt and other rules?
How can I identify a pattern which can lead to a potential harmful bot in real time by checking the apache access logs?

The threshold values like connections or packets/time/ip can not be set as this will result in poor user experience for the proper customers on the site.
Answer: Here is what I did, and what I recommend:
Create the following script that runs on cron between 1-5 minutes: Read the raw access logs (say, the last 20,000 lines - depending on how active your site is), organize the data by IP/hostname, and then by unix time with attached results. Loop through the results, and identify which IP's have not made any requests to known and required page elements, like images, js, css, etc. From those, count how many page requests were made in one second. I'd characterize 4 page requests or more in a second as excessive and abusive. From there, check against a whitelist of good bots (preg_match against hostname for things like "googlebot.com", etc.), and store all the ip and hostname of the results not white-listed into a database.
Create another script that runs on every page before anything is displayed/processed. Have it validate if the page that is being requested is from an IP that is in your database of banned IP's. If it is, return a 403 with a captcha form prompting the user to submit for reconsideration. If they do, and it validates, have the script unban them. If they aren't banned, store this in a session to avoid repetitive validation for that visitor.
Finally, install monit on your server, and configure it to monitor http once per minute. If the server is unresponsive, it'll restart automatically. This will help to minimize downtime and extreme lag. The script I outlined above will automatically identify scrapers and bad bots, and revoke access. It will also automate reconsideration requests if there are any.
Comment: Hi @Don, I have reposted the same question here : http://programmers.stackexchange.com/questions/126700/development-of-a-bot-web-crawler-detection-system
Answer: A solution like Cloudflare or Project HoneyPot should do the trick. Look at this for a few other pointers - https://drupal.stackexchange.com/questions/45678/watchdog-404-page-not-found-entries-from-spambot-guessing-urls/48448#comment50114_48448


What is an algorithm to spiral outwards from (0,0) in increments of +/- 1

Question: I need to map a collection onto a grid with an odd width and height (thus it can have a center) in a way that spirals out from the center to an arbitrary size. There's a description here that shows how to spiral inwards through a matrix, but it requires knowing the dimensions of the matrix. I want to spiral outwards for any number of grid tiles given just the index. For instance, given a grid like this:

(-1,-1)
(0,-1)
(1,-1)

(-1,0)
(0,0)
(1,0)

(-1,1)
(0,1)
(1,1)

We have a function f that we hardcode an initial direction of up (negative y) and a spiral direction of counterclockwise such that we can say:
f(0) = (0,0)
f(1) = (0,-1)
f(2) = (-1,-1)
f(3) = (-1,0)
And so on to
f(8) = (1,-1) and f(9) = (1,-2)
Is this even possible to model as a function? Would it have something to do with pi because it's kind of a circle? Every spiral function I can find has curves instead of abrupt whole integer steps. I recall from an algorithms class a couple of years back that clamping stuff to integers sometimes counterintuitively makes computation less tractable.
Comment: See Ulam spiral https://oeis.org/A174344
Comment: See this question: https://math.stackexchange.com/questions/3157030/parametrizing-the-square-spiral
Answer: Like Jean Marie pointed out, the answer is the Ulam (square) spiral. It is a recursive algorithm, I was hoping for a clean O(1) function, but it works! It starts on the right and spirals out clockwise.
The following is in the Python language.
def ulam_spiral_xy(n):
    if n == 1:
        return (0, 0)
    else:
        x, y = ulam_spiral_xy(n-1)
        return (
            x + int(math.sin(math.floor(math.sqrt(4*n-7))*math.pi/2)),
            y + int(-math.cos(math.floor(math.sqrt(4*n-7))*math.pi/2))
        )

This block of code
array = [
        [21,22,23,24,25],
        [20,7,8,9,10],
        [19,6,1,2,11],
        [18,5,4,3,12],
        [17,16,15,14,13]
]

for i in range(1, 26):
        coords = ulam_spiral_xy(i)
        print(array[coords[1] + 2][coords[0] + 2], end = " ")

gives us the expected output of
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Comment: FYI for readers who might want to reproduce this themselves, the code is in Python
Answer: It is possible to write the function $f(n)$ in an $O(1)$ form (provided you assume all arithmetic operations, including the sqrt function, are $O(1)$).
The spiral consists of sequences of motion up, left, down, or right
in a predictable pattern, so you just have to deduce which sequence of motions the $n$th point is in, how far within that sequence it is, and where that puts it in the coordinate grid.
Here is a non-recursive version of the function $f(n),$ coded in Python 3.
# Find the nth set of coordinates in a spiral through
# lattice points starting at 0,0

from math import sqrt, floor, ceil
import numpy as np

# Treating the spiral as a sequence of concentric squares
# around the origin, return the inradius of the square that
# the nth point is on.
def cycle_number(n):
    x = floor(sqrt(n))
    return ceil(x/2)

def first_number_in_cycle(k):
    return 4*k*(k-1) + 1

def side_length_in_cycle(k):
    return 2*k

def point(x,y):
    return np.array([x,y])

corner_vectors = (point(1,-1),point(-1,-1),point(-1,1),point(1,1))
side_directions = (point(-1,0),point(0,1),point(1,0),point(0,-1))

def f(n):
    if n == 0:
        return point(0,0)
    k = cycle_number(n)
    distance_from_cycle_start = n - first_number_in_cycle(k)
    # Identify which of the four sides (straight sections)
    # of the cycle n is in:
    side_length = side_length_in_cycle(k)
    side = floor(distance_from_cycle_start / side_length)
    distance_along_side = 1 + distance_from_cycle_start % side_length
    ref_position = k * corner_vectors[side]
    return ref_position + distance_along_side * side_directions[side]

#-----------------------------------------------------------
#  Everything below this point is just to test f(n)

# Assume x and y coordinates range from -3 to 3 inclusive
data_array = np.array([[0] * 7] * 7)
def write_data(p, value):
    x = p[0]
    y = p[1]
    data_array[y + 3, x + 3] = value

def print_data():
    for row in range(7):
        for column in range(7):
            print(f' {data_array[row][column]:3}', end='')
        print('')

for n in range(49):
    p = f(n)
    write_data(p, n)
print_data()

Displaying the output in the same coordinate system used in the question
(left-handed Cartesian coordinates with the $y$ axis pointing down and the $x$ axis pointing right), the output looks like this:
  30  29  28  27  26  25  48
  31  12  11  10   9  24  47
  32  13   2   1   8  23  46
  33  14   3   0   7  22  45
  34  15   4   5   6  21  44
  35  16  17  18  19  20  43
  36  37  38  39  40  41  42

As a bonus, if you append the following to the Python code shown above,
you get a function sequence_number that takes a pair of coordinates and
returns the value of $n$ such that $f(n)$ is the given pair of coordinates.
That is, sequence_number is the inverse of f.
Using sequence_number, we can produce the same output shown above, but it is computed left to right one row at a time instead of by increasing values of $n.$
def taxicab_distance(u,v):
    return max(abs(v[0] - u[0]), abs(v[1] - u[1]))

# Return the value of n such that f(n) has the given coordinates
def sequence_number(p):
    x = p[0]
    y = p[1]
    k = max(x, y, -x, -y) # the cycle number
    side = (3 if x == k
            else 2 if y == k
            else 1 if x == -k
            else 0)
    ref_position = k * corner_vectors[side]
    distance_along_side = taxicab_distance(p, ref_position)
    side_length = side_length_in_cycle(k)
    n = first_number_in_cycle(k) + side * side_length + distance_along_side - 1
    return n

#-----------------------------------------------------------
#  Code to test sequence_number(p)

print('plotting f(n) -> n')
for y in range(-3, 4):
    for x in range(-3, 4):
        p = vector(x,y)
        n = sequence_number(p)
        print(f' {n:3}', end='')
    print('')


I am stuck on barre chords

Question: I started learning guitar months ago. Now I can play basic melodies and couple of basic chords and couple of songs with pick or finger style.
The problem is I stopped progressing because I'm having problem on playing complicated chords specially barre chords.
Does anyone suggest me how to go through this phase and overcome this difficulty?
Comment: Maybe consult a teacher for tips on technique, but mostly it's building up muscles/practice.
Comment: @Rich see my own answer
Answer: Several factors arise with barre chords. The first consideration for me is the action of the guitar. If that's not good, any player will have hard work making them sound good easily. In a lot of classical playing, half barres are used, and those are easier to play, and get you into the right positions better.
Bear in mind that with full 5 or 6 string barres, there is never the need to actually press down all the strings - two or three are usually pressed down by fingers higher up the fretboard than the barre.
Barres are notoriously difficult to start with - I've only ever had one student who played them cleanly, first time, in the lesson, having only just been introduced to them - certainly not practised beforehand. All others take a few weeks to settle themselves in.
Experiment with rolling the barre finger so that it touches the strings with its more boney side, nearer to the thumb. Also, decide how much finger needs to be sticking out at the top on the fretboard, near the 6th string, so no strings are under the creases of skin where the joints are.
And sort it out with a teacher!
Comment: "With full 5 or 6 string barres, there is never the need to actually press down all the strings" — I certainly don't agree. I get to play some of these every day (in "classical guitar" pieces like Torroba or Lobos — an "empty" 5-string barre makes a major 11th chord, for instance). Otherwise +1.
Comment: @Ramillies - often there are other fingers used to form the other notes used on barre chords - far more often than needing to play maj11, or m7add11 chords. So 'never' should be 'rarely'.
Comment: Exactly. That was the only thing I wanted to say. A nice answer otherwise.
Comment: Good answer. I simply want to add that beginners can also practice playing mini-barre chords. For instance, you could barre only the 1st, 2nd + 3rd strings on, say, the 5th fret to play an `Am` chord. After you get comfortable with that, you can add your small finger on the 7th fret of the 4th ('D') string to add another voice to that `Am` chord. After you get comfortable with that, you can add your ring finger to the 7th fret of the 5th ('A') string and then, finally, a full 6 string `Am` barre chord by extending your first finger all the way to the 6th (low 'E') string.
Comment: @DougRisk - it's a nice idea, and works best with kids and those with small hands. However, the skill in making a 2 or 3 string half-barre doesn't go a long way to preparing for a 5 or 6 string barre, in my experience.
Answer: After some researched I found that strings have different tensions and some people were talking about using low tension string or Flamenco strings.
I replaced my strings with Flamenco strings and I feel it is a little easier to hold the barre chords.
However I marked the other post as answer, I thought this may help other beginners.
Answer: Check with your teacher (or at least an experienced player) that you're approaching barre chords in the right way.  Then just keep practicing.  It will come.

I am stuck on barre chords


Is evaluating a holdout model against the full model a pseudo way of in-sample testing?

Question: A model has been built using quarterly data over a 14 year period. The data is not available for each quarter hence the total number of observations is less than 4*14.
Then a second model is built by using first 80% of the quarterly data from the total pool. The parameters of this 'holdout model' are compared with the original model that has all data points.
Is this valid in-sample testing? I don't consider this in-sample testing but I'm open to a convincing argument. The variables used to build the two models were the same.
Answer: Ok, after more research - this isn't quite in-sample testing per se but more so bootstrapping (albeit one sample) to test the stability of model parameters.


Animação em background HTML

Question: gente eu vi em um site a seguinte animação no background e gostaria de saber se alguém tem o  código fonte dela ou algo do tipo ....
segue o link do site com a animação: a link!
Answer: Esse background é uma animação com canvas (js)
Aqui tem o Github do projeto
https://github.com/VincentGarreau/particles.js/
E aqui o link dele funcionando e com opções de configuração e download
http://vincentgarreau.com/particles.js/
Se vc quiser estudar o código aqui no Codepen também tem um modelo.
https://codepen.io/VincentGarreau/pen/pnlso?limit=all&page=2&q=Canvas

Animação em background HTML


What is the relation between the training time and the batch size?

Question: In the deep learning process, especially SAR-ATR (e.g., generic object detection),
is there any relation between the training time (speed) and the training batch size?
Is there a paper related to this question?
Comment: Even if you read data, without any additional operations, then with larger files it takes longer then with smaller files.
Answer: There's no exact formula, but usually there's some kind of a optimal batch size. Batch size 1 or batch size equal to entire training sample size usually run slower than something between these extreme, e.g. 100. You'll have to find what's the optimal size for your problem and ML software/hardware setup.
Answer: If you use GPU you can usually achieve better performance (speed-up) by increasing batch size, this because of matrix multiplication and using multi-threading in better way. Bigger batch leads optimization step to be more "directed by data" (less random walking), however it could in rare situation leads to stack in a local minimum. You should be aware that increasing batch size could also leads to need of no epochs increasing.
Some authorities recommend to use the biggest batch you can.


Can't access a property in an API using Jquery

Question: I am trying to retrieve data from an API using jQuery but I am unable to get a response.
This is the API endpoint I am using (https://en.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=frank%2525ocean&format=json&gsrprop=snippet&prop=info&inprop=url).
This is the code to retrieve the property 'gsroffset':
<code>$(document).ready(function(){
  $.getJSON("https://en.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=frank%ocean&format=json&gsrprop=snippet&prop=info&inprop=url", function(x){
    var testCheck = x.continue.gsroffset;
    console.log(testCheck);
  });
});
</code>
But the value does not appear in my console.
Comment: You can't query wikipedia, because of [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), You would see it in console: Failed to load https://en.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=frank%ocean&format=json&gsrprop=snippet∝=info&inprop=url: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Comment: Do you recieve any errors in the console?
Comment: @S.Walker Nah noting appears
Comment: @BogdanKuštan Interesting thanks. The wiki API is messed up.
Comment: I threw the code in a simple web page and got this error on the Chrome browser console: "Failed to load https://en.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=frank%ocean&format=json&gsrprop=snippet∝=info&inprop=url: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access."   HOWEVER, using Postman, the url did fetch the data; and that header referenced in the error above, was not in the GET request.
Answer: Try adding "origin" key set equal to value'*' at the end of your url
like this :<code>"https://en.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=frank%ocean&format=json&gsrprop=snippet&prop=info&inprop=url&origin=*"</code>


Device Driver IOCTL pass int

Question: I have written a device driver and need to pass an int value to it. Am using copy_from_user() for this. Here is what I have done so far,
#define MY_MAGIC 'G'
#define TEST_IOCTL _IO(MY_MAGIC, 0)
#define PASS_STRUCT_ARRAY_SIZE _IOW(MY_MAGIC, 1, int )
#define TEST_IOCTL_ONE _IO(MY_MAGIC, 2)

int major;

int device_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg){

int ret, SIZE;

switch(cmd){

    case TEST_IOCTL:
        printk("NO argument IOCTL called\n");
        break;

    case PASS_STRUCT_ARRAY_SIZE:
            printk("Inside PASS_STRUCT_ARRAY_SIZE\n");
        ret = copy_from_user(SIZE, arg, sizeof(int));
        if(ret < 0){
            printk("Error in PASS_STRUCT_ARRAY_SIZE\n");
            return -1;
        }
        printk("Struct Array Size : %d\n",SIZE);
        break;

    case TEST_IOCTL_ONE:
        printk("NO argument IOCTL_ONE called\n");
        break;

    default :
        return -ENOTTY;
}

return 0;

}

When I call the TEST_IOCTL & TEST_IOCTL_ONE the module works properly. However when I call PASS_STRUCT_ARRAY_SIZE the system freezes.
Userspace code is this,
if(ioctl(fd, PASS_STRUCT_ARRAY_SIZE, 10) < 0){
    perror("PASS_STRUCT_ARRAY_SIZE : ");
        return -1;
}

What can I be doing wrong?
Comment: You should never pass an `int` via an `ioctl`, because it may be a different size in kernel vs userspace.
Answer: Sorry, my previous answer was wrong. Since the argument is an integer you should just use it without copy_from_user:
SIZE = arg;

You only need copy_from_user when the argument is a pointer.
Comment: Thanks :) the new one works..actually your previous answer was helpful I want to pass(next step) a struct from user space the memory address issue is helpful :)

Device Driver IOCTL pass int


Is it ok to leave a sql connection open?

Question: I am receiving data through a com port continuously and doing some decoding. When decoding is done i have to store the results in a sql database. I am thinking since the decoding is done (in a while loop always running) dozens of times per second and data need to be stored to the database dozen of times every second if it is wise to open and close the connection to the sql server in each while loop or just leave it open and continue to write data to the database.
First of all is this possible? Secondly if the connection remains open can third party applications or computer access the database at the same time and read data as my programm stores data?
Comment: http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx
Comment: Personally, I open/close to avoid confusing transfer in scope/lifetime -- even if it might not be needed. If there is a perceived performance issue, benchmark (as others pointed out, pooling essentially negates this). Make sure to manage *transactions*, however. Even if the DB is kept open, remember to *commit* as required. Otherwise data may never be commited or locks may never be released :)
Comment: And another thing. Can i open and close a connection several times a sec or there is a timeout or something like that preventing such often use?
Comment: Program will be running 24/7. This means never closing the connection
Answer: A database supports more than one concurrent connection, so yes it is very feasible in this scenario to leave the DB connection open - you will only lock out others if you have i.e. a long running query that results in row/ table locking.  Just close the connection when you are done.
Also consider though that most DBs (i.e. SQL Server) use connection pooling internally, so even though you close a DB connection it just goes back to the pool and is not physically closed - the pool manages the physical DB connections - this results in much better performance, so the impact of opening/closing connections rapidly is reduced.
From MSDN:

Connection pooling reduces the number of times that new connections
  must be opened. The pooler maintains ownership of the physical
  connection. It manages connections by keeping alive a set of active
  connections for each given connection configuration. Whenever a user
  calls Open on a connection, the pooler looks for an available
  connection in the pool. If a pooled connection is available, it
  returns it to the caller instead of opening a new connection. When the
  application calls Close on the connection, the pooler returns it to
  the pooled set of active connections instead of closing it. Once the
  connection is returned to the pool, it is ready to be reused on the
  next Open call.
Comment: @redfrogsbinary: Unless you explicitly disable it its on by default
Comment: actually  I wouldn't do that. Open/close as needed and let connection pooling do what it was designed for.
Comment: pooling is engaged automatically?
Answer: I'd open the connection, go through the loop as many times as needed, then close the connection.  Opening and closing is very expensive.  But, thanks to Mitch Wheat and Dave Markle, I've learned that connection pooling is done for free in the background with .NET, so the expense should be amortized over all your requests.
Even better, I'd batch the requests in the loop and execute the batch after the loop was done.  You only require one network round trip that way.
If you agree with that last bit, I'd make sure that the batch INSERT was done in a transaction context so it could be committed or rolled back as a single unit of work.  Isolation and thread safety will matter.
Comment: "Opening and closing is very expensive." - Opening first time is; after that, provided connection string is the same, connection pooling should kick in. But as you say, batch requests.
Comment: Although opening and closing *is* expensive, he's using C#, which probably means that he's got connection pooling working for him in the background, which just about completely mitigates this issue.
Comment: Assuming that a pool is used, Mitch.  No initial indication that one is in play.  I agree if you see one.  I didn't realize that pooling came along for free in .NET.  If that's the case, I'll amend my answer.
Comment: loop never ends. This is what keeps com port open
Comment: pooling is engaged automatically?
Answer: I personally would open and close the connection each time.  You should be protecting your code in a way that any exception will ultimately close your connection.  Will your app be the only application talking to this database?
Comment: In that case I would cautious with holding onto connections any longer than necessary.
Comment: in my case eachtime would be in the loop
Comment: correct.  I would only keep the connection open when there is something left to read or write.  If you are waiting for some other process/step to finish, I would close the connection.
Answer: Actually you must explicitly close SqlConnection.Open()
From MSDN, "Note   If the SqlConnection goes out of scope, it is not closed. Therefore, you must explicitly close the connection by calling Close or Dispose."
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.open(v=vs.71).aspx
Cheers!


Data validation in google forms related to questions

Question: hiii, i am new here, I am preparing a google form, and wanted data validation details as below:
Question 1 - how many children with you
Ans (example)- 3
Question 2 - Son
Ans (example)- 1
Question 3 - Daughter
Ans (example)- 2
I want validation in last both answers, that Answer 2 & 3 must match with Answer 1
waiting for your fruitful responses...
Answer: For validating check the official support google docs
check this below mentioned links for validation in google forms
reference: https://support.google.com/docs/answer/3378864?hl=en
Comment: thanks for your prompt reply, but my question is different, i already tried that but there is no solution for my question,


String variables in GAMS

Question: How can I define a string variable in GAMS. I want to use it as a reference to including files as shown below
<code>set file = "myfile.inc"; (i have no idea how to do this part)
$include file;
</code>
istead of
<code>$include "myfile.inc"
</code>
Answer: $set file file_name_here
$include %file%.inc
File is being replaced by your desired filename.
Note that if you want to use this string variable in other included files too you have to use $setglobal instead of $set

String variables in GAMS


Conveniently obfuscating all string literals in C++

Question: I have seen this question and ADVobfuscator git repository. The closest thing I've found  is something akin to this repository.
But my problem is that I have a rather large code that uses several system calls and prints lots of messages based on string literals and concatenations thereof. Because of this, many commands get written in the object code, where I'd like them to remain readable with minimal clutter.
Unlike a single password that can be locally encrypted with a OBFUSCATE macro, I'd like to have a global solution, such that every string is obfuscated, without having to place this macro each time, so that my code remains readable for developers and reviewers, while the executable has these strings somewhat obfuscated.
This is not a matter of security, but rather of protection of intellectual property, I just want to avoid having curious end-users reverse engineering my executable in their spare time. I'm not trying to prevent any elaborate attack.
Comment: *"This is not a matter of security, but rather of protection of intellectual property"* Confidentiality is a branch of security. Protecting intellectual property is a matter of security.
Comment: Feels odd seeing "convenient" and "obfuscation" being used together.
Comment: @FrançoisAndrieux : Fair point, but I'm not sure how to reword then. What I mean is that I'm not storing passwords in the code, but rather plain commands. If a few strings were decrypted, I wouldn't care, the problem would be if any user would gather all the strings form the executable and guess-work his way into replacing significant parts of my application, thus rendering the application borderline useless for that user. That, over time, would also help him reverse engineer a lot of stuff.
Comment: "_the problem would be if any user would gather all the strings form the executable and guess-work his way into replacing significant parts of my application_" - If that is a real concern, you are going about solving it the wrong way. Pretend that your obsufcation algorithm is known to the public. It will be in no-time even if you don't want it anyway. You could hash the commands and only store hashes in your executeable to obfuscate it a little, but how do you verify that a user (with ample time to depickle your program) is entitled to use it?
Comment: @TedLyngmo The software is meant for very limited distribution with perpetual license + yearly support + pay for new/custom features monetization scheme. Because the amount of end-users is small, and they're expected to be busy people, I simply assume there will be none who happens to have the free time and minimal documentation to start a reverse engineering project. What I do want to avoid is having a user with little free time guesswork his way into a lot of important stuff in a manner that is just way too easy to do.
Comment: In this way, I'd expect the end user to have no ideia that there would be encrypted strings in the object code. So I'd be very unlucky if he both found out about this, and found the hashing method and only then started reverse engineering for fun.
Comment: Well, you could use a `constexpr` hash function so that all that is stored in your object files are numbers. `if( hashfunc(user_command) == hashfunc("secret_command") ) ...` "secret_command"` would then be hashed when compiling and no trace of the real command would be found in the object file.
Comment: @TedLyngmo That would be good for passwords, but what I have is actually a lot of system call commands. Because I do lots of `system("string I don't want in executable");` or `printf("Error message the user might see, but doesn't need to find in the executable");` I can't just use if-else logic based on hash functions.
Comment: Ok, in that case you need encryption, not a one-way hash.
Comment: Perhaps the easier solution is just to run the executable through one of the .exe-compressor type programs before distributing it.
Comment: A portable solution is going to be hard. Do you have a specific OS in mind?
Comment: I don't think you can get any convenient way unless you use a preprocessing tool to process the strings before every build
Comment: @JeremyFriesner: While not perfect, I think UPX did a pretty good job. If you want to add an answer explaining about executable compressors, I'd surely upvote it and probably accept it.
Answer: One easy(ish) solution is to run your executable file through an executable-compression program like UPX before distributing it.  The file-compression should serve to obfuscate any string literals in the resulting executable file.
Comment: you can add UPX as an example to your reply.
Comment: i am not familiar with these, but if they are compressing wouldn't it be trivial to decompress ie extract?
Comment: Yes, fairly trivial -- but the questioner wasn't asking for anything "secure", just for some way to obfuscate plain-text strings enough to discourage amateurs.


Como usar o evento Keyup do Jquery para mostrar registros dentro de uma div vindos de um script PHP?

Question: Estou trabalhando em um projeto onde gostaria que quando fosse digitar algum valor dentro de um input, fosse mostrando os registros logo abaixo do mesmo. Abaixo segue a estrutura de código que tenho até então:
index.html

   Pesquisar
   <input type="search" id="pesquisar">

//Div que mostra os dados relativos a consulta feita através do script filter.php

Abaixo, o script php (filter.php) que consulta uma tabela chamada (produtos_tbl) no MySql:
Tabela produtos_tbl
prodID | nome   | preco
------------------------
001     | sapato  | 20.00
002     | calça   | 25.00
003     | Camisa  | 15.00

filter.php:
<?php

include 'mysqli_connection.php'; // Script para conexão com o banco de dados

$pesquisar = $_POST['pesquisar'];

$stmt = $db -> prepare('SELECT prodID, nome, preco FROM produtos_tbl WHERE nome LIKE '%$pesquisar%'');

$stmt -> execute();
$stmt -> store_result();
$stmt -> bind_result($prodID, $nome, $preco);

while ($stmt -> fetch()) {

echo '

'.$nome.'

R$ '.$preco.'

Produto ID '.$prodID.'

    ';

}

?>

Baseando-se no script php acima, quando tento digitar alguma coisa dentro do input localizado na página index.html, ocorre o seguinte erro:
Warning: A non-numeric value encountered in filter.php on line 26

------------

Fatal error: Uncaught DivisionByZeroError: Modulo by zero in /filter.php:26 Stack trace: #0 {main} thrown in /filter.php on line 26

O que poderia ser e como posso melhorar o meu código acima para que me retorne os valores corretamente dentro da div?
Comment: Mais uma coisa. A query está usando aspas simples. Nesse caso o PHP vai simplesmente ignorar suas variáveis e usar como se fossem strings.

Além disso, o bind está errado. Você não está definindo as localizações para os binds.

https://www.w3schools.com/php/php_mysql_prepared_statements.asp
Comment: o autocomplete do jquery não resolveria isso? https://pt.stackoverflow.com/questions/428997/php-jquery-autocomplete-din%c3%a2mico
Comment: Não parece ter nada errado na linha 26, mas percebi que existe uma aspa a mais no fim da query:  '%$pesquisar%' '. Você deveria escapa-la, assim:

... WHERE nome LIKE \'%$pesquisar%\';
Comment: Vou tentar adaptar o Jquery Autocomplete em uma outra página de busca. Também encontrei o Bootstrap 3 - Typeahead, porém parece que esta descontinuado para novas versões do bootstrap.
Comment: Obrigado pelo feedback pessoal. O problema estava na concatenação da variável dentro da query conforme mencionado pelo Franklin Barreto. O correto é: "%'.$pesquisar.'%".
Answer: Você está com problema de concatenação. Troque o script
$stmt = $db -> prepare('SELECT prodID, nome, preco FROM produtos_tbl WHERE nome LIKE '%$pesquisar%'');

por
$stmt = $db -> prepare('SELECT prodID, nome, preco FROM produtos_tbl WHERE nome LIKE "%'.$pesquisar.'%"');

Comment: Obrigado Franklin. O problema era mesmo. Valeu!


O que significa esse ponto "." em Python?

Question: O que significa esse ponto entre a variável var e index?
Exemplo:
 var = ['João','Pedro','André','Alice']
 var.index('André')

Tem algum nome?
Answer: É o dot operator ou operador de ponto. Ele é o operador que dá acesso a membros do objeto contido na variável. Esses membros podem ser variáveis ou métodos do objeto.
Então nesse caso var é um objeto de lista. Uma lista possui alguns métodos, um deles é o index(). Então você está acessando o método index() contido na classe de lista e ele será aplicado ao objeto contido em var.
Se já viu como se cria um método na classe sabe que o primeiro parâmetro dele deve ser o self que é o parâmetro que receberá este objeto que está antes do ponto.
var.index('André')

é o equivalente a se escrever uma função assim:
index(var, 'André')

Coloquei no GitHub para referência futura.
Comment: Entendi! Isso é valido pra funções também caso eu queira acessar uma var, ou são casos diferentes?
Comment: Isso é válido para métodos apenas.


VB.net System.Data.OleDb.OleDbException: 'Syntax error (missing operator)

Question: I am using Access 2013 as database in Visual studio 2017. The database is connected and all but when i run this code:
myConnToAccess = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database11.accdb")
    myConnToAccess.Open()
    ds = New DataSet
    tables = ds.Tables
    da = New OleDbDataAdapter("SELECT Typ záznamu from Typ", myConnToAccess)
    da.Fill(ds, "Typ")
    Dim view1 As New DataView(tables(0))
    With ComboBox1
        .DataSource = ds.Tables("Typ")
        .DisplayMember = "Typ záznamu"
        .ValueMember = "Typ záznamu"
        .SelectedIndex = 0
        .AutoCompleteMode = AutoCompleteMode.SuggestAppend
        .AutoCompleteSource = AutoCompleteSource.ListItems
    End With

I get the **System.Data.OleDb.OleDbException: 'Syntax error (missing operator) in query expression 'Typ záznamu'.'
**
I have the
Dim mySQLCommand As OleDbCommand
Dim mySQLStrg As String
Dim ds As DataSet
Dim da As OleDbDataAdapter
Dim tables As DataTableCollection
Dim myConnToAccess As OleDbConnection

in the begining of the class... also the:
Imports System.Data.OleDb

I dont know what to d any more... can someone please help me?
Comment: Is "Typ záznamu" a column-name?
Comment: Simply put your sql syntax is incorrect. What are you trying to do with the "Typ záznamu"? What is the column name you are trying to read?
Comment: yes the "Typ záznamu" is a column name... i had made it work...

this line:

da = New OleDbDataAdapter("SELECT Typ záznamu from Typ", myConnToAccess)

Should look like this:

da = New OleDbDataAdapter("SELECT [Typ záznamu] from Typ", myConnToAccess)
Answer: If you want to query the column Typ záznamu then you need to put it in square brackets because of the space between the words.
da = New OleDbDataAdapter("SELECT [Typ záznamu] from Typ", myConnToAccess)

Comment: yes made it work just a couple of seconds after posting the question but thank you very much
Comment: Please create a new question for this with the required details and your last attempt. Also mark the answer you think is the best by clicking the check mark next to the answer.
Comment: another question for you. If i have a If statement to find out if the Combobox selected value is a specific string how can i do it if the combobox is filled from database?
Answer: I had made it work:
this line:
da = New OleDbDataAdapter("SELECT Typ záznamu from Typ", myConnToAccess)

needs to look like this:
 da = New OleDbDataAdapter("SELECT [Typ záznamu] from Typ", myConnToAccess)

The only difereance is in the column name. it needs to be in squere breaces or how do you call it [ ]


Proof verification - Minimal polynomial of $\alpha$ has integer coef.s iff its an alg. integer

Question: I want to prove the following theorem:
Theorem. The minimal polynomial of $\alpha$ has integer coefficients if and only if $\alpha$ is an algebraic integer.
Here is what I have done and I want to ask whether it has any problematic parts or not:
($\implies$) part is trivial. For the converse, let $q(X) \in \mathbb{Q}[X]$ be the minimal polynomial of $\alpha$ and $f(X) \in \mathbb{Z}[X]$ such that $f(\alpha)=0$. Then, since $q(X)$ is the minimal polynomial of $\alpha$, $f(X)=q(X)r(X)$ for some $r(X) \in \mathbb{Q}[X]$.
Assume that $q$ has at least one non-integer coefficient. Define
$ V = lcm\{$denominators of coefficients of $q(X) \}$.
$ U = lcm\{$denominators of coefficients of $r(X) \}$. Then,
$UVf(X) \equiv 0$ modulo ($UV$) but $Vq(X)Ur(X) \equiv UVq(X)r(X) \not \equiv 0$ . So, I think we are done.
Comment: But for every algebraic number $\alpha$ there's a polynomial $f(X)\in\mathbb{Z}[X]$ such that $f(\alpha)=0$. It just need not be monic.
Comment: Where does your proof use the fact that $\alpha$ is an algebraic integer?
Comment: While I am saying that $f \in \mathbb{Z}[X]$.
Comment: The notes I follow defines it a number satisfying a monic polynomial with integer coefficients and I am taking it as $f$.
Comment: I agree that $Vq(X) $ and $Ur(X) $ are non-zero modulo $UV$. But how can we argue that the product $Vq(X)Ur(X) $ is also non-zero modulo $UV$? The problem is that $\mathbb Z_{(UV)}[X]$ is not necessarily an integral domain, so there may exist non-trivial zero-divisors in $\mathbb Z_{(UV)}[X]$. Have you considered picking a prime $p | UV$, and reducing modulo $p$? This would help, because $\mathbb Z_p[X]$ **is** an integral domain.
Comment: @KennyWong I could not find out how to prove it that way, yet.
Comment: @Ninja Okay, I've provided some clarifications below.
Comment: I'm a little confused, normally the definition of an algebraic integer is that $m_\alpha(x)\in\Bbb Z[x]$, what definition are you working with?
Comment: The definition that I am using is that $\alpha$ is a root of some monic polynomial in $\mathbb{Z}[X]$. It only says that it is monic. After that, there is a proposition which says that "$\alpha$ is an algebraic integer $\iff m_\alpha(X) \in \mathbb{Z}[X]$. So it does not says that the minimal polynomial of it has integer coefficients but it satisfies a monic polynomial with integer coefficients.
Answer: Essentially, the lemma we need to prove is:

Suppose $f(X) \in \mathbb Z[X]$ is a monic polynomial, and suppose $f(X) =q(X)r(X)$, where $q(X)$ and $r(X)$ are monic polynomials in $\mathbb Q[X]$. Then $q(X)$ is in $\mathbb Z[X]$.

I'll try my best  to guide you through a proof that incorporates as many of your ideas as possible.

Define $V$ and $U$ to be the smallest positive integers such that $Vq(X) \in \mathbb Z[X]$ and $Ur(X) \in \mathbb Z[X]$. I invite you to check that the greatest common divisor of the coefficients of $Vq(X)$ is one. The same is true of the coefficients of $Ur(X)$. While checking this, it is important to think about why we need $q(X)$ and $r(X)$ to be monic.
Suppose, for contradiction, that $V > 1$. Then there exists a prime number $p$ that divides $V$. Consider the equation
$$ (Vq(X))(Ur(X)) = UVf(X)$$
as an equation in $\mathbb Z_p[X]$. I encourage you to show that $UVf(X)$ is zero in $\mathbb Z_p[X]$, and that $Vq(X)$ and $Ur(X)$ are non-zero in $\mathbb Z_p[X]$.
Finally, you can think about how this contradicts the fact that $\mathbb Z_p[X]$ is a integral domain, and hence, conclude that $V = 1$.

So the idea of this argument is very similar to your argument, except that we are working in $\mathbb Z_p[X]$ rather than $\mathbb Z_{(UV)}[X]$. The latter is not necessarily  an integral domain, and that is the important difference.
Answer: I assume the definition you have of algebraic integer is "a root of a monic polynomial with integer coefficients".
Your attempt at a proof is invalid: there is no justification of the main step. Moreover "modulo $UV$" means you are working in a ring with zero divisors.
Thus one direction is obvious. For the other one, let $f(X)$ be the (monic) minimal polynomial of the algebraic integer $\alpha$ and let $g(X)$ be a monic polynomial with integer coefficients such that $g(\alpha)=0$.
Then $g(X)=f(X)q(X)$ for some $q(X)\in\mathbb{Q}[X]$.
We can write
$$
g(X)=\frac{a}{b}f_1(X)\cdot\frac{c}{d}q_1(X)
$$
where $f_1$ and $q_1$ have integer coefficients and greatest common divisor of the coefficients equal to $1$ (that is, they are primitive). It's not restrictive to assume the leading coefficient of $f_1(X)$ is positive.
Therefore
$$
bdg(X)=acf_1(X)q_1(X)
$$
Since $f(X)$ is irreducible in $\mathbb{Q}[X]$ and $f_1$ is primitive, also $f_1(X)$ is irreducible in $\mathbb{Z}[X]$ (Gauss' lemma). Due to $\mathbb{Z}[X]$ being a UFD, $f_1(X)$ is prime and so it divides $g(X)$ in $\mathbb{Z}[X]$, because it divides neither $b$ nor $d$.
Hence $g(X)=f_1(X)q_2(X)$ in $\mathbb{Z}[X]$ and, comparing the leading coefficients, we conclude the leading coefficient of $f_1$ is $1$. Therefore $f_1(X)=f(X)$, because $f_1(\alpha)=0$.
Comment: Can you explain how did you write $$
g(X)=\frac{a}{b}f_1(X)\cdot\frac{c}{d}q_1(X)
$$?
Comment: @Ninja First let $b$ be the least common multiple of the coefficients in $f$; express each coefficient as having $b$ as denominator, then take $a$ as lhe least common multiple of the numerators. Do similarly with $q$.


comparing elements of the same array in java using single for loop

Question: comparing elements of the same array in java using single for loop
<code>   a=[1,2,3,4,5,6]
for(int i=0;i<n;i++){
   if(a[i]=a[i+1])
      { // some stuff}
</code>
Array out of bound exception occur how to resolve this
Comment: Your code doesn't even compile. Please [edit] and make it a [mcve].
Comment: Please provide enough code so others can better understand or reproduce the problem.
Comment: Does this answer your question? [My Java code is giving me an out of bounds error](https://stackoverflow.com/questions/52709381/my-java-code-is-giving-me-an-out-of-bounds-error)
Answer: There are a few issues with the code above. Hopefully this will get you on the right track.
<code>// Indentation makes code more readable.
public void test ()
{
    // Need to declare the type of variable a.
    // Need to use braces for data definition.
    int[] a = {1, 2, 3, 4, 5, 6};

    // Iteration stops at the second to last element
    for (int i = 0; i < a.length - 1; i++)
    {
        // Use == for comparison. The = is for assignment.
        if (a[i] == a[i + 1])
        {
            // some stuff}
        }
    }
}
</code>


Check: Let G be a group and H be a subgroup of G. Define R by $xRy \iff xy^{-1} \in H$. Show R is an equivalence relation.

Question: Let G be a group and H be a subgroup of G. Define R by $xRy \iff xy^{-1} \in H$. Show R is an equivalence relation.
$\textbf{Definition:}$ R is a relation on X. R is an equivalence relation of X if R satifies the following for $\forall x,y,z \in X$:

xRx (relexive)
If xRy, then yRx (symmetric)
If xRy and yRz, then xRz (transitive)

$\textbf{Proof:}$

Reflexive
$$xRx \iff xx^{-1}=1$$
Since $1 \in H$. Hence R is relexive.
Symmetric
$$xRy \iff xy^{-1} \iff (x^{-1}y)^{-1}$$

So $x^{-1}y \in H$ so does it's inverse. Hence R is symmetric.

Transitive
Let $x=(a,b),y=(c,d),z=(e,f) \in A$. Assume the following:

\begin{equation*}
\begin{aligned}
xRy & \iff xy^{-1} \\
yRz & \iff yz^{-1} \\
\end{aligned}
\end{equation*}
Using this facts, if we multiply xRy and yRz, we have $xz^{-1} \in H$. Hence xRz.Thus R is transitive.
Since all the properties are satified, R is an equivalence class.
Comment: No. For instance, $x\mathrel{R}x$ if and only if $xx^{-1}\in H$. The fact that $xx^{-1}=1$ is true by definition. Similar quirks are also in the other arguments.
Comment: $xRy\iff xy^{-1}\iff (x^{-1}y)^{-1}$ is nonsense. You mean $xy^{-1}\in H,\dots$.
Comment: San with transitive. You can only write "$P\iff Q$" when $P$ and $Q$ are statements. $xy^{-1}$ is not a statement, it is an expression. $xy^{-1}\in H$ is a statement.
Comment: Note that (generally) $(ab)^{-1} = b^{-1}a^{-1} \neq a^{-1}b^{-1}$
Comment: Yes, if $G$ is non commutative, it is not true that $xy^{-1}= (x^{-1}y)^{-1}$.
Answer: The ideas are good, but badly exposed.
Reflexivity Let $x\in G$; we want to show that $x\mathrel{R}x$, that is, $xx^{-1}\in H$. This is true, because $xx^{-1}=1\in H$.
Simmetry Let $x,y\in G$ and suppose $x\mathrel{R}y$. We want to show that $y\mathrel{R}x$, that is, $yx^{-1}\in H$. By hypothesis, $xy^{-1}\in H$, so, by the properties of a subgroup, $(xy^{-1})^{-1}\in H$; but, by general rule, $(xy^{-1})^{-1}=yx^{-1}$, so we are done.
Transitivity Let $x,y,z\in G$ and suppose $x\mathrel{R}y$ and $y\mathrel{R}z$. We want to show that $x\mathrel{R}z$, that is $xz^{-1}\in H$. We know that $xy^{-1}\in H$ and $yz^{-1}\in H$, so $(xy^{-1})(yz^{-1})\in H$. But $(xy^{-1})(yz^{-1})=xz^{-1}$, so we are done.
Comment: Thank you that what I was worried about
Comment: @UsernameUnknown I find it more useful and instructing to write proofs verbosely, not as a sequence of symbols. As others commented, be careful that $(xy)^{-1}=y^{-1}x^{-1}$, not $x^{-1}y^{-1}$.


Reduced performance in mysql after upgrade to 5.6.27

Question: Our application was using MySql version 4.0.24 for a long time. We are trying to migrate it to version 5.6.27.
But, on testing the performance on 5.6.27, even the simple selects and updates are 30-40% slower when we are doing load testing. The CPU and IO speeds are much better than the older server. The storage engine of the tables is MyIsam in both versions. There's only one connection to the database. We tried the following options:

Changing storage engine to InnoDb - this reduce the performance drastically (70% slower)
Changing the innodb log size and buffer size - didn't help much
Increasing key buffer size with MyIsam storage engine for tables. - It made no difference

We tried modifying other parameters like query cache, tmp_table_size, heap_table_size. But, none of them made any difference.
Can you please let me know if there's any other option that we can try?
Here's a copy of my.cnf:
lower-case-table-names=1
myisam-recover=FORCE
key_buffer_size=2000M

Comment: You will probably get better answers from ServerFault ...
Comment: Please show us a copy of my.cnf. In a Linux server, it can typically be found at /etc/my.cnf
Comment: is this all my.cnf ? usually same server with same my.cnf and different versions of mysql behave the same way
Comment: "Simple selects and updates" -- are you timing them individually?  Or as a batch of queries?
Comment: InnoDB is probably slower only because of not adequately tuning the variables.  Try again with innodb_buffer_pool_size at 70% of available ram and innodb_flush_log_at_trx_comment set to 2.
Answer: Some things you can look at are whether the two servers have the same amount of RAM or not as it may be that the old server has more RAM and so can cache more things in memory.
You can also look at how are you connecting to the MySQL server - is it over a network?  Is that network speed / quality different?  Is one server accessed locally and the other over a network.
You tried tuning some good parameters, but in case there are ones you're missing, you can run mysql -e 'show variables' on both servers and then use a tool like Winmerge to compare the values of the two and see what might be different that you might not have thought of.
Comment: 5.6 has soooo many more `VARIABLES` that the Winmerge will be hard to read.
Comment: Given what the OP has already tried, I feel like it may be worth it at this point.
Answer: After trying multiple options, here are the configurations that worked for us. There may be other solutions as well but this worked for us.
Option 1:

Turned off the performance schema
Added a  couple of jdbc connection parameters: useConfigs=maxPerformance&maintainTimeStats=false

Option 2:
Migrate to MariaDB. From a performance perspective, this worked out really well. It was giving a 5%  better performance compared to mysql for our system. But, we couldn't pursue this option due to non-technical reasons.
Thank you for your inputs.


Using DIC for model selection: (in)valid comparisons

Question: Imagine I have the following 7 glmm models where $b_1$ through $b_3$ are fixed effects.
$M_1 = y \sim b_1 \times b_2 \times b_3$
$M_2 = y \sim b_2 \times b_3$
$M_3 = y \sim b_1 \times b_3$
$M_4 = y \sim b_1 \times b_2$
$M_5 = y \sim b_3$
$M_6 = y \sim b_2$
$M_7 = y \sim b_1$
DIC can be used to asses the relative fit of models. However, I would like to know what comparisons would be valid to make because I am unsure and struggling to know what route to take. Imagine the following scenario, where the DIC for each model is shown in red.

I am not sure what would and would not be valid comparisons/correct interpretations of using DIC compare the models. Would it be valid to compare, for example, the following:
A) $M_1$ with $M_2$ - I think this is a valid comparison, and shows whether dropping the parameter $b_1$ improves the fit of the model. If $\Delta$ DIC > 2 then model fit is improved by dropping the term.
B) $M_1$ with $M_5$ - I suspect that this is not a valid comparison. It tests whether dropping two parameters at the same time improves model fit. I think I should first try dropping both $b_1$ and $b_2$ individually, then proceeding to testing $M_2$ and $M_3$ against $M_5$, retaining the most complex model where dropping terms does not improve fit.
C) $M_5$ with $M_6$ - I suspect that this is not a valid comparison. It shows the effect of substituting the parameters, which may mean different data is included.
Essentially it boils down to this. Can one only use DIC to compare models with sequentially dropped effects, or can I drop multiple effects simultaneously and/or compare models with different fixed effects?
Then how would I draw conclusions from this? Would it be best to present the model $M_1$ as the best fitting model, because it is the most complex model of all of my models where $\Delta$ DIC is <2 when dropping parameter $b_3$... or, that models $M_5$ and $M_6$ (and $M_1$) are the best fitting models when using parameters $b_3$, $b_2$, (and $b_1$) respectively.
Answer: You can use DIC to compare any of the models to each other without considerations to nesting of effects as long as at least one of the below holds

The random effects structure is the same for all models
If the random effects structure is different then all models are fit using maximum likelihood

As far as the delta_DIC < 2 policy, I know burnham and Anderson suggested a deltaAIC cut-off < 2... but I am unsure how this will translate to DIC. But otherwise, IMHO you can just choose the best fitting model from all models
Comment: so then I could look at all of my models, and just pick the one with the lowest DIC as being the best fit - in my example it would be model $m_5$
Comment: yes that is correct. That is the goal of using an IC based model selection strategy is that non-nested models can be compared. When you use an likelihood Ratio approach you can only compare nested models
Comment: and so I don't need to work from most complex (m1) -> least complex (e.g. m5) models and take the most complex model where DIC isn't substantially reduced?
Comment: The point of the model selection is that you will have to ensure that you have explored the entire set of model space. In your example it is simple, but if you add a few more variables the # of models to fit increase substantially. You don't have to fit models in any particular order, just have to fit all possible models :) and then compare with your favorite IC criteria


Infinitely many primes not congruent to 1 mod n

Question: Given an integer $n>2$, prove that there are infinitely many primes $p$ such that $p\not\equiv1\text{ mod }n$.
I read about the question here when $n=5$, where they used that $n$ itself is a prime. However, how should I prove it for any natural $n$? I got the hint "consider the polynomial $nx-1$" and tried to prove by contradiction, buy I couldn't go any further.
Thank you!
Comment: It's the special case of the generalization of Euclid's proof in the linked dupe, where $\,S = 1 + n\Bbb Z,\ c(k) = nk-1\ \ $
Answer: Assume that there were only finitely many primes not congruent to 1 modulo $n.$ Consider $nx - 1$ for $x$ a positive integer. If $p \mid x$ is a prime factor of $x,$ then obviously it cannot be a prime factor of $nx-1,$ since $p \mid nx$ but $p \nmid -1.$ But now you're done, for $nx - 1$ has to have at least one factor not congruent to 1 modulo $n$ (if all of its factors were $1$ modulo $n,$ then $nx-1$ would be congruent to $+1$ modulo $n,$ which is impossible unless $n=2,$ and you can show there are infinitely many odd primes on your own).
Thus if $p_1, ..., p_k$ are the finitely many primes not congruent to 1 mod $n$, take $x = p_1\cdots p_k$ to get a contradiction.
Comment: This seems convoluted in phrasing. Is the last line supposed to be " are the finitely many not congruent to 1 mod n primes"? (If so, I believe you have a correct approach.)
Comment: @CalvinLin You're right, I changed it.


União entre vetores em C

Question: Estou com uma duvida nesse código pois a função deveria imprimir {1,2,3} porém imprimi {1,2,3,4,10,24,73}
void uniao(int A[], int B[], int C[]){
int i;

for(i = 0; i < TAMANHO ; i++){
    if (A[i] == 1){
        C[i] = A[i];
    }
    if (B[i] == 1){
        C[i] = B[i];
    }
}

}
A função imprimir que usei foi:
void imprimir( int vet[], int tam) {
int i;

for (i = 0 ; i < tam ; i++){
    if( vet[i] == 1){
        printf("Conjuntos: %d \n",i );
    }

}

}
main do cod:
int A[TAMANHO] = {0,0,1,1};
int B[TAMANHO] = {0,1,1,1};
int C[TAMANHO];

uniao(A,B,C);
imprimir(C,TAMANHO);

Comment: Aqui: http://ideone.com/NwHEA4 funcionou corretamente.
Comment: ei, realmente funciona adicionando o tamanho como 4, mas eu preciso adicionar o tamanho como 200. E quando faço isso continua imprimindo os numeros 10,24 e 73.
Comment: Mas quando você informa tamanho 200 você informa os 200 valores de cada um dos vetores?
Comment: não, esse tamanho é apenas o que é pedido no enunciado da questão (que eu nao entendi muito bem, por isso estou cheio de duvidas). No caso as funções tem que ser bem genéricas pois serão testadas em outros programas.
Comment: Neste caso é melhor colocar o tamanho dos vetores como parâmetro também na função uniao.
Comment: Agora uma observação: pelo que entendo de união sua função não faz a união dos vetores.
Comment: Acho que ta tudo muito confuso, principalmente no meu entendimento deste trabalho (algumas funções estou usando as ja fornecidas pelo professor). Mas obrigaso por tentar me ajudar ;)
Comment: quando voc e muda o tamanho pra 200, como você inicializa os vetores A e B?
é melhor voce coloar o código todo aí, em vez de pedacinhos que não podem ser executados por quem está vendo a pergunta.
Answer: O problema é que o vetor C não está sendo inicializado. Isso quer dizer que da maneira que está implementado ele está recebendo valores "aleatórios" da memória e para resolver isso você precisa primeiro inicializá-lo.
Existem diversas maneiras de se inicializar um vetor, mas para este exemplo eu vou mostrar a mais explícita, com um laço:
int C[TAMANHO];

for (int i = 0; i < TAMANHO; i++) {
    C[i] = 0;
}

Dessa forma o resultado vai ser sempre determinado e seu exemplo vai ser executado conforme esperado.
Comment: Obrigado por me ajudar, mas ue consegui resolver os problemas deste código, agradeço :)

União entre vetores em C


Is there any way to use loop to change variable's strings from lowercase to uppercase?

Question: (Sorry for my bad English)
I'm new to JS and continuously doing some weird stuff to learn how JS works!
I'm currently wanting to change the array strings from lower case to uppercase and to do that, I'm doing something like this:
        let names = ['Shakir', 'smith', 'Anderson', 'Kyle', 'Ketty', 'jason'];

for (var i=0; i<names.length; i++){

    // This also doesn't work, i'm not using let (or any other variable keyword because names has already been defined: names[i] = to.UpperCase(names[i]);

// Neither does this: let names[i] = to.UpperCase(names[i]);

}

Can anyone tell me where I'm mistaking?
Once again, this is my array:
let names = ['Shakir', 'smith', 'Anderson', 'Kyle', 'Ketty', 'jason'];

And I want to convert all the strings inside it from lower cases to uppercase like:
 let names = ['SHAKIR', 'SMITH', etc..]

Is this possible?
Answer: You can assign to the array entry in your loop:
for (var i=0; i<names.length; i++){
    names[i] = names[i].toUpperCase();
}

Also be sure to get the method name right, I've corrected it above. And it's a method of the string, so you call it on the string rather than passing the string into it as an argument.
Another option is to create a new array with the modified entries in it, perhaps assigning it back to the same variable:
names = names.map(name => name.toUpperCase());

Comment: It worked, thank you! I was doing toUpperCase.names instead of the opposite! Also, why we cant do "let names [i]" in the loop? I thought doing "let names [i]" would be much safer than to simply doing names[i]
Comment: @prettyversatile - `let` declares variables. Variables can't have `[` or `]` in their names. You could do `let newName = names[i].toUpperCase();`, but all that would do is store the upper-case name in a variable that will disappear at the end of that loop iteration (because I used `let` in the example; that's also true for `const`, but not `var`).
Answer: The method is .toUpperCase() and you need to add the string before it (see docs: https://www.w3schools.com/JSREF/jsref_touppercase.asp)
So in your example, you would need to do:
let names = ['Shakir', 'smith', 'Anderson', 'Kyle', 'Ketty', 'jason']

for (var i = 0; i < names.length; i++) {
  names[i] = names[i].toUpperCase()
}

Comment: Yes. I just realized that - Thank you!
Comment: Also, why we cant do "let names [i]" in the loop? I thought doing "let names [i]" would be much safer than to simply doing names[i]
Comment: You've already declared the variable 'names' as an array.

You can't redeclare a let within the same scope.

In the loop, you're simply overwriting the value in the 'names' array with the uppercase text by using the i variable as the index.
 You can read more here on the let variable here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let


Cannot open database "our database" requested by the login. The login failed. Login failed for user 'ADUser'

Question: We are rolling out our first .net 4.0 entity framework application and are having an issue with security.
We have it working on our alpha site inside our development environment with the following setup:

SQL2005
IIS6
.NET 4.0
asp.net mvc 2
Entity Framework
NTLM

But when we moved it to our production environment for beta testing we are getting the following error via asp.net

SqlException (0x80131904): Cannot open
  database "our database name"
  requested by the login. The login
  failed. Login failed for user
  'Domain\User'.

The only difference between the between the 2 environments is we are using Kerberos instead of NTLM in our production environment. We have several other .net 3.5 sites using LinqToSql that run on both environments.
We have already done the following:

Replaced an active user on another test site with the user that is failing to make sure it isn't an issue with the way the user is set up. - worked
Dropped and re-added the user from sql2005 - did nothing

The issue appears to be related to .net 4.0 as this is our first...
Answer: Based on the error message, 2 questions:

Does the login have access to the database in your production site?
Does the database that you specified in the connection string on the SQL server that is specified in the connection string?

These are the 2 most common causes of that issue.  A Kerberos issue usually manifests itself in SQL Server a little differently.
Thanks,
Eric
Comment: Yes, via role=>schema.
If you second question reads: "Does the database exist on the sql server...", yes
Answer: The difference between NTLM and Kerberos is huge. With NTLM, you can use pass-through authentication with Kerberos you cannot. With Kerberos and Windows Authentication, you need to setup a Service Principal Name (SPN for short) that tells SQL Server that it can be accessed by whatever IIS account you use.
Understanding Kerberos and NTLM authentication in SQL Server Connections
Here's another article on setting up Kerberos. Jump down to the section titled "Configure a service principal name for the domain user account"
Comment: But we have several other sites that use sql 2005 and the others settings (NTLM and Kerborose). The only difference is that fact that this is our first .net 4.0 site
Comment: @J.13.L - Whether you are using Kerberos makes a significant difference. However, I would first ensure that the connection string is correct. Is the protocol being used enabled? Is the server name correct and is the server able to resolve the name correctly? Is the database name correct? Does the user account being used have access to the database? etc.
Comment: I have verified all these things. We have it working in our Development environment. So the only thing that changes is the connection string and we have verified that several times.
Comment: Does 3.5 cause security to fallback to ntlm where as 4.0 would not?
Comment: Thanks for you help, after doing some research on service principal name we were able to get it running...


Matlab left - division in vectors?

Question:

x=[1;2;3]

x =
 1
 2
 3

y=[4;5;6]

y =
 4
 5
 6

x\y

ans =
2.2857

How did Matlab find that result ? (I searched many forums but I did not understand what they told.I would like to know the algorithm which gave this result.)
Answer: From MATLAB documentation of \:
If A is an M-by-N matrix with M < or > N and B is a column vector with M components, or a matrix with several such columns, then X = A\B is the solution in the least squares sense to the under- or overdetermined system of equations A*X = B.
Here your system is not under/over-determined. Since both have 3 rows. So you can visualize your equation as:
xM=y
M=inv(x)*y

Now, since your matrix is not square, it will calculate the pseudo-inverse using SVD. Therefore,
M=pinv(x)*y;

You will get value of M as 2.2857.
Another explanation can be: It will give you the solution of xM=y in the sense of least squares. You can verify this as follows:
M=lsqr(x,y)

This will give you the value of M = 2.2857.
You can always do help \ in MATLAB command window to get more information.
You are encouraged to check more details about the least squares and pseudo-inverse.
Answer: This documentation should explain it
http://www.mathworks.com/help/matlab/ref/mrdivide.html
Here is a link to the algorithm
http://www.maths.lth.se/na/courses/NUM115/NUM115-11/backslash.html
You can see the source inside matlab much more easily though. (I don't have it locally so I can't check but the source of a lot of matlab functions is available inside matlab)

Matlab left - division in vectors?


Weird Socket.IO behavior: events "on connection" and "on disconnect" happen almost at the same type

Question: On the socket io server I have something like:
io.sockets.on('connection',function(client) {
    console.log(client.id + ' connected at '+(new Date()).getTime());
    client.on('disconnect',function() {
        console.log(client.id + ' DISCONNECTED at '+(new Date()).getTime());
    });
});

And my problem is that this happens:
   debug - client authorized
   info  - handshake authorized 15229479751557595508
   debug - setting request GET /socket.io/1/websocket/15229479751557595508
   debug - set heartbeat interval for client 15229479751557595508
   debug - client authorized for
   debug - websocket writing 1::
15229479751557595508 connected at 1313769716321
   debug - websocket received data packet 5:::{"name":"estimatepp","args":[9]}
   debug - websocket received data packet 5:::{"name":"ready","args":[null]}
   info  - transport end
   debug - set close timeout for client 15229479751557595508
   debug - cleared close timeout for client 15229479751557595508
   debug - cleared heartbeat interval for client 15229479751557595508
15229479751557595508 DISCONNECTED at 1313769716454
   debug - discarding transport

I don't know if this is normal but as you can see, the client 15229479751557595508 connects at 1313769716321 and disconnects at 1313769716454, just 133 mili-seconds later (this number is always either 132 or 133). I'm not ordering the client to disconnect after something.
Any ideas on why does this happen ?
Also I have another doubt. If I listen for connection events on io.sockets.on, shouldn't I be listening for disconnect events also there ? Except there's no client there...
What is the correct way to listen for disconnections ?
Thanks for any help.
EDIT: You can ignore the lines
debug - websocket received data packet 5:::{"name":"estimatepp","args":[9]}
debug - websocket received data packet 5:::{"name":"ready","args":[null]}

It's part of the project I'm working on. Maybe the thing is that it just receives those events and after that because there's no activity for a while it closes the connection ? But this is not wanted behavior is it ?
Answer: The server-side code that you have posted is fine and should work as expected. Check for bugs in your client-side code (or post your client-side code here). If nothing there, try a different browser.

Regarding your disconnect event.
You have an io.sockets.on("connection", function (client) { ... }) event handler where when a new connection is made, a session is created for the connection and is stored in the client variable.
You then attach event handlers (like the disconnect one) to this client object.
Now when that client disconnects, the disconnect event handler attached to that particular client object is invoked.
Moreover, as you can see in Exposed Events — Socket.io, io.sockets.on only exposes the connection event.
Answer: I have similar thoughts as the creator of the question.
The time in ms is probably your roundtrip time to the server or the time it takes to manage connects with the client etc etc. So I wouldnt bother so much with the time factor.
I get same result when I refresh the client manually and repeatedly. between say half and one second intervals. This seems to create a scenario which otherwise only happen with poor network quality.
I can see in the logs that I get a connection, before a disconnection with the same socket.id.
client connected:  qEcxQQCivSyKJVbF85dc
client disconnected: qEcxQQCivSyKJVbF85dc
However my on.disconnect event does in this scenario NOT fire.
On disconnects I clean up my local object of connected clients and I can see that I a client left in there and when I analyze the socket.connected status it is disconnected.
So under certain circumstances the above scenario causes a disconnect event to not fire.
Probably due to timings, asynch, network quality etc.
Two ways to go.

Build the application according to those constraints or
find someone who can come up with a more solid method for listening to on.disconnect, which, as the original question eluded, does not involve being attached to a specific socket client.

It is like the event listener is overwritten when the client connects again with the same id. A more general disconnect event listener would disregard that but potentially cause other issues instead.
I am personally going with option 1. and instead creating a garbage collector of sorts that clean up my local array of clients if they are disconnected.


Can we really assign random slopes to between-subject effects in a mixed effects model?

Question: This question is inspired by the comments to one of my answers on this forum: Should all adjustments be random effects in a mixed linear effect?.
In my answer, I stated something akin to the following:  In a mixed effects model, only within-subject predictor variables can be allowed to have varying (or random) effects across the levels of the corresponding random grouping factor.
The comment I received from @HeteroskedasticJim was that this is not really true, implying that even between-subject predictor variables can in fact have within-subject effects that can vary across subjects. (At least, that is my interpretation of this comment.)
My own response to this comment was as follows:
How can we compute the effect of gender within one subject when there is no variability in the values of gender within that subject? The effect of gender within one person would imply that when that person switches genders from male to female, say, there is a difference in the expected value of their response. The variability of the (within-subject) gender effects across subjects would imply that the difference would vary across subjects - so all those subjects would have to have a gender switch! Just trying to understand intuitively what is going on here.
Can someone on this forum provide a concrete example that can help me understand what this comment is trying to get at? I always thought that, to estimate a within-subject effect for a predictor variable, you need to have variability in the values of that predictor variable within that subject.  What glaring thing am I missing?
Comment: @CliffAB I thought about that too, and the reason random intercept would not apply is that it is typical to have one constant in the predictor matrix.
Comment: @HeteroskedasticJim - this is the promised question.  If it needs any edits before you answer it, just let me know.  Thank you in advance for taking the time to follow up on this!
Comment: Can you explain why random intercepts would not fit that criteria (i.e. constant within subject but still identifiable)? Or are you saying that something that is constant within subject is not identifiable given a random intercept? Just trying to clarify the question for my own sake.
Comment: I am just trying to understand why between-subject variables would be allowed to have random slopes - that's all!
Comment: (+1) This is a great question !
Answer: I will work with an example using the Verbal Aggression dataset, largely borrowing off this paper: https://www.jstatsoft.org/article/view/v039i12
library(lme4)
VA.dat <- VerbAgg[, c("Gender", "r2", "id")]
VA.dat <- VA.dat[order(VA.dat$id), ] # sort data by person id

I prepare the data to regress the binary response on gender and permit the gender effect to be different by person:
VA.dat$M <- (VA.dat$Gender == "M") + 0
VA.dat$F <- (VA.dat$Gender == "F") + 0
VA.dat$rbin <- (VA.dat$r2 == "Y") + 0

Look at data frame to confirm gender is person level:
table(aggregate(M ~ id, VA.dat, mean)$M)
#
#   0   1
# 243  73

The mean of the male indicator by person is either 1 or 0, so gender values are constant within id.
Regression:
summary(fit <- lmer(rbin ~ F + (0 + M + F || id), VA.dat))
# Random effects:
#  Groups   Name Variance Std.Dev.
#  id       M    0.04164  0.2041
#  id.1     F    0.04903  0.2214
#  Residual      0.20202  0.4495
# Number of obs: 7584, groups:  id, 316
#
# Fixed effects:
#             Estimate Std. Error t value
# (Intercept)  0.51370    0.02619  19.617
# F           -0.04885    0.03037  -1.609

I have an intercept representing Male and the Fem difference from it. Note the use of the || before id in the random effect specification. It stops the gender slopes from being correlated and forces a simpler interpretation of the random slopes. With a |, each id would have a value on both male and female slopes, which can be confusing to deal with.
On average, male responses are higher than female responses. However, the random intercept variance of female respondents is slightly larger than the random intercept variance of male respondents.
To look at the random slopes:
head(ranef(fit)$id)
#            M            F
# 1 -0.1153768  0.000000000
# 2 -0.3926609  0.000000000
# 3  0.0000000 -0.041122748
# 4  0.0000000  0.101123911
# 5  0.0000000 -0.041122748
# 6  0.0000000 -0.005561083

The first two persons are male and the gender effects for them are more negative than the overall gender effect, $0.514 - 0.115; 0.514 - 0.393$. The next four persons are female, and the gender effect for the first two are: $0.514 - 0.049 - 0.041; 0.514 - 0.049 + 0.101$.
So clearly, one does not need variability within the grouping factor to permit the effect of a variable to vary across persons. The reason for the confusion is older model formulations which separate the data in level 1 dataset and level 2 datasets. With lme4, and more recent model formulations, there is no need for such formulation. Douglas Bates covers details here: https://cran.r-project.org/web/packages/lme4/vignettes/Theory.pdf
Comment: @IsabellaGhement I wouldn't call it "random slopes" for F and M, you have two separate "random intercepts" for F and M. Put otherwise you just say that the random intercepts for F and M have different variances. And if you would allow the error variance to be different between F and M, this would correspond to a sub-group analysis fitting separate models for F and M.
Comment: Thank you for this beautiful answer, @HeteroskedasticJim!
Comment: @IsabellaGhement you're welcome.
Comment: @IsabellaGhement yes, it can be re-written that way. It's flexible that way.
Comment: There are other places on this forum where your answer would be helpful, like here: https://stats.stackexchange.com/questions/245960/between-subject-variable-in-mixed-effect-model.
Comment: Could the fixed effects portion of your model be re-written as 0 + F + M? I think that would make it easier to then understand that we're allowing the F and M variables to have random slopes.
Comment: (+1) great answer !
Comment: @HeteroskedasticJim Jim Sorry for bringing this back, but I came across it now as I was looking at the same issue. How do you know when to include between variables as random slopes? Would you always go for the maximal random structure as suggested by Barr and decide based on model comparison?
Comment: @CatM If for any reason, I thought some coefficient might vary by a grouping structure and the model wasn't too complex to fit, I'd try a random slope on just about any variable.
Comment: @HereroskedasticJim Thank you so much for your prompt response! I was also biased to think that between variables were not an option as a random slope because of reading the same sources as the original poster. This was quite an interesting thing to adjust to, thanks!


What are the number of ordered pairs $(x,y)$ where both $x$ and $y$ divide $20^{19}$, however $xy$ doesn't?

Question: What are the number of ordered pairs $(x,y)$ where both $x$ and $y$ divide $20^{19}$, however $xy$ doesn't?
I started by taking the prime factorization of $20^{19}$ to get : $2^{38}5^{19}$.
I then noticed, that the only way for $xy$ to not divide this number was if the powers of $x$ and $y$ add to greater than $38$ or $19$. For example, if $x=2^{38}$ and $y = 2^{2}$, then $xy$ would be $2^{40}$ which would not divide $2^{38}5^{19}$ evenly.
My question is, what would be the total number of ordered pairs?
Answer: There are $39^220^2$ pairs of divisors, with no restrictions.
There are $\binom{40}{2}\binom{21}{2}$ pairs of divisors such that the product is also a divisor.
This is because if $0\leq a_1< a_2\leq 39$ and $0\leq b_1<b_2\leq 20$ you get a pair of divisors $$d_1=2^{a_1}5^{b_1}, d_2=2^{a_2-a_1-1}5^{b_2-b_1-1},$$
and these are all such pairs.
So the pairs of divisors with the product not a divisor is the difference:
$$39^220^2-\binom{40}2\binom{21}{2}$$

More generally, let $\rho_k(n)$ be the number of $k$-tuples of natural numbers such $(d_1,\dots,d_k)$ such that $d_1d_2\cdots d_k\mid n.$
Then we see that $\rho_k$ is multiplicative - $\rho_k(mn)=\rho_k(m)\rho_k(n)$ if $\gcd(m,n)=1.$
Also, $\rho_k(p^a)=\binom{a+k}{k}.$
So if $n=p_1^{a_1}\cdots p_m^{a_m}$ then the number of $k$-tuples $(d_1,\dots,d_k)$ of divisors or $n$ whose product is not a divisor of $n$ is:
$$\tau(n)^k - \rho_k(n)=\prod_{i=1}^{m}(a_i+1)^k - \prod_{i=1}^{m}\binom{a_i+k}{k}.$$
Answer: Well, If $x = 2^a5^c$ and $y = 2^b5^d$
thenn we have $a+b > 38$ or $c+d > 19$.
To have $a+b > 38$ while $a \le 38$ and $b \le 38$ if we have $a = k$ then $b$ can be as small as $39-k$ and can be as large as $38$.  Those are $k$ options.  $(38+1) - (39-k) = k$.  So there are $\sum_{k=1}^{38}k = \frac {38*39}2 = 741$ such pairs.
And likes there are $\sum_{k=1}^{19} k = 190$ such possible pairs.
If $(a,b)$ is such a pairc $c,d$ can be anything from $0$ to $19$.  Thatn is $20^2 = 400$ options.
So there are $741*400$ pairs where $a+b > 38$.
Like wise there are $190*39^2$ pairs were $c + d > 19$.
But we counted all the pairs where $a+b > 38$ and $c+d >19$ twice!  So we must subtract that number of pairs.  There are $190*741$ so pairs.
So the total number of pairs where $a+b>38$ or $c+d > 19$ or both is
$741*400+190*39^2 - 190*741$.
Answer: You have made good progress.  Now let $x=2^a5^b, y=2^cy^d$.  This lets you work with the exponents.  Your observations can be expressed as you need $a,b \le 38, c,d \le 19$ and either $a+b \gt 38$ or $c+d \gt 19$ (or both).  Can you count the possibilities from that?


Need to flush cache after node translation

Question: I have a Drupal 6 site running with multi language support. When I translate a node and get redirected to the newly translated node only the headline is visible. If I flush the cache using the administration tools I can see the rest of the node.
Why is this happening and I how do I prevent it? I feel like I have tried everything!
For example trying:
  drupal_flush_all_caches();
  cache_clear_all();
  cache_clear_all('*', 'cache', TRUE);
  cache_clear_all('*', 'cache_content', TRUE);
  cache_clear_all('*', 'cache_page', TRUE);
  cache_clear_all('*', 'cache_menu', TRUE);
  cache_clear_all('*', 'cache_filter', TRUE);
  cache_clear_all('*', 'cache_views', TRUE);
  cache_clear_all('*', 'cache_views_data', TRUE);
  cache_clear_all('*', 'cache_update', TRUE);
  cache_clear_all('*', 'cache_block', TRUE);
  cache_clear_all('*', 'cache_form', TRUE);

Using function mymodule_node_form_submit($form, &$form_state) and function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL). I have verified that both hooks works using Devel.
I have also tried looking into the cache tables to try and figure out which rows change when flushing the caching using the administration tools, but without luck.
UPDATE JULY 18:
Even if I turn off the cache I cannot see the translated node before I flush the cache. How is this even possible?
UPDATE JULY 18 PT2: I think I have found the problem. In the table cache_content a row called e.g. content:1269:1270 got the value(data) a:0:{}. If I delete this row the text appears. To me it seems that it does not cache the new translation correctly, and thus saving an empty cache which makes the translated node empty. But how do I solve this? Even with db_query('DELETE FROM cache_content'); in the submit hook the row gets created.
Thanks in advance.
Comment: Are you positive your browser is not caching the page?
Comment: Yes. When translating a node and viewing it in another browser or computer the cache still needs to be flushed before the text shows up.
Comment: Note in regards to the first update: The cache setting *only* affects the complete page cache for anon users. Drupal will still cache a lot of things if that setting is disabled and would be unusable slow if it wouldn't.
Answer: Run the cache clear in a shutdown function. A little bit of a hack but it should work.
<?php
register_shutdown_function('cache_clear_all', 'content:' . $node->nid . ':', content_cache_tablename(), TRUE);
?>

Taken from content_delete()