How to implement user enrollment or subscription?

Question: I want to create a website with few courses in it. Each course will have a node of content type Course. I want users to be able to enter the course.
So this is sort of a "many-to-many" relationship question for Drupal, as for each subscription I will need to keep details on the progress, e.g. "last completed lesson", "total score", etc.
Is there a module that will have Enrollment/Subscription as a separate Entity/Content or Relation module will do it?
What is the best approach?
UPDATE 1:

This should allow to show all students subscribed to a course on a course page;
Show all current subscriptions with their details (fields) to student on my_courses page.

UPDATE 2: Can I use Open Group module for that?
Comment: I think http://drupal.org/project/entityreference will do what you're wanting.
Comment: @Cthos can I add fields to subscriptions via entity reference? It looks like Relation might be a more suitable solution...
Comment: Sure, you'd make a content type of "Progress" which would be owned by a user, which is then referenced by the course. You'd use views/blocks to show that information on a course dashboard page, and so on. Though, the Relation page itself says "While a similar module could be built based on Entityreference and Entity Construction Kit (ECK) by creating a custom entity and adding entity reference fields to it [...]" - That implies that both of the modules could do what you're proposing.
Comment: Sounds good, I will test both methods tomorrow. Thanks. I actually did not think of `author` as a reference field.
Comment: One other module that I did not consider yet, is OG. Can it be used for that? I think I will have to use it anyway for other purposes, so if OG Membership is configurable, it might do the trick.
Comment: I can't vouch for that as I've not used it before.
Answer: It seems that this can be done with Entity Registration module.
Answer: You could build it yourself, or why not go for a free ride? The OpenAcademy distribution looks like it is preconfigured with the kind of things that you would need.
Comment: I guess I will have a look at OpenAcademy's implementation, but this is sort of theoretical question on finding the optimal way to implement the subscription. Enrollment is just an example.
Comment: I had a look at openacademy's source, and it has all modules one can imagine. I could not figure out which module(s) they used to implement enrollment process.
Answer: You might want to give it a try to use the Group module, which allows for creating arbitrary collections of your content and users on your site, and grant access control permissions on those collections.
It is available as of D7, and has a D8 version also. It creates groups as entities, making them fully fieldable, extensible and exportable. Every group can have users, roles and permissions attached to it (refer to "What are the various roles supported by the Group module?" for more details about that).
Sample configuration
Below is an example of a possible configuration, which may help to get you started with possible configurations (using the Group module):
Group type ID ! Group type ! Group role ID ! Role
--------------+------------+---------------+------------
 1            ! Class      ! 3             ! Instructor
 1            ! Class      ! 4             ! Student
 2            ! Customers  ! 5             ! Lead
 2            ! Customers  ! 6             ! Prospect
 2            ! Customers  ! 7             ! Licensed Customer
 2            ! Customers  ! 8             ! Sales
 2            ! Customers  ! 9             ! Support
 2            ! Customers  ! 10            ! Accounting
 2            ! Customers  ! 11            ! R&D
 3            ! Project    ! 12            ! Project Manager
 3            ! Project    ! 13            ! Developer
 3            ! Project    ! 14            ! Customer

Group Types
The above example consists of 3 group types:

Class.
Customers.
Project.

Group Roles
For each of the 3 group types, there are specific Roles defined, some more details about some of them:

for the Class group, these are the 2 roles that are configured:

Instructor.
Student.

for the Project group, these are the 3 roles that are configured:

Project Manager.
Developer.
Customer.

These are the Group Specific Roles: these roles can be configured per group type and will only be available on groups of that group type. As an example, for group type "Class", the defined roles are Instructor and Student (which are not available for the other group types.
On top of the group specific roles, there are also Special Global Roles: These are the special (hardcoded) roles named Outsider (= a signed in user that did not join a group) and Member  (= a signed in user that did join a group). These cannot be defined by the Drupal administrator, and they are always available for any group. These roles can have different permissions sets for each group type. Special case: the role Anonymous is related to a user that is not signed.
Groups
Each of the configured group types can have any number of Groups.
Examples of groups:

for the Class group type, there could be these Groups:

Getting started with Drupal.
Drupal for site builders.
Become an expert in using the Rules module.

for the Customers group type, there could be these Groups:

Service Requests.
Order Processing.
Sales Orders.
Relationship Management.

Permissions
For each of the configured group types, you can then also configure for each Content Type which Role has what kind of access (= none, view, create, edit, delete). Be aware: even though this looks similar to Drupal's permission configuration, these permissions are not the same permissions (they are specific to the Group module).
Comparison with the Organic groups module
Have a look at my answer to "What are the features of the Group module versus Organic Group module?" for details about:

How both modules (Group versus Organic groups) compare to each other.
Integration with various modules that you might want to take advantage of also.

Resources

Community documentation for the Group module.
Video tutorial "How to use the Group module in Drupal 8 to manage editorial access control to different areas of a web site".

PS: this answer applies to either D7 or D8.


Solving a exponential floor flunction equation

Question: I am trying to solve this question but can't simplify this further.
Question:
$$ 2^{\lfloor log_2{(x)} + \frac{1}{2} \rfloor} = 2^{\lfloor log_2(x-2^{\lfloor{ log_2{(\frac{x}{2})} + \frac{1}{2}}\rfloor}) + \frac{1}{2}\rfloor}  + 2^{\lfloor log_2{(\frac{x}{2})+\frac{1}{2}}\rfloor}$$
My first step
$$
= 2^{\lfloor{log_2{(x - 2^{\lfloor{log_2{(x)} + \frac{1}{2}-1}\rfloor})} + \frac{1}{2} }\rfloor} + 2^{\lfloor{log_2{(x) + \frac{1}{2} - 1}}\rfloor} $$
as : $log_2(x) + \frac{1}{2} = \lfloor{log_2(x) + \frac{1}{2}}\rfloor + r $
Then I rewrite $\lfloor{log_2(x) + \frac{1}{2}}\rfloor = log_2(x) + \frac{1}{2} - r $
So : $ 2^{\lfloor{log_2{(x)} + \frac{1}{2}}\rfloor} = 2^{log_2{(x)} + \frac{1}{2} -r} = x \cdot 2^{v}$ where $v = \frac{1}{2} - r$
So that
$$ 2^{\lfloor log_2{(x)} + \frac{1}{2} \rfloor} =  2^{\lfloor{log_2{(x - x\cdot2^{v-1} )} + \frac{1}{2}}\rfloor} + x \cdot 2^{v-1} $$
$$ = 2^{\lfloor{log_2{(x(1 - 2^{v-1}) )} + \frac{1}{2}}\rfloor} + x \cdot 2^{v-1}$$
$$ = 2^{\lfloor{log_2{(x)}+ \frac{1}{2}  + log_2{(1-2^{v-1})} }\rfloor} + x \cdot 2^{v-1} $$
I'm stuck here. Can anyone help?
Answer: ${first}... \\ $
$\mathrm{2}^{\left[\left(\mathrm{log}_{\mathrm{2}} {x}\right)+\frac{\mathrm{1}}{\mathrm{2}}\right]} =\mathrm{2}.\mathrm{2}^{\left[\left(\mathrm{log}_{\mathrm{2}} \frac{{x}}{\mathrm{2}}\right)+\frac{\mathrm{1}}{\mathrm{2}}\right]}  \\ $
$. \\ $
${so}... \\ $
$. \\ $
$\mathrm{2}^{\left[\left(\mathrm{log}_{\mathrm{2}} {x}\right)+\frac{\mathrm{1}}{\mathrm{2}}\right]} −\mathrm{2}^{\left[\left(\mathrm{log}_{\mathrm{2}} \frac{{x}}{\mathrm{2}}\right)+\frac{\mathrm{1}}{\mathrm{2}}\right]}  \\ $
$. \\ $
${then}... \\ $
$. \\ $
${k}=\mathrm{2}^{\left[\left(\mathrm{log}_{\mathrm{2}} \frac{{x}}{\mathrm{2}}\right)+\frac{\mathrm{1}}{\mathrm{2}}\right]} =\mathrm{2}^{\left[\left(\mathrm{log}_{\mathrm{2}} \left({x}−{k}\right)\right)+\frac{\mathrm{1}}{\mathrm{2}}\right]}  \\ $
$\frac{{x}}{\mathrm{2}}={x}−{k}\Rightarrow\frac{{x}}{\mathrm{2}}={k}=\mathrm{2}^{\left[\left(\mathrm{log}_{\mathrm{2}} \frac{{x}}{\mathrm{2}}\right)+\frac{\mathrm{1}}{\mathrm{2}}\right]}  \\ $
${for}:\:\left\{\mathrm{log}_{\mathrm{2}} \frac{{x}}{\mathrm{2}}\right\}\:\in\left[\mathrm{0},\frac{\mathrm{1}}{\mathrm{2}}\right) \\ $
$\mathrm{log}_{\mathrm{2}} \frac{{x}}{\mathrm{2}}=\left[\mathrm{log}_{\mathrm{2}} \frac{{x}}{\mathrm{2}}\right]\Rightarrow{x}=\mathrm{2}^{{n}} ,\:{n}\in{Z} \\ $
${for}:\:\left\{\mathrm{log}_{\mathrm{2}} \frac{{x}}{\mathrm{2}}\right\}\:\in\left[\frac{\mathrm{1}}{\mathrm{2}},\mathrm{1}\right) \\ $
$\mathrm{log}_{\mathrm{2}} \frac{{x}}{\mathrm{2}}=\left[\mathrm{log}_{\mathrm{2}} \frac{{x}}{\mathrm{2}}\right]+\mathrm{1}\Rightarrow\left({no}\:{solution}\right) \\ $
$. \\ $
${so}\:{the}\:{answer}:\:{x}=\mathrm{2}^{{n}} ,\:{n}\in{Z} \\ $


Random element generation without duplicates Java

Question: I am trying to get this code to run without duplicates but am having no success researching this area.
Its the start of a question I am doing which will ask the user to input the missing element. However, when I generate random elements I am getting duplicates
import java.util.Random;

public class QuestionOneA2 {

    public static void main(String[] args) {

        String[] fruit = {"orange", "apple", "pear", "bannana", "strawberry", "mango"};
        Random numberGenerator = new Random();

        for (int i = 0; i < 5; i++) {
            int nextRandom = numberGenerator.nextInt(6);
            System.out.println(fruit[nextRandom]);
        }

    }

}

Comment: So you're trying to select 5 random items from a set of 6 items?
Comment: Apply `Collections.shuffle()` to sequence-filled list
Comment: Yes I am trying to randomly select 5 from 6 without duplicates
Comment: HI folks, really appreciate all f the help, is there a way that I can just randomly leave out an element from the array? May be that could be an easier way to perform the task
Answer: When you generate a random number, I suggest adding it into an array.
Then, when you generate your next number, do some sort of search (google for something efficient) to check if that number is already in the array and thus, has been used already.
If it is, generate a new one, if its not, use it.
You can do this by nesting it in a while loop.
Although, from what I can tell from your question, you would be better off just creating a copy of your fruit array using an ArrayList and then, when you generate a random number to select a fruit, simply remove this fruit from this new list and decrement the range of random numbers you are generating.
Comment: binary search works only in sorted arrays
Comment: @SashaSalauyou correct, don't know what I was thinking haha!
Answer: There are many different approaches you can consider, depending on how flexible the algorithm should be.
Taking 5 random elements from a list of 6, is the same as selection 1 element from the list of 6 that you don't choose. This is a very inflexible, but very easy.
Another approach could be to delete the element from the list, and decrease the maximum random number. In this cause I would advice to not use a String[].
Comment: Storing it in a string is one of the requirements of what I am trying to do
Answer: Copy your array into List<String>, then shuffle it, then just pick elements one by one:
List<String> copy = new ArrayList<>(Arrays.asList(fruit));
Collections.shuffle(copy);
for (String f : copy)
    System.out.println(f);

Answer: If I understand you correctly, then you want to choose n-1 elements at random from a list of n elements. If yes, then I recommend to choose just one at random and take all the others.
Arrays.shuffle(fruit);
int notThis = numberGenerator.nextInt(6);
for(int i = 0; i < fruit.length; i++)
    if(i!=notThis) System.out.println(fruit[i]);

Comment: Then shuffle the fruits first, then this issue is fixed as well: Arrays.shuffle(fruits) must be added before printing the results. I added this to my solution
Comment: If he'll do that then he might end up getting the same ordering again and again. For instance, if `apple` is excluded then order will be `OPBSM` and if `pear` is excluded then order will be `OABSM`. In both the cases order of `Orage` is fixed i.e. 0.
Comment: Yes, `shuffling` would do it.
Answer: You can use a Set to validate if the random generated number is duplicate or not. You just have to keep generating randomNumber until you find a unique random and then add it to the Set to prevent the duplicates.
Here is a quick code snippet:
public static void main(String[] args) {
    String[] fruit = {"orange", "apple", "pear", "bannana", "strawberry", "mango"};
        Random numberGenerator = new Random();
        /* Generate A Random Number */
        int nextRandom = numberGenerator.nextInt(6);
        Set<Integer> validate = new HashSet<>();
        /* Add First Randomly Genrated Number To Set */
        validate.add(nextRandom);
        for (int i = 0; i < 5; i++) {
            /* Generate Randoms Till You Find A Unique Random Number */
            while(validate.contains(nextRandom)) {
                nextRandom = numberGenerator.nextInt(6);
            }
            /* Add Newly Found Random Number To Validate */
            validate.add(nextRandom);
            System.out.println(fruit[nextRandom]);
        }
}

Output:
mango
apple
strawberry
pear
orange

Answer: You can wrap int into 'Interger' and add it to Set. Set holds no duplicates so there will be only unique values in it. So then just check if a Set already has given Integer with Set.contains(Integer).
Answer: my personal solution :
private static int[] randomIndexes(int len) {
    int[] indexes = new int[len];
    for (int i = 0; i < len; i++) {
        indexes[i] = i;
    }
    for (int i = len - 1, j, t; i > 0; i--) {
        j = RANDOM.nextInt(i);
        t = indexes[j];
        indexes[j] = indexes[i];
        indexes[i] = t;
    }
    return indexes;
}

See it in action : https://gist.github.com/GautierLevert/a6881cff798e5f53b3fb
Answer: I think it will be easier using an ArrayList, and also controlling the generation of the random number as shown below.
import java.util.Random;

public class QuestionOneA2 {

      public static void main(String[] args) {

        List<String> fruits = new ArrayList<>();

        fruits.add("orange");
        fruits.add("apple");
        fruits.add("pear");
        fruits.add("bannana");
        fruits.add("strawberry");
        fruits.add("mango");

        Random numberGenerator = new Random();
        int nextRandom;

       for (int i = 0; i < 6 ; i++) {
           nextRandom = numberGenerator.nextInt(6 - i);
           System.out.println(fruits.get(nextRandom));
           fruits.remove(nextRandom);
        }
      }

}

Answer: fruit.remove(fruit[nextRandom]);

Maybe, is it the remove sub-method?
Comment: Arrays do not have a `remove` method.


How to keep `click` event on sortable elements

Question: .itemp are children inside .pwrap.
$(document).on('click', '.itemp', function() {
console.log('323');
});

the above works but:
$('.pwrap').sortable({
axis: "y",
connectWith: ".pwrap",
tolerance: 'pointer',
update: function(event, ui) {
    $('#btnsave').addClass('btnred');
}
});

with the above code click event doesn't work.
How to keep click event on sortable elements?
Comment: as you can see it works. [fiddle](https://jsfiddle.net/e6ny1rqw/) Could you clarify the problem? Thanks
Comment: @gaetanoM, it doesn't work. Alert is there only after click. I need it after click and after sorting, because element IS CLICKED before sorting.
Comment: If you want the alert after the sorting, go ahead and put the console.log('323') line into the update method.
Comment: @AnthonyCollins, I simplified my `click` event. In fact it is much more complex. This is the reason I want to keep them separetely.
Answer: try adding disableSelection() and delegate click event
$('.pwrap').sortable({
    axis: "y",
    connectWith: ".pwrap",
    tolerance: 'pointer',
    update: function(event, ui) {
        $('#btnsave').addClass('btnred');
    }
    }).disableSelection().on("click", ".itemp", function() {
        console.log('323');
    });

if you wand the click on a separate event use
add     $('.pwrap').on('sortupdate',function() {alert('323')});

$(document).on('click', '.itemp', function() {
  alert('323');
});

$('.pwrap').sortable({
  axis: "y",
  connectWith: ".pwrap",
  tolerance: 'pointer',
  update: function(event, ui) {
    $('#btnsave').addClass('btnred');
  }
});
$('.pwrap').on('sortupdate',function() {alert('323')});
#sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
#sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
#sortable li span { position: absolute; margin-left: -1.3em; }

<link href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" rel="stylesheet"/>

Item 1

Item 2

Item 3

Item 4

Item 5

Item 6

Item 7

Comment: hmm... I need the `click` as separate event, because of `click` without `drag`.
Comment: The use of `$('.pwrap').on('sortupdate',function() {alert('323')});` is probably the best way to go here (like @Ram Segev pointed out).
Answer: The click events associated with the sortable() element are going to take precedence over the other one that you defined.
I suggest that you put your console.log() logic in a "start" method for the sortable(). Something along the lines of this should work:
$('.pwrap').sortable({
    axis: "y",
    connectWith: ".pwrap",
    tolerance: 'pointer',
    start: function(event, ui) {
        console.log('323');
        // anything else you want to do...
    },
    update: function(event, ui) {
        $('#btnsave').addClass('btnred');
    }
});

Let me know if this works. If it does, please mark this answer appropriately.
Comment: you say - `The click events associated with the .sortable() element are going to take precedence...` but `click` associated with the `sortable` doesn't exist in my code.
Comment: What I mean is that jQuery's source code creates click events on top of yours that override your .itemp click events.
Comment: could you give me the source for your assumption? I would be surprised if this is true. Why would jquery override my existing code ?


How many different possible remainders of a square number modulo an odd prime?

Question: Here is a solution to the question:

I get it up to 'This means that either x-y = 0 ...' Beyond that, I am very confused. I was wondering if someone more experienced could clarify the remaining solution/explain it in simpler terms, if that is possible, please? For example:
I don't get what it means when it says:

We get the same remainder if x and y have the same value mod p
The only way these can give the same remainder is when they add to a multiple of p...
This pairs the remainder x with p-x

And so on...
Apologies if my question is too vague - I'm just quite stuck on this and would really appreciate any help. Thank you!
Comment: When in doubt, work with examples. Here consider $1^2, 2^2, 3^2, 4^2, 5^2 \mod 5$.
Comment: Okay @cosmo5 - so that would give remainders 1, 4, 4, 1 and 0... I see how that fits into the given solution in terms of 'pairing up' etc...But I still don't understand the general case - i.e. why this pattern occurs...
Comment: Hmmm...Sorry @cosmo5 - I still don't get that fourth paragraph in the solution given above...
Comment: I've added explanation in my answer. Please see.
Comment: Ah okay! Thanks @cosmo5 - just one final thing: How does the factorisation (x-y)(x+y) = 0 (mod p) tell us that 'the only way these can give the same remainder when squared, is when they add to a multiple of p'...? Also, why are the pairs x and p-x distinct, EXCEPT for when p-x = x (mod p)? What does this actually mean. Thank you for your help so far. I think I'm starting to understand.
Comment: $1$ and $4$ are *two* distinct primitive remainders. But $5$ and $0$ are same modulo $p$. $0\equiv (5-0) \pmod 5$.
Comment: Okay. And - How does the factorisation (x-y)(x+y) = 0 (mod p) tell us that 'the only way these can give the same remainder when squared, is when they add to a multiple of p'...?
Comment: $x-y \equiv 0$ means $x$ and $y$ both give same remainder eg, both give 1. $x+y \equiv 0$ means remainders are $x$ and $p-x$ eg, 1 and 4. $x+y$ and $x-y$ are coprime in second case.
Answer: Consider a numerical example. $p=5$.
We have

$4\equiv -1 \pmod 5 \Rightarrow 4^2\equiv (-1)^2 \equiv 1^2 \pmod 5$
$3\equiv -2 \pmod 5 \Rightarrow 3^2\equiv (-2)^2 \equiv 2^2 \pmod 5$
$5\equiv 0 \pmod 5\Rightarrow 5^2\equiv 0 \pmod 5$

The primitive remainders modulo $p$ are $\{ 0,1,2,3,\ldots,p-2,p-1 \}$ which are also $\{ 0,1,2,3,\ldots,-2,-1 \}$ modulo $p$. These are $p$ in total.
Squaring these we obtain distinct remainders $\{ 0,1^2,2^2,3^2,\ldots,(\frac{p-1}{2})^2 \} $ modulo $p$.
Thus we obtain $\frac{p-1}{2}$ pairs $\{(1,p-1), (2,p-2), \ldots\}$ (each pair summing to $p$) and a single distinct remainder, $0$.


CKeditor: Add class to all ul and ol elements on output

Question: The ul and ol elements are often used in theming outside of the 'text'-context (e.g. category blocks, etc.). Therefore the bullets are removed by default.
Is there a way to add a class to all ul and ol elements outputted by CKeditor? For example class 'editor', so that we can theme the ul/ol elements differently if they are outputted by CKeditor (with bullets or decimals).
Answer: There is no reason to do that for styling purposes. You can target the ul and ol elements by their parent container. The classes depends on your theme output, but consider this for the Garland theme:
/* Style all ul and ol elements from the body output. */
#center .node .content ul,
#center .node .content ol {
  /* Styles here */
}

If you are missing classes you can add those in the page.tpl.php and node.tpl.php templates.
Comment: Not possible to style on .content, because this contains other ul's which need to be styled differently + I'm trying to get a very clean HTML output without any (drupal default) exceed div's and classes, so most of those are stripped by Mothership.
However, the solution is easy. Install Display Suite and add a class (e.g. .editor) to the output of your body/text field :)
Comment: Drupal sucks in terms of clean HTML.


In android how to place components in a listview with items?

Question: I am using a listview with listitems and there is a need for me to add button near each listitem. How can i make it possible.
Answer: you need to have your own custom adapter and in that you have to set the layout in the getView() method. Now in the layout file that is the xml file keep the button.


worship leader range loss and excessive vocal fry

Question: I am experiencing vocal fry in my upper register that I did not use to have. I am a bass but leading worship generally puts me outside of my range sometimes significantly. I always make sure to relax and support correctly what I sing and I hydrate like a maniac. At the end of the day I still end up with a sore throat and my voice sounds like trash. I am worried that I am being pushed too hard and am causing damage. Is this something that I can eventually train through, or do I seriously need to consider taking some vocal rest to see if that helps? I'm also experiencing loss of range at the top of my register not the bottom. Any advice would be helpful at this point.
Comment: Yikes, loss of range has generally been permanent in my experience. My mom reports losing her upper range decades ago and never getting it back, and my range has been dropping for over a decade (slowly lose top notes and gain bottom notes). Warm-ups only temporarily increase my upper range, and only seem to boost it by a whole tone at most.
Answer: Just like every other art of our bodies, those which produce sound deteriorate over time. Even greats like Elvis (!) needed to drop some songs a couple of keys in later life, and he is not alone.
Simple solution - sing in a range which suits your voice, rather than straining, which will only exacerbate the problem - maybe even to the permanent damage point. Not good. So, changes of keys with high tessitura are in order. Just hope your accompanist/s will cope!
Use a mic, learn the techniques we have for singing more gently - there really should be no need to belt out anything.
Answer: Consider an evaluation by an otolaryngologist, if possible one with a specialized practice in voice medicine.  While it is true that changes of this sort are unavoidable with aging, it's also possible that there is a contributing factor that you can manage.  A common one is gastroesophageal reflux, which can be managed relatively effectively in many cases.  Another possible factor in voice changes is neurological.
If there is an underlying cause of these changes, it is unlikely to affect only your voice, so you will probably want to identify any such cause and, if possible, address it as early as possible.
If no underlying cause can be found, you can probably still improve your lot.  An otolaryngologist can help with treatment for your symptoms.  A voice teacher, preferably an experienced one with a sound training in the science of vocal pedagogy, can help you determine whether your "relax and support correctly" is in fact correct.
Unless I've overlooked it, you haven't mentioned your age.  If you are young, especially if you are in your mid 20s or younger, you may want to consider the possibility that your voice is still maturing and your newfound difficulties arise because of that.  Regardless of your age, you may simply have a voice that is unsuited to leading worship.  The keys chosen for unison singing are nearly always too high for a true bass.  It's a bit like singing Le veau d'or from Gounod's Faust for 40 minutes straight (in the opera, the two verses with chorus take less than two minutes).
Comment: Im currently 27 I can't remember at what age the voice fully matures. And yes unison singing is very much in unfriendly territory for me.
Comment: I'm over 30, and I swear I'm still gaining bottom notes in my singing range. (I'm also female.)


Multiple Imputation of Coarsened/Interval Data

Question: I'd like to know how to impute non-normally distributed data from interval data, where the intervals differ across different individuals.
The variable I am interested in is the number of months an individual was unemployed in the three years after leaving full-time education. This variable is naturally bounded at 0-36.
I have partially observed working-histories for some individuals,though, so in some cases I can narrow this interval down. For example, I may observe an individual for 12 months and see they were unemployed in 3 of those months. Their interval can therefore be narrowed to 3-27.
These data are not normally distributed - they are heavily skewed towards zero, with a sizeable number of individuals at 36, too - due to truncation. (See picture below.)
Given this I think I should use predictive mean matching. I'd like to know if anyone knows of any method/software where the candidate pool of donors can be restricted based on the individuals' specific interval. Otherwise, I'm likely to impute values which I know to be false - i.e. outside the known bounds.
I know of programs which can use different bounds for different individuals, but these assume normally distributed data (e.g. ice package in Stata) or just truncate values afterwards if the imputed value is outside bounds (e.g. mice in R).
Does anyone have any suggestions please?
Thanks.
Comment: Did you actually try PMM ? In my experience it does not impute values outside the relevant range. An alternative is hot-deck imputation.
Comment: @RobertLong that is essentially a plausible answer. Predictive mean matching is a cross between propensity score matching and imputation - you basically match by random draw from the *k* observations most similar to the one being imputed. Note that by default, *k = 1* in Stata, and you can and almost certainly should change that to 5 or so.
Comment: @RobertLong, I haven't tried it yet as need to get covariates together. Have you tried PMM in this setting where each individual has their own range?
Comment: There is a broader statistical question of whether you can even model that kind of data with a standard modeling function, let alone perform imputation on it. As you said, there exist methods for modeling when the *residual* are normally distributed (doesn't have to be the data that are normally distributed), such as `truncreg` and `intreg` in Stata, which are compatible with `mi impute chained`. Perhaps ask another question about how to model that data. Then you can attempt to customize a MI software with that model.
Answer: @RobertLong commented first, but hasn't fleshed this out into an answer. Predictive mean matching is a bit like propensity scoring. I'm simplifying the description in the link, but for each observation with missing $x$, you find the $k$ complete data observations that should be most similar to the one with missing data, then impute one of the $k$ nearest neighbors' complete data observations, then repeat the process (note, it's more complicated that that and involves an additional stochastic step I didn't describe; read the link).
You're drawing imputations from actual data, sort of like you would in bootstrapping. So, the imputed data are going to match the characteristics of the observed data.
Since you're using Stata, one issue you need to be aware of is that the default setting has $k = 1$, which Allison (the link above) argues is much too low and produces too little variability, and that you should set $k =$ 5 or 10.
In Stata, the syntax would be
mi impute pmm Status3_M = x1 x2 x3 ... , knn(5)
Or, if doing as part of a larger imputation by chained equations,
mi imputed chained (pmm, knn(5)) Status3_M (regress) ... (whatever else) ... = x1 x2 x3
Default $k$s vary from program to program, but SPSS apparently shares Stata's default. SAS and R's mice default to $k=5$.
Comment: This doesn't address OPs problem. It's true PMM bounds imputed values at the sample bounds, but OP wants to bound imputed values at specific, different values for each individual. PMM would rely on the bounds of other individuals; for example, if the k nearest neighbors had bounds of 30 but the individual in question had a bound of 20, the individual's bound would not be respected by KNN.
Comment: Thank you for the replies. What I am looking for is a PMM algorithm that adds in extra step that donor pool is restricted to observed values which are within the known interval for the missing value.

By example, with k=1, let's say we have one missing observation and three observed values. Predicted values are 4, 1, 5, 6 (missing and observed, respectively). Observed values are 2, 4, 7, and known interval for missing is 1-3. First observed value with be taken (2) as only one in known interval, even though the predicted score for this observation is furthest away.


Prove that $D'_n=\langle x^2\rangle$

Question: I want to check if my solution to one problem from my group theory course is valid. The problem is:

Given $D_n=\{x^iy^j:0\leq i<n,0\leq j<2\}$, prove that $D'_n=\langle x^2\rangle$.

My attempt is:
Given two different elements $g=x^ay^b$ and $h=x^cy^d$ (it's clear that $g,h\in D_n$). We calculate its commutator:
$$[g,h]=x^ay^bx^cy^dy^{-b}x^{-a}y^{-d}x^{-c}$$
Using that $yx^iy=x^{-i}$ (I'll go almost straight to the result avoiding the operations) we get that
$$[g,h]=x^ax^{-c}y^by^dy^{-b}y^{-d}x^ax^{-c}=x^{2a-2c}=(x^2)^{a-c}\in \langle x^2\rangle.$$
So this proves that, $\forall g,h\in D_n$, $[g,h]\in\langle x^2\rangle$, so from this we conclude that
$$\boxed{D'_n=\langle x^2\rangle}$$
Is my solution valid? If not, why? Any help will be appreciated, thanks in advance.
Comment: small tip: in mathjax, instead of using $<$ and $>$ for group presentations, use \langle and \rangle, which look like $\langle$ and $\rangle$
Comment: @AtticusStonestrom Thanks for the tip! I'll edit my post.
Answer: Well, you showed that $D_n'\subseteq \langle x^2\rangle$. But what about the other direction? It is easy though, because $x^2=[x,y]\in D_n'$, and so $\langle x^2\rangle\subseteq D_n'$.
By the way, another way to see that $D_n'\subseteq\langle x^2\rangle$ is to note that $D_n/\langle x^2\rangle$ has either order $2$ or order $4$, depends if $n$ is even or odd. But in either case, $D_n/\langle x^2\rangle$ is abelian, and so $\langle x^2\rangle$ contains all the commutators of the group.

Prove that $D'_n=\langle x^2\rangle$


Mixed Nash Equilibrium of cyclic game of order 4.

Question: I am looking at a symmetric zero-sum game with 4 strategies and the following payoff matrix that has no pure Nash Equilibrium since it forms a circulant graph.$$\begin{pmatrix}
0 & 1 & 0 & -1\\
-1 & 0 & 1 & 0 \\
0 & -1 & 0 & 1\\
1 & 0 & -1 & 0 \\
\end{pmatrix} $$I entered the game in a state of the art calculator  (bimatrix solver, by Avis, Rosenberg, Savani, and von Stengel) and obtained the result as follows: $$p_1=0.5,\quad p_2=0,\quad p_3=0.5,\quad p_4=0,\quad q_1=0.5,\quad q_2=0,\quad q_3=0.5,\quad q_4=0 $$
$$p_1=0.5,\quad p_2=0,\quad p_3=0.5,\quad p_4=0,\quad q_1=0,\quad q_2=0.5,\quad q_3=0,\quad q_4=0.5 $$
$$p_1=0,\quad p_2=0.5,\quad p_3=0,\quad p_4=0.5,\quad q_1=0.5,\quad q_2=0,\quad q_3=0.5,\quad q_4=0 $$
$$p_1=0,\quad p_2=0.5,\quad p_3=0,\quad p_4=0.5,\quad q_1=0,\quad q_2=0.5,\quad q_3=0,\quad q_4=0.5 $$ What I do not understand is why the mixed strategy with all strategies played with probabilities $\frac{1}{4}$ not a MNE for this game? Is the calculator missing some solutions or am I missing something?
Comment: Isn't it the case that if you have two equilibria in a two-player zero-sum game, then any convex combination of those equilibria is also an equilibrium?
Comment: How do you say that the strategy in question is not an equilibrium?
Answer: When you enter your bimatrix in the solver, you get the following result:
<code>4 x 4 Payoff matrix A:

   0   1   0  -1
  -1   0   1   0
   0  -1   0   1
   1   0  -1   0

4 x 4 Payoff matrix B:

   0  -1   0   1
   1   0  -1   0
   0   1   0  -1
  -1   0   1   0

EE = Extreme Equilibrium, EP = Expected Payoff

Decimal Output

  EE  1  P1:  (1)  0.500000  0.000000  0.500000  0.000000  EP=  0.0  P2:  (1)  0.500000  0.000000  0.500000  0.000000  EP=  0.0
  EE  2  P1:  (1)  0.500000  0.000000  0.500000  0.000000  EP=  0.0  P2:  (2)  0.000000  0.500000  0.000000  0.500000  EP=  0.0
  EE  3  P1:  (2)  0.000000  0.500000  0.000000  0.500000  EP=  0.0  P2:  (1)  0.500000  0.000000  0.500000  0.000000  EP=  0.0
  EE  4  P1:  (2)  0.000000  0.500000  0.000000  0.500000  EP=  0.0  P2:  (2)  0.000000  0.500000  0.000000  0.500000  EP=  0.0

Rational Output

  EE  1  P1:  (1)  1/2    0  1/2    0  EP=  0  P2:  (1)  1/2    0  1/2    0  EP=  0
  EE  2  P1:  (1)  1/2    0  1/2    0  EP=  0  P2:  (2)    0  1/2    0  1/2  EP=  0
  EE  3  P1:  (2)    0  1/2    0  1/2  EP=  0  P2:  (1)  1/2    0  1/2    0  EP=  0
  EE  4  P1:  (2)    0  1/2    0  1/2  EP=  0  P2:  (2)    0  1/2    0  1/2  EP=  0

Connected component 1:
{1, 2}  x  {1, 2}
</code>
I believe the way to read this is the strategy $1$ is given by $s_1 =(0.5,0,0.5,0)$ and the strategy $2$ is given by $s_2 = (0,0.5,0,0.5)$.
The very last line says there is a "connected component", and in this case it means that both players playing any convex combination between $s_1$ and $s_2$ is also a Nash equilibrium. In particular, the strategy profile $((0.25,0.25,0.25,0.25),(0.25,0.25,0.25,0.25))$ is a Nash equilibrium.
Comment: I am confused of the meaning of having an infinite number of equilibrium. Does stability matter in those scenarios? I guess I should read on Equilibrium Selection.


Best place to find open questions / latest research

Question: Is there a central wiki or something where open questions (and relevant research on them) takes place?
Comment: I'm not aware of such a thing, but I'd be interested in knowing the answer. There's always Wikipedia's list of unsolved problems (http://en.wikipedia.org/wiki/List_of_unsolved_problems_in_mathematics)
Comment: See http://mathoverflow.net/questions/48299/more-open-problems
Comment: How is this related to [mathematica]? Changed the tag.
Comment: Depends on the area; some areas have *some* sites. See the link I give below.
Answer: Going by the title of your question if you are trying to find out the "Best place to find... latest Research" I think I would go by http://arxiv.org. Lots of papers out there. Many papers are junk (including some of mine... hehe) But you can also find papers on open problems by serious mathematicians.
For me, reading papers from arxiv and trying to understand them has helped me a lot to learn new stuff.
For a wiki like site, you might check, http://garden.irmacs.sfu.ca/
For collaborative mathematics:
You might also do google search on the polymath project which started from this blog post: http://gowers.wordpress.com/2009/01/27/is-massively-collaborative-mathematics-possible/
Comment: [nielsen polymath wiki](http://michaelnielsen.org/polymath1/index.php?title=Main_Page)


Need help in panel data tests and steps

Question: Greetings!
I am analyzing the impact of climate change of wheat crop across 4 districts for the last 30 years.
It is imperative to check the stationarity of the panels.
I performed LLC and IPS tests. The results showed that the panels are stationary.
Now please let me know:

Whether I need to perform cointegration tests like Kao, Westerlund etc. I doubt that if the panels are stationary, there is no cointegration, and there is no need to go for  cointegration tests.

The LLC and IPS unit root tests assume the cross sectional independence. If their results show no unit roots, then, do I still need to test the cross sectional dependence through Pesaran CD or other LM tests. Or I can skip the cross sectional dependence tests

If the panels are stationary, should I proceed directly to the model specification tests to find the best model among Pooled OLS, Fixed Effect and Random Effect Models.

I will be highly thankful to you all for your help and guidance in this regard.
Answer: Ad 1, indeed, if the series are stationary, there cannot be cointegration, as cointegration describes the situation of stationary linear combinations among nonstationary variables.
Ad 2, yes, as it is quite possible that the rejection you obtained from LLC/IPS is spurious, i.e., that it did not result because the series really are stationary but because an underlying assumption of the test is not met so that it does not give trustworthy results.
Ad 3, I am not sure what you mean by "directly", but that does not sound like a bad idea.
Comment: Thank you sir for guiding me in my analysis. I used "directly" as I intended to say that I should skip cross sectional dependence test and proceed to model specification tests.
Comment: OK, thanks for clarifying. In 2, by yes I meant that you should test for CSD and if you find it, use robust panel unit root tests

Need help in panel data tests and steps


finite elements-exercice

Question: We consider in $\mathbb{R}^2$ the set of points $$\{M_1(-1,1),M_2(0,1), M_3(2,1),M_4(-1,0),M_5(1,0),M_6(2,0)\}$$
Let $\Omega$ a rectangular structure consisting of the heads $\{M_4(-1,0),M_6(2,0), M_3(2,1),M_1(-1,1)\}$
Let the two polygons $\sum_1 = \{M_4,M_5,M_2,M_1\}$ and $\sum_2 = \{M_5,M_6,M_3,M_2\}$
let the mesh $\{(e_1,\sum_1,Q_1),(e_2,\sum_2,Q_2)\}$ such $$Q_1=\{f : \mathbb{R}^2 \rightarrow \mathbb{R} , f(x,y) = a + bx + cy + d xy , a , b, c , d \in \mathbb{R}\}$$
1- Prove that $(e_1,\sum_1,Q_1)$ and $(e_2,\sum_2,Q_1)$ are two finite elements of Lagrange.
2- Let $V$ the finite-dimensional space that corresponds to the mesh. Prove that $V \nsubseteqq H^1(\Omega)$
My problem is to prove 2.
Answer: For any piecewise polynomial $v\in V$, $v$ restricted in each polygon has the form of $Q_1$:
$$
v = \begin{cases}
a_1+b_1 x+ c_1y + d_1 x y \quad\text{ in } \Sigma_1
\\
a_2+b_2 x+ c_2y + d_2 x y \quad\text{ in } \Sigma_2
\end{cases}
$$
Now we wanna argue that there exits such $v\notin H^1(\Omega)$. For $v$ is definitely continuous in both $\Sigma_1$ and $\Sigma_2$ respectively, and it has $H^1$-regularity in both polygons. You can check $v$ restricted on $\Sigma_1$ is $L^2$ and so is its gradient, the same applies to $v$ restricted on $\Sigma_2$.
The only possible problematic part is where these two polygons intersect with each other: $\partial \Sigma_1 \cap\partial \Sigma_2 = M_2 M_5$.
The construction is pretty straight forward, we set $v = 1$ at node $M_2$, and zero on all other nodes, see if we can get a function that is continuous across the interface $M_2 M_5$ between these two polygons.
In $\Sigma_1$, we have:
$$
\begin{cases}
&a_1+&b_1 (-1)+ &c_1 1 + &d_1 (-1) &= v(M_1) = 0
\\
&a_1+ & &c_1 1  & &= v(M_2) = 1
\\
&a_1+ &b_1 1 &  & &= v(M_5) = 0
\\
&a_1+ &b_1 (-1) &  & &= v(M_4) = 0
\end{cases}
$$
solving this leads to:
$$
v\big|_{\Sigma_1} = y+xy.
$$
In $\Sigma_2$, we have:
$$
\begin{cases}
&a_2+&b_2 2+ &c_2 1 + &d_1 2 &= v(M_3) = 0
\\
&a_2+ & &c_2 1  & &= v(M_2) = 1
\\
&a_2+ &b_2 1 &  & &= v(M_5) = 0
\\
&a_2+ &b_2 2 &  & &= v(M_6) = 0
\end{cases}
$$
solving this leads to:
$$
v\big|_{\Sigma_2} = y-\frac{xy}{2}.
$$
Therefore, for a $v\in V$ satisfying that $v(M_2) = 1$ and zero at other nodes:
$$
v = \begin{cases}
y+xy \quad\text{ in } \Sigma_1
\\
y-xy/2 \quad\text{ in } \Sigma_2
\end{cases}
$$
Now it is up to you to check this function is not in $H^1$.

Update:

please help me! i need an reference (book ) who we can found the definition of $V$ ($v\in V$ iff $v\in H^1$ on the two polygones and $v$ is continuous on $M_2$ and $M_5$ please.

I already gave you the reference in the comments. You are not satisfied with its presentation, yet I think it is crystal clear: Ciarlet's The Finite Element Method for Elliptic Problems, please refer to the proof of Theorem 2.1.1 on pg40.
The result is commonly used for finite elements w/o citing any references, and it is very straightforward to prove. It can be formulated as follows:
Lemma: Suppose $\Sigma_1$ and $\Sigma_2$ are Lipschitz polygons, and $\partial\Sigma_1 \cap \partial \Sigma_2 = F$. Let $v_1\in H^1(\Sigma_1)$, $v_2\in H^1(\Sigma_2)$, and $v \in L^2(\Sigma_1\cup\Sigma_2\cup F)$ so that $v = v_1$ in $\Sigma_1$ and $v=v_2$ in $\Sigma_2$. Then if $v_1 = v_2$ on $F$, we have $v\in H^1(\Sigma_1\cup\Sigma_2\cup F)$.
Proof: Let $\Omega = \Sigma_1\cup\Sigma_2\cup F$. It suffices to show that the weak gradient of $v$ on the joint domain coincides with $\nabla v_1$ on $\Sigma_1$ and $\nabla v_2$ on $\Sigma_2$. Let $\phi \in C^{\infty}_c(\Omega)$,
$$
\int_{\Omega} \frac{\partial v}{\partial x_i} \,\phi :=
- \int_{\Omega} v \,\frac{\partial \phi}{\partial x_i} .
$$
This is the definition. The right side now can be divided into two parts:
$$
- \int_{\Omega} v \,\frac{\partial \phi}{\partial x_i} =
- \int_{\Sigma_1} v_1 \,\frac{\partial \phi}{\partial x_i}
- \int_{\Sigma_2} v_2 \,\frac{\partial \phi}{\partial x_i}
\\
= \int_{\Sigma_1} \frac{\partial v_1}{\partial x_i} \,\phi - \color{blue}{\int_{\partial \Sigma_1}  v_1 \phi \,(n_{\partial \Sigma_1})_i\,dS}+ \int_{\Sigma_2} \frac{\partial v_2}{\partial x_i} \,\phi
- \color{blue}{\int_{\partial \Sigma_2}  v_2 \phi \,(n_{\partial \Sigma_2})_i\, dS},
$$
$n_{\partial \Sigma_k}$ is the unit outer normal vector to $\Sigma_k$ ($k=1,2$). Blue terms will cancel because $n_{\partial \Sigma_1} = -n_{\partial \Sigma_2}$ pointwisely, and $v_1 = v_2$ pointwisely as limit from their defined domain respectively (or use a trace argument if you like). Hence
$$
\int_{\Omega} \frac{\partial v}{\partial x_i} \,\phi =  \int_{\Sigma_1}\frac{\partial v_1}{\partial x_i} \,\phi + \int_{\Sigma_2} \frac{\partial v_2}{\partial x_i} \,\phi.
$$
This tells us $\nabla v = \nabla v_1$ on $\Sigma_1$ and $\nabla v = \nabla v_2$ on $\Sigma_2$. Hence
$$
|\nabla v|_{H^1(\Omega)}^2 = \|\nabla v\|_{L^2(\Omega)}^2
= \|\nabla v_1\|_{L^2(\Sigma_1)}^2 + \|\nabla v_2\|_{L^2(\Sigma_2)}^2 < \infty,
$$
and the lemma follows.
Comment: @jijiii Oh I see, maybe we have a little misunderstanding. In stackexchange forum, "accepting" means clicking the check box outside the answer on the left upper corner of the answer, below the upvote arrow and the downvote arrow.
Comment: @jijiii And I suggest you go back to all of your previous question, accept the answer you are by clicking the check box. (If you don't know how to do, please refer to http://math.stackexchange.com/faq#howtoask  ctrl+f accept on this page)

finite elements-exercice


Different size for file system and LV when shrinking a Logical Volume?

Question: I need to shrink a Logical Volume, and some of the articles on the Internet were saying that there are three ways of achieving this:
1) the simplest route - use the same size for file system and logical volume group
2) shrink the file system, check the numbers with vgdisplay and shring the LV based on this number with the option of --extent
3) set file system to 90% of the size of the LV that you want to have. So this could be 45G for file size part and create the LV of 50G after that. The last step here would be to "grow the file system so that it uses all available space on the logical volume". The article that was saying that was like 6-7 years old, so I am not sure. I read another article that was suggesting the same method, but people in the comments were not sure about it, and were thinking that this may be wrong (a mistake; they were thinking about the same numbers).
I am using Centos 7 and ext4. What is the best way of going about that now?
Thanks.
Answer: If by "best" you mean least math, you can let lvm deal with the fs.
lvreduce --resizefs --size -2G /dev/vg/lv
Where --size if it has the - in front is the amount to reduce, absolute size if no negative sign.
Reduce does require unmount, but this integration with fsadm can do that for you.


Is there an option to configure a priority in memcached? (Similiar to Expiry)

Question: A hashtable in memcached will be discarded either when it's Expired or when there's not enough memory and it's choosen to die based on the Least Recently Used algorithm.
Can we put a Priority to hint or influence the LRU algorithm? I want to use memcached to store Web Sessions so i can use the cheap round-robin.
I need to give Sessions Top Priority and nothing can kill them (not even if it's the Least Recently Used) except their own Max_Expiry.
Answer: Not that I know of.
memcached is designed to be very fast and very straightforward, no fancy weights and priorities keep it simple.
You should not rely on memcache for persistent session storage. You should keep your sessions in the DB, but you can cache them in memcache. This way you can enjoy both worlds.


How to change the default version of gcc man page?

Question: I have installed gcc-4.8 and gcc-6. The default gcc version is gcc-4.8, but I want to change the default gcc version to gcc-6, so I do the following:
$ sudo update-alternatives --remove-all gcc
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 10
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 20

then the default gcc version has changed to gcc-6, but when I run command
$ man gcc

the man page version of gcc is still gcc-4.8. How can I change the man page version of gcc to gcc-6? Thanks!
Sorry for my bad English.
Comment: Try `apt-get remove gcc-doc` and then look for an updated version of that package to install.
Answer: I have found the solution:

Find the location of gcc-6 man page:
$ locate gcc-6 | grep 'man'
/usr/share/man/man1/gcc-6.1.gz
/usr/share/man/man1/x86_64-linux-gnu-gcc-6.1.gz

so the location of gcc-6 man page is /usr/share/man/man1/gcc-6.1.gz
Remove the file /usr/share/man/man1/gcc.1.gz if it exist:
$ sudo rm /usr/share/man/man1/gcc.1.gz

Create a symbolic link to /usr/share/man/man1/gcc-6.1.gz:
$ sudo ln -s /usr/share/man/man1/gcc-6.1.gz /usr/share/man/man1/gcc.1.gz

Then run comman:
$ man gcc

You will see the man page version of gcc has changed to gcc-6.
Sorry for my English.


Properly discontinuous action on manifold

Question: I am actually not familiar with topology, but since we had a short outlook on these things in our differential geometry lecture today, I would appreciate some general remarks:
Let $M$ be a smooth manifold and $\Gamma$ a group of diffeomorphisms on $M$, then
$\Gamma$ is called properly discontinuous, if 1.) and 2.) hold.
$1.) \forall p \in M \exists p\in U$ (open nbh.)$ \forall \phi \in \Gamma \backslash\{id\}: \phi(U) \cap U = \emptyset. $
This seems to tell me that there is basically no fixed point under such a non-trivial diffeomorphism (even more, we get that we can separate the image by an open nbh.)
$2.) \forall p,q \in M,$where $q$ is not in the orbit of $p$ there are open nbhs $U(p),U(q)$ such that $\phi(U(p)) \cap U(q) = \emptyset$ for all $\phi \in \Gamma.$
First question:
I feel that the second property is often skipped in textbooks, but don't know why?! To me, it seems to be similar to a Hausdorff property in $M/\Gamma.$
Now, we showed that such a group $\Gamma$ implies that $M/\Gamma$ is again a manifold and the projection $\pi: M \rightarrow M/\Gamma$ is a covering map. In this sense $\Gamma$ can be regarded as the group of deck transformations. If $M$ is simply connected, then this group can be also considered as the fundamental group of $M / \Gamma.$
Second question: If I understand this correctly, then the converse also holds. $M/\Gamma$ is a manifold, only if $\Gamma$ acts properly discontinuous on $M$?
Third question: In this thread Lee Mosher argues that properly discontinuous is not sufficient to conclude that $M \rightarrow M/\Gamma$ is a covering map (see his comments). Is this also true for my definition?  Actually I don't understand why free action is not a corollary of my first part of the definition, cause it just means that the only group element that is allowed to have fixed points is the identity?
Comment: Did you check out [this math.OF thread](http://mathoverflow.net/questions/55726/properly-discontinuous-action)? I believe property 1 corresponds to Type D there.
Comment: See my answer to [this question](http://math.stackexchange.com/questions/1082834/properly-discontinuous-action-equivalent-definitions).
Comment: The answer to your second question, as you posed it, is no. For example, the action of $\mathbb R$ on $\mathbb R^2$ by vertical translations has a quotient diffeomorphic to $\mathbb R$, but it's not properly discontinuous. But if you assume it's a covering space action (meaning that it satisfies your condition 1), then the quotient is a manifold iff the action satisfies condition 2.
Comment: @JackLee thanks that clarifies it, I bet you also know the answer to question 2.)
Comment: @JackLee could you please give me also a hint regarding the second question?
Answer: Exactly the same group action (but named little differently) is in the book "Differential Geometry"on page 68 written by Marcel Berger and Bernard Gostiaux.

Additonaly on the page 70 there is theorem of yours. It is done well with details.

Back to your questions.

You are perfectly right. In the proof of this theorem condition 2) starts to work, when we want to show that $M/\Gamma$ is Hausdorff.
Hard question.
Here we come back to the definition. Your group actually acts "properly discontinuously without fixed points (freely)." This additional condition makes the difference. (see the proof in the book I've mentioned)
Comment: I have troubles understand your point 3.) Why is the acts freely part not included in the first assumption of the definition? I don't see how 2.) is related to the acts freely?
Comment: It is not included in the discussion you have linked. They mean something different than you when speak of proper discontinuous action. But you are right. Your definition truncated to this part is exactly the proper discontinuous action.
Answer: Let me address some issues raised in your question which are not addressed in the accepted answer.
First of all, when you see the expression "properly discontinuous" you should not assume that it is meant in the same sense you (whoever you might be) have in mind. I counted 6 inequivalent definitions of proper discontinuity used in the literature (and I probably missed some). Let me refer to the definition 1 in OP as PD1 and to 1 & 2 as PD2.
The definition that Lee Mosher had in mind in his comment in the linked answer is PD3 which different from PD1 and  PD2! His definition PD3 allows for fixed points and can be written as:
For every compact subset $K$ of  $M$, the subset
$$
\{\gamma\in \Gamma: \gamma K\cap K\ne \emptyset\}
$$
is finite. This definition allows non-free group actions (i.e. a non-identity element can have a fixed point). By my count, this is actually the most common definition. It is not hard to see that PD2$\Rightarrow$PD3 and, clearly, PD2$\Rightarrow$PD1.
Now, to your question 2:

Suppose that $\Gamma$ is a group of homeomorphisms of $M$ such that $M/\Gamma$ is a manifold. Does it follow that $\Gamma$ acts  properly discontinuously on $M$?

As Jack Lee noted in his comment: regardless of what definition of proper discontinuity you use, the answer is negative. For instance, we can take $M={\mathbb R}^n$ and $\Gamma\cong {\mathbb R}^m$, $0<m\le n$, a group of translations acting on $M$ (and preserving a splitting of ${\mathbb R}^n$ as ${\mathbb R}^n={\mathbb R}^m \oplus {\mathbb R}^{n-m}$). Then the quotient $M/\Gamma$ is homeomorphic to  ${\mathbb R}^{n-m}$ but the action is not properly discontinuous in any sense.
Let's modify this question and, assume additionally, that the quotient $M/\Gamma$ has the same dimension $n$ as $M$. Then the answer is still negative if one were to use PD1:
Take $M={\mathbb R}^2$ and the group $\Gamma$ of order 2 generated by the involution $(x,y)\mapsto (-x,-y)$. Then the action is not free (hence, fails PD1) but $M/\Gamma$ is homeomorphic to ${\mathbb R}^2$.
It is easy to see, however (and it was already observed in the OP)
that if $M/\Gamma$ is Hausdorff, then Property 2 in the OP holds. This leaves us with two questions, which, I think, are open problems:
Question 1. Suppose that  $M/\Gamma$ is a manifold of the same dimension as $M$. Does $\Gamma$ satisfy PD3?
Question 2. Suppose that  $M/\Gamma$ is a manifold of the same dimension as $M$ and the action of $\Gamma$ on $M$ is free. Does $\Gamma$ satisfy PD1? (Which then would imply PD2.)


Algolia - Get all unique tags with its total counts

Question:
How can I get all the tags attribute and group by distinct as circled in the provided image? Each record may have tags and the tags may duplicates. I've tried to get this data by using the JavaScript API as seen below and it didn't work. I expect it to show all the unique tags as circled but instead, it returns every record. Any idea on how to achieve the desired outcomes?
import algoliasearch from "algoliasearch";

const algoliaClient = algoliasearch(
  process.env.VUE_APP_ALGOLIA_APP_ID,
  process.env.VUE_APP_ALGOLIA_ADMIN_KEY
);

const algoliaIndex = algoliaClient.initIndex("main-index");

algoliaIndex.setSettings({
  attributeForDistinct: "tags",
  attributesToRetrieve: ["tags"],
  distinct: 1
});

algoliaIndex.search().then(({ hits }) => {
  console.log(hits);
});

Answer: Thanks to Marie Gillier from the Algolia team in answering my question. Below is the solution. You can find more explanation from the link given (Algolia's Forum)
algoliaIndex.searchForFacetValues("tags", "").then(({ facetHits }) => {
  console.log(facetHits);
});


Why is pod's memory almost double the pod's only container's memory with no ephemeral storage?

Question: Well, the title says it all :-)
I don't know where the extra pod's memory is coming from. Any command to reveal that? I want to set memory request correctly.
I look at it in Lens. I expect it to be the same in this setup.
Comment: OK, I probably found an answer: https://stackoverflow.com/questions/69281327/why-container-memory-usage-is-doubled-in-cadvisor-metrics/69282328#69282328, I guess that's a Lens' bug.
Comment: Can you update the question to show the commands you are running to determine the pod memory, the container memory, etc?
Comment: As I wrote, I see it in Lens.
Answer: OK, I probably found an answer:
Why container memory usage is doubled in cAdvisor metrics?
Lens probably just sum all metrics for a pod (= bug).


Dataframe within Dataframe to retrieve Stock Information

Question: So I have a dataframe with Stock Symbols, Ratings, Company names, and etc. What I wanted to do was to add a new column called extra information where I could have a dataframe within a dataframe.
I know I can use the code below to get a dataframe of specific information for a company:
data <- getSymbols("TSLA", src = 'yahoo', from = as.Date(Sys.time())-7,
                  auto.assign=FALSE, verbose=TRUE)

However, I would like to get this stock information for every company when I click it's value on the Extra Information column. Any ideas?
Comment: The Quantmod package
Comment: what library are you using?
Answer: Maybe you can store the data in a list.
library(quantmod)
stock <- c("TSLA", 'QQQ')

result <- sapply(stock, getSymbols, src = 'yahoo', auto.assign = FALSE,
                 from = as.Date(Sys.time())-7, verbose=TRUE, simplify = FALSE)

Now you can access individual stocks with $ symbol.
result$TSLA
#           TSLA.Open TSLA.High TSLA.Low TSLA.Close TSLA.Volume TSLA.Adjusted
#2021-02-01    814.29    842.00   795.56     839.81    25391400        839.81
#2021-02-02    844.68    880.50   842.20     872.79    24346200        872.79
#2021-02-03    877.02    878.08   853.06     854.69    18343500        854.69
#2021-02-04    855.00    856.50   833.42     849.99    15812700        849.99
#2021-02-05    855.00    864.77   839.00     852.23    18566637        852.23

When you View the result object you get the stock symbols with their names.


XmlReader ReadString() removes '\r' from "\r\n"

Question: I have a class inheriting from IXmlSerializable. I've properly overridden the ReadXml and WriteXml methods.
I am using XmlSerializer to Serialize/Deserialize the object to an xml file.
When I Serialize the object, it is correctly writing the \r\n to the file. But when I Deserialize the object the same way, the \r has been removed and only the \n is present. I can't figure out why it is doing this.
Answer: It is called normalization and explicitly defined in the XML specification

... an XML processor must normalize line breaks in parsed entities to #xA either by translating the two-character sequence #xD #xA and any #xD that is not followed by #xA to #xA on input before parsing, ...

Some of the normalizations can be disabled via XmlTextReader.Normalization.
Comment: I'm not using `XmlTextReader`, so that's not an option. When I call `XmlSerializer.Deserialize()` and pass the object, the object's inherited method `IXmlSerializable.ReadXml(XmlReader reader)` is called. I tried to edit the reader's settings on the first line but the settings property is null and has no setter. I wanted to find a solution I could put into my `Serializer` and/or `Deserialzer` methods which handles all objects serialization. But I'm guessing my best option is to add `.Replace("\n", "\r\n")` where needed, unless that's a bad idea?
Comment: What are you using, if not `XmlTextReader`?
Comment: @Paul-SGSPfINDE If re-normalizing `"\n"` to `"\r\n"` works for you it may be reasonable option. Passing properly configured `XmlTextReader` as source is another approach... XML is surprisingly bad format to store arbitrary strings... if you *must* keep strings exactly as they are provided it may be better to treat them as binary data and Base64 encode. XML have very strict rules for characters in 0-32 range as well as surrogate pairs, so keep that in mind.
Answer: It is normal to process only '\n' for new line in text files. DOS/Windows C libraries have "text mode" which transparently convert CR-LF to LF and back.
Comment: So why does it write `\r\n` to the file? If I just read the text from the file I get the `\r\n` but if I call `XmlSerializer.Deserialize()` if reads only `\n`.
Comment: In Unix world, new line in text files is `\n` only. In Windows it is `\r\n` (CR-LF). In Mac it is CR only `\r`. But for compatibility, when you read from text file in C/C++ under Windows, all `\r\n`-s are converted to `\n`. By this way original Unix (console) programs can be compiled under DOS/Windows and they have to work. It is because C language "come" from Unix world.
Comment: Note that this question is about XML: XML have very strict rules on new line handling. While for general text operations \r\n is somewhat follow what you said they are flexible in more or less randomly produce/consue either of the sequences. Compliant XML parser on other hand limited to just exposing `\n` all the time by the specification irrespective of what is in source text. So as long as XML parser is compliant switching between *nix and Windows will not have any effect on *this* issue.
Comment: You are right but in fact XML will have the same "value" even without any new lines. All tags can be at single "line".


What is the probability of picking a card from a deck of cards that was split in half?

Question: Lets say you have a regular 52 card deck, you split it in half and you're presented one of the halves. What is the probability that the card you'll draw is the ace of spades for example?
This is kind of confusing me because the sample space/the half you're choosing from might not even have the aces of spaces if its in the other deck.
I thought of several answers, including 1/52, 1/26 but they all dont make sense because if the card isnt there.
Comment: Every card has the same probability of being drawn.  Since there are 52 cards, that common probability must be $1/52.$
Answer: Lets say that A is the event that the ace of spades is presented to you, so that it is in the right half of the deck, P(A) = 0.5
Let's be B the event that you pick the ace of space in a deck of 52, P(B) = 1/52
Because the 2 event are not independent P(A and B) = P(A)P(B|A)
Therefore P(A and B) = 0.5 * P(B|A)
P(B|A) is the probability you pick the ace of spade if it is presented to you (half a deck) so P(B|A) = 1/26
Thus P(A and B) = 0.5*1/26 = 1/52
Comment: if the card is not in the half you have the probability you pick it is 0. If it is the probability you pick it is 1/26. But because the first event is "the card is in your half" and has a prob of 0.5, it gives 1/52 as showed above
Comment: This confuses me because what if the card isnt in the half you have? How can it still be 1/52? How is there a probability for something that can never happen?
Comment: basically the important part is to realize that the event are not independent. Thus if you can pick the card, it means it was presented to you in the first place
Answer: The process of splitting the deck is irrelevant here. Assuming that the deck is randomly sorted to begin with, and you choose one card from the deck with seeing the card faces, then the probability of choosing the ace of spade is always 1/52. It doesn't matter what your process of choosing the card is --- you might just take the top card, or you could split the deck then choose randomly, or split the deck twice, or whatever --- it just doesn't matter and can't change the probability.
The fact is that all 52 cards are treated symmetrically, hence all must have the same probability of being selected.
Given your setup, you could display the probability using the law of total probability:
P(choose ace spades) =
P(choose ace spades | ace of spades is in my half of deck) x P(ace of spades is in my half of deck) +
P(choose ace spaces | ace of spades is not in my half of deck) x P(ace of spaces is not in my half of desk)
= 1/26 x 1/2 + 0 x 1/2
= 1/52.
which may clarify things, but this calculation is just for education purposes. It is already apparent from general principles what the answer must be without doing any calculations.
Comment: Exactly. (+1) One can actually take this further and think of splitting the deck in four, 13, 26 and ultimately 52 chunks to see this.


Probability of rolling a $6$ with $2$ dice (that both have a second $6$)

Question: Ok, this is a slightly weird question because its not using regular dice. Long story short, these dice have $2$ sides with the same symbol on them, so I need to know the probability of rolling AT LEAST ONE of this side with the $2$ dice. I can find the probability of landing doubles and landing exactly one. But I don't know the chance of at least one with both.
Comment: The probability of *at least one* is the probability of *exactly one* plus the probability of *exactly two*.  It is also $1$ minus the  probability of *exactly zero*
Comment: Welcome to MSE. It will be more likely that you will get an answer if you show us that you made an effort.
Answer: Basically, let the die have the markings on the faces as: $$A, A, B, C, D, E$$ The probability of rolling an $A$ is thus: $P_A=\frac13$ along with $P_B=P_C=P_D=P_E=\frac16$.
Note that $$P_{\text{At least one A}} = 1- P_{\text{No} A_{\text{Die 1}}}P_{\text{No} A_{\text{Die 2}}} $$ $$=1-\left(\frac23\right)^2=\frac59$$
Comment: You can accept the answer if it helped you by ticking the tick mark next to the answer, sir.


How to change False to True using the button

Question: I am learning React.js. And I decided to make such an application. I would like to know how to change False to True using the buttons in action. You can explain or you can an example.  Tried to change it, but nothing changed. Thank you in advance!
`
class TodoApp extends React.Component {
  constructor(props) {
    super(props);
    this.state = { items: [], text: '' };
    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
    this.handleToggleComplete = this.handleToggleComplete.bind(this);
  }

  handleChange(e) {
    this.setState({ text: e.target.value });
  }

  handleSubmit(e) {
    e.preventDefault();
    if (!this.state.text.length) {
      return;
    }
    const newItem = {
      id: this.state.items.length + 1,
      text: this.state.text,
      date: moment().format('l'),
      completed: 'false',
    }
    this.setState(state => ({
      items: state.items.concat(newItem),
      text: '',
    }));
  }

  handleToggleComplete() {
    this.setState(state => ({
      completed: !this.state.completed
    }))
  }
}

class TodoList extends React.Component {
  render() {
    return (

        {this.props.items.map(item => (

              {item.id}
              {item.text}
              {item.date}
              {item.completed}
              <button onClick={item.handleToggleComplete} className="btn btn-xs btn-success img-circle">✓</button>

          ))}

    );
  }
}

`
Comment: You need to add code so can people help you to solve. Adding a picture is not helpful.
Comment: This screenshot isn't that helpful, please post your code
Comment: @bdbdbd I added the code
Comment: @Jalal I added the code
Answer: I can not give you the solution (no code provided) so i will give you a hint.
Let's imagine  your state looks like this:
state = {
  completed: false
}

Your button can do such a thing:
button onClick={this.setState{(completed: !this.state.completed)}}

And in your table you can display the value like this:
{this.state.completed}

Maybe try to implement something similar in your code :)
Comment: If you want to have a feature of marking each item as "completed", you need to store each task as an object like item = {text:someInputValue, completed: false}. Clicking on each item should change the object's "completed" flag to "!item.completed" so it would change from false to true


Content REST view does not work because of moderation states

Question: I've created a simple view using the REST export to export all published content in JSON format, but I get this error:
Symfony\Component\Routing\Exception\RouteNotFoundException:
    Route "entity.moderation_state.canonical" does not exist.
    in Drupal\Core\Routing\RouteProvider->getRouteByName()
    (line 191 of core/lib/Drupal/Core/Routing/RouteProvider.php).

Drupal\Core\Routing\UrlGenerator->getRoute('entity.moderation_state.canonical') (Line: 285)
Drupal\Core\Routing\UrlGenerator->generateFromRoute('entity.moderation_state.canonical', Array, Array, 1) (Line: 110)
Drupal\Core\Render\MetadataBubblingUrlGenerator->generateFromRoute('entity.moderation_state.canonical', Array, Array, ) (Line: 754)
Drupal\Core\Url->toString() (Line: 291)

Moderation states have indeed been added, but I have no idea why that's throwing this kind of error...
Answer: The route is not in core. Probably it is in a contrib or custom module. You have to search for a *.routing.yml file, where it is defined and then look for an error in the yml file and then clear the cache.
You can get a complete list of all routes with drupal console:
drupal route:debug


Reqrep does not update my query string on HAPROXY 1.5.18

Question: I want my HAPROXY 1.5.18 to update a parameter in the query string (&mc=cg to &mc=cd)
I have this config :
global
    user haproxy
    group haproxy
    pidfile /var/run/haproxy.pid
    daemon

defaults
    log                 global
    mode                http
    retries             3
    balance             roundrobin
    maxconn             1000
    option              redispatch
    timeout client      10m
    timeout server      10m
    timeout queue       5s
    timeout connect     5s

    log-format [%t]\ [%ci/%ft/%b/%s]\ [%Tq/%Tw/%Tc/%Tr/%Tt]\ [%ac/%fc/%bc/%sc/%rc]\ [%sq/%bq]\ %ST\ %B\ %{+Q}r\ %hr

frontend F_4_RPA
    bind 192.168.100.200:443 ssl crt /etc/ssl/certs/app_cert.pem
    acl APP1_ACL hdr(host) -i app1.x.y
    acl APP2_ACL hdr(host) -i app2.x.y
    acl APP3_ACL hdr(host) -i app3.x.y
    use_backend B_2_APP1 if IGT_ACL
    use_backend B_2_APP2 if ADT_ACL
    use_backend B_2_APP3 if EXP_ACL

backend B_2_APP3
    reqirep ^([^\ ]*)mc=cg(.*)    \1mc=cd\2
    server app301 ...
    server app302 ...

URL example : https://app3.x.y/appse/mashup/ExposeV1/getCa?service=71cceda2-75a8-2cbf-4bc0-69e1a0a352fg&mc=cg&platform=test1
I always have an output with mc=cg instead of cd (I suppose it's never matched but why ?).
I've tested my regexp on some tester over the Net and it should work but it does not...
Any idea ? :)
Thanks
Comment: I'm sorry, did you say HAProxy 1.5.18? You know that you're 5 full versions behind the current supported version right?
Comment: Yes I know we plan to update (and maybe it will works with http-request set-query) but I need something before this update that will take weeks (holidays ...).
Comment: And waiting for Centos 8 also ...
Answer: reqirep ^([^\ ]*)(\ .*)mc=cg(.*)    \1\2mc=cd\3

Works perfectly.


Quebra de linha automatica textbox multiline form de email C#

Question: Ola pessoal me ajudem aqui pois já tentei de tudo e não deu certo, Não estou conseguindo fazer a textbox modo multiline enviar a quebra de linha por email no form de contato.
ex:
Ola
Quebra de linha
tudo bem
resultado:
Ola Quebra de linha tudo bem.

segue código abaixo.
Html
<!DOCTYPE html>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Contato</title>
    <link rel="stylesheet" type="text/css" href="Content/Site.css"/>
    <link rel="stylesheet" type="text/javascript" href="Scripts/Contato.js"/>

    <form id="formEmail" runat="server">
        <asp:Label runat="server" id="lblNome">Nome:</asp:Label>

        <asp:TextBox  runat="server" ID="text_nome"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="text_nome" ErrorMessage="Obrigatório">*</asp:RequiredFieldValidator>

        <asp:Label runat="server" ID="lblemail">Email</asp:Label>

        <asp:TextBox runat="server" ID="text_email"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="text_email" ErrorMessage="Obrigatório">*</asp:RequiredFieldValidator>

        <asp:Label runat="server" ID="subject">Assunto</asp:Label>

        <asp:TextBox runat="server" ID="text_assunto"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="text_assunto" ErrorMessage="Obrigatório">*</asp:RequiredFieldValidator>

        <asp:Label runat="server" ID="lblMensagem">lblMensagem</asp:Label>

        <asp:TextBox runat="server" ID="text_mensagem" TextMode="MultiLine" Height="161px" Width="355px" ></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="text_mensagem" ErrorMessage="Obrigatório">*</asp:RequiredFieldValidator>

        <asp:Label runat="server" ID="Label1">Label</asp:Label>

        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />

        <asp:Button runat="server" ID="jbEnviar" OnClick="jbEnviar_Click" Width="50px" Text="Enviar"/>
    </form>

Code Behind
protected void jbEnviar_Click(object sender, EventArgs e)
    {
        MailMessage mailMessage = new MailMessage();
        // Endereco que irá aparecer no e-mail do usuário
        mailMessage.From = new MailAddress(text_email.Text);
        // Destinatarios do e-mail, para incluir mais de um basta separar por ponto e virgula
        mailMessage.To.Add("email@example.com");
        mailMessage.Subject = text_assunto.Text;
        mailMessage.IsBodyHtml = true;
        text_mensagem.Text.Replace("\n", "
");

        // Conteudo do corpo do e-mail
        mailMessage.Body = text_mensagem.Text;
        mailMessage.Priority = MailPriority.High;
        //smtp do e-mail que irá enviar
        SmtpClient smtpClient = new SmtpClient();
        smtpClient.EnableSsl = true;
        smtpClient.Host = "smtp.gmail.com";
        smtpClient.Port = 587;

        smtpClient.UseDefaultCredentials = false;
        //credenciais da conta que utilizará para enviar o e-mail
        smtpClient.Credentials = new
        NetworkCredential("email@example.com", "senha");

        smtpClient.Send(mailMessage);
    }

Comment: desculpem sou novo kkk
Comment: Wellington não sei se ajuda, mas tente colocar todos os textos dentro de tags, tipo asism: `texto`. o P é um elemento de bloco e teoricamente deveria jogar o próximo P para linha de baixo.
Answer: Segue um tratamento que já utilizei algumas vezes.
    string conteudoTexto =  text_mensagem.Text.Replace(System.Environment.NewLine, "
");

    // Conteudo do corpo do e-mail
    mailMessage.Body = conteudoTexto;

Comment: Deu Certo.valeu mano vc e o cara kkkk


How to ensure that a SSH and HTTPs-url of a repo refer to same git repository

Question: Our platform enables creating applications and connecting them to Git repositories to manage them. We do support GitHub, Azure, Bitbucket etc. Let's suppose we have an application linked to a GitHub repo using HTTPs. We would like to provide the capability to the users to switch to SSH authentication at any point of time, which requires the URL to be changed. This could mean that the user can by mistake enter a URL of a different repository and link to it. How do we prevent this ? Is there a way to find out that the repository pointed by the previous url and the changed url is the same irrespective of the Git Repository Management System used?
Answer: Don't let the user specify a new URL: modify the existing URL.
Consider a fictional Github URL:
https://github.com/jdoe/project.git

To replace that with an SSH URL, you simply replace https://github.com/ with firstname.lastname@example.com:.
Similar, though different, mappings would need to be coded for each supported Git provider. For example, on Azure it looks like only the user name U and the project name P is important; they can be extracted from one type of URL and used to construct another type of URL.

HTTP: http://@dev.azure.com/<USER>/<PROJECT>/_git/<PROJECT>
SSH: firstname.lastname@example.com:v3/<USER>/<PROJECT>/<PROJECT>

Regardless of the provider, the user need only provide a URL once; you will handle conversions from one scheme to another behind the scenes.
Comment: Thanks for your response. That works for a repository in github.com. But in case of azure the url looks like below :

https://firstname.lastname@example.com/kt/mast_gs_lm/_git/mast_gs_lm and ssh looks like email@example.com:v3/kt/mast_gs_lm/mast_gs_lm and similarly it differs for bitbucket. Given that we are supporting multiple Git repo management systems, how do we make sure that we map to the right repo ?
Comment: There's no universal mapping that will support any Git provider (because there is no standard that says how they must design their URLs), but for a given provider, it should be straightforward to convert URLs with different schemes to one another.
Comment: Yes, so given one http/ssh url, is it possible to get the other url from the remote ? That would save us from conversions for independent providers.
Comment: That would again depend on the provider. Nothing in Git itself says anything about what URLs may or may not exist for any given repository.


Adjust probabilities to make it equal to 1

Question: Is there a way to normalize the given probabilities? Let's say for example I have this probability for the following words:
<code>                              I    am     the   best   today
</code>
$$1/5 + 1/5 + 1/5 + 1/5 + 1/5 = 1$$
Given that people typed the word
<code>am
</code>
50% of the time, the distribution would adjust to
$$ 1/5 + 1/2 + 1/5 + 1/5 + 1/5$$
It is obvious that the equation wouldn't be equal to $1$. How can I force the equation to give a distribution wherein the probability of am would stay at $1/2$ while the others would adjust to make the equation be equal to $0$?
Answer: As I understand you correctlly, you want "am" to have 0.5 probability, keep relations between other probabilities and make all probabilities sum to 1. Am I right?
If so, you should first normalize the four probabilities you want to normalize to make them sum to 1. You can do this by dividing them by their sum (0.2/0.8 and all four probabilities would be 0.25, 0.25, 0.25, 0.25).
Then you can compute, that all other probabilities except probability of "am" should sum to 0.5 (because 1 - 0.5). Then you should multiplicate every of the remaining probabilities by this 0.5.
So result would be 0.25*0.5=0.125 and all probabilities would be: 0.125, 0.5, 0.125, 0.125, 0.125.


Can I avoid creating a new revision of every attached field upon entity save?

Question: I have created a custom entity with several properties and several attached fields.
When I load a instance of my custom entity, update a property of the entity (e.g UID) and save it a new revision of the entity is created, but also a new revision of every attached field is created.
To avoid saving lots of redundant data I only really want to create a new revision of an attached field if the data in that field has changed.
I've noticed that this same behavior is exhibited by core node objects, but is still not really desirable.
My function which currently saves my entity looks like this:
<code>/**
* Saves a emtr safe check to the database.
*
* @param $emtr_safe_check
*   The emtr_safe_check object.
*/
function emtr_safe_check_save(EMTRSafeCheck $emtr_safe_check) {

    $is_new = isset($emtr_safe_check->is_new) ? $emtr_safe_check->is_new : false;

    // always make a new revision
    $emtr_safe_check->is_new_revision = TRUE;
    $emtr_safe_check->save();

    if($is_new) {
        // now we have the new emtr safe check id lets save the attached fields
        field_attach_insert('emtr_safe_check', $emtr_safe_check);
    } else {
        // This is where my attached fields are saved
        // Can I do something clever here to avoid creating redundant revisions?
        field_attach_update('emtr_safe_check', $emtr_safe_check);
    }

    return $emtr_safe_check;
}
</code>
Comment: There was an issue for this in D7 queue: [Deeply decouple revisions from Entity API and Node module](https://drupal.org/node/1279440). But it was change to D8 and the discussion has moved on to a new issue in D8: [Reconsider the separate field revision data tables](https://drupal.org/node/2083451). So, I think the simple answer to your question is "no". David Rothstein suggests that it might be possible to rewrite the field_sql_storage module as contrib that does this differently, but I'm pretty sure there hasn't been any meaningful work done to that end.
Comment: Interesting reading. I noticed by the end of the first thread the issue had been moved to the D9 queue - that really is a no! Looks like the options are stick with it how it is or re-write field_sql_storage.
Comment: I don't think you can. An alternative would be not to use fields with your entity. (Does not help much!!?)
Comment: I just remembered coming across [this issue (Beans need revisions)](https://drupal.org/node/1335494) when writing a small helper module that [hides the bean revision field](https://github.com/balsama/beannorev). That seemed to indicate that beans have the ability to be saved without creating a revision (as it was the original default). I just ran a few tests and can confirm that if you uncheck the "Create new revision" checkbox, no revision rows are added to the DB. I haven't done any further investigation, but for now, it seems my answer has changed to "Yes, it **seems** to be possible".
Comment: I posted an answer below, does anyone think this could work or it's a bad idea?
Answer: I have looked around and found one HACKY solution. I think it probably has some serious side effects that you may be able to handle with custom code and db queries. This is definitely not a generic solution.
I did my test on the node entity and every thing worked fine in my 5 min test case. Here is what I did:
<code>function playground_node_presave($node){
  dpm($node);
  // do a query here and check if the value is in the field_revision_table is
  // equal to the value on the node/entity object.
  unset($node->field_cookies);
  dpm($node);
  // The node will be saved without changing the value of the field and without creating
  // creating a new entry in the field_revision_table.
}
</code>


Equivalency of probabilities

Question: *In a hospital, the probability that a patient has Disease M is $0.003$. A test is carried out for Disease M. This test has a probability p of giving a positive result if patient has Disease M and the same probability p of giving a negative result if patient does not have Disease M. A patient is given the test.
Taking p to be $0.897$, find the probability that the result of the test is positive.
This problem can be very easily solved with the aid of a tree diagram. What I have a problem with is this:
To find the p(test positive), I simply take $0.003p + 0.997(1-p)$, and of course I'll then use $p = 0.897$. I know this in an extremely mechanistic manner and I feel like I don't truly understand it intuitively. What I'm finding now is p(patient has disease and test positive) + p(patient does not have disease and test positive). Why does this automatically give me p(test positive)? Why are they equivalent? Can somebody explain in a way which would allow me to understand this intuitively? Ridiculous as it may sound, why can't I just say, the probability of the test being positive is simply p + (1-p), i.e. disregarding whether the patient actually has the disease or not? I mean, the question asks for the probability of the test being positive - it didn't ask about the status of the patient!
Answer: I'm not sure whether or not this will help you to understand, but I will give it a try...

First, split the given scenario into disjoint events:

The patient is sick and the test is positive
The patient is not sick and the test is positive
The patient is sick and the test is not positive
The patient is not sick and the test is not positive

Then, find the probabilities of the desired events:

The patient is sick $\color\red{\text{and}}$ the test is positive: $(0.003)\color\red\times(0.897)$
The patient is not sick $\color\red{\text{and}}$ the test is positive: $(1-0.003)\color\red\times(1-0.897)$

Finally, find the probability of the unified event:

The 1st event $\color\green{\text{or}}$ the 2nd event: $(0.003)\times(0.897)\color\green+(1-0.003)\times(1-0.897)$
Answer: "[T]he probability that a patient has Disease M is $0.003$." This means that (on average) out of every $1000$ people, $3$ have Disease M and $997$ do not have Disease M.
"This test has a probability $p$ of giving a positive result if patient has Disease M and the same probability $p$ of giving a negative result if patient does not have Disease M. A patient is given the test. Taking $p$ to be $0.897$, ... ." This is actually two separate statements, one about people who have the disease and one about about people who don't:

Out of every $1000$ people who do have Disease M, on average $897$ will test positive and $103$ will test negative.
Out of every $1000$ people who do not have Disease M, on average $103$ will test positive and $897$ will test negative.

Now suppose we administer this test to one million people.
The expected results are:
Of the people tested, $3000$ have the disease. Of those $3000$ people,
$2691$ ($897$ out of every thousand) tested positive
and $309$ ($103$ out of every thousand) tested negative.
Of the people tested, $997000$ do not have the disease.
Of those $997000$ people,
$102691$ ($103$ out of every thousand) tested positive
and $894309$ ($897$ out of every thousand) tested negative.
That's four different groups of people, and if we knew exactly who had
the disease and who did not, we could put each person's name on one
of four lists according to which group they belonged to.
But the question is asking us just to list the people who tested positive.
There will be $2691$ ill-and-the-test-detected-it people on that list,
and $102691$ healthy-but-tested-positive-anyway people,
for a total of $105382$ people with positive tests.
In summary, given the numbers in the problem statement
(probability $0.003$ to have the disease, $p=0.897$), we have

$1000000 \times 0.003 \times 0.897$ ill-and-the-test-detected-it people, and
$1000000 \times 0.997 \times (1 - 0.897)$ healthy-but-tested-positive-anyway people,

for a total of
$1000000 \times (0.003 \times 0.897 + 0.997 \times (1 - 0.897))$
positive tests.
If we went instead with the formula $p + (1 - p)$,
notice that $p + (1 - p) = 1$, which tells us that everyone tests positive!
To put it in much less formal terms, since the test has a much higher
percentage of positive results ($89.7\%$) for sick people than
for healthy people ($10.3\%$),
shouldn't we intuitively believe that the fact of a person being
sick or healthy has some effect on whether they test positive?
And that if a lot more people in our population were sick,
we'd have more positive results?
Comment: If you contrive arbitrary formulas that aren't answering the original question, to make sense of them we might just have to contrive arbitrary variations on the question. For any patient, the test has only two possible outcomes, with probabilities $p$ and $1-p$, so $p + (1-p)$ is the probability that you get an outcome (positive _or_ negative) when you give the test; which of course _always_ happens. If you test two healthy people, the probability they get different test results is $p(1-p)$. The possible interpretations are limited only by your patience for contriving them.
Answer:
What I'm finding now is p(patient has disease and test positive) +
  p(patient does not have disease and test positive). Why does this
  automatically give me p(test positive)

Let $B$ the event a patient is diseased-$\overline B$ the converse event.
And $A$ is the event that the test is positive.
You are asking why
$=P(A\cap B)+P(A\cap \overline B)=P(A)$
To see that this is true you can draw a venn diagram:

1) I think you can identify  $A \cap B$.
2) To get $A\cap \overline B$ you have to mark $A$ first. I have marked it with green lines. And $\overline B$ is the area marked with black lines. The intersection of $A$ and $\overline B$ is the area with green and black lines. You can say it is the area $A$ without the intersection of $A$ and $B$.
You have to sum up the areas of 1) and 2) to get $A$. I hope it is comprehensible.

Using the equation of conditional probability $P(A\cap B)+P(A\cap \overline B)$ is equal to
$P(B)\cdot P(A|B)+P(\overline B)\cdot P(A|\overline B)=P(A)$
with $P(B)=0.003, P(\overline B)=1-P(B)=1-0.003, P(A|B)=0.897$ and
$P(A|\overline B)=1-P(\overline A|\overline B)=1-0.897$
Thus $P(A)=0.003\cdot 0.897+(1-0.003)\cdot (1-0.897)$
Comment: @Charlz97 You are welcome. Could you elaborate or reformulate your question ? I have to admit I don´t really know what do you mean or you referring to.
Comment: Oops sorry thought I could delete the whole comment thread. I worked out what I was trying to ask and yeah its kinda nonsensical. But thanks anyways!
Comment: @Charlz97 It would be nice if you would accept my answer, especially because a troll has downvoted my answer.

Equivalency of probabilities


How to get path to the vim being executed in vimscript

Question: For example, in directory /abc the command vim def/my.txt would edit file /abc/def/my.txt.
I want to get the path /abc in my vim plugin script, but I don't know which function can do it.
I have read related articles, like
(Please add http:// to following items if you want to access, I don't have enough reputation to post more than 2 links o(╯□╰)o ):

learnvimscriptthehardway.stevelosh.com/chapters/40.html
vim.wikia.com/wiki/Get_the_name_of_the_current_file
How to get path to the current vimscript being executed

But useless.
Thanks.
==============================
I noticed at http://vim.wikia.com/wiki/Get_the_name_of_the_current_file, it said:
:echo @%    def/my.txt
I thought I found the hope.
Because I can get /abc by minus def/my.txt from full path.
But I tested above command in my vim environment, it didn't work. It just print my.txt.
Comment: I am not sure which path do you want to get. you want to get usr's current dir? (under which dir the user has started vim?) vim's `:pwd and getcwd()` will give you that, as Ingo answered. However, user can in vim execute commands, which leading to the dir gets changed, like `:cd ..` or with `autochdir option`. in this case, you won't get that dir any more.  When your plugin function will be triggered?
Comment: I made commands in my vim plugin to call the path function, the design is that user need execute the commands once they launch "vim" or "vim some_path_to_file". So :cd .. will not have chance to impact it but autochdir maybe. But anyway, it doesn't matter to my logic, I just want to get the current dir where user execute "vim" with or without file name arguments. For more details, I explained why I found pwd and getcwd() not work in my cases. Thanks for your asking.
Answer: I think you're looking for the :pwd command / getcwd() function.
When you edit def/my.txt from /abc, the latter is your current directory, and all files are addressed relative to it. (Unless you have something like :set autochdir.)
For dealing with file paths, the fnamemodify() function is also very helpful; e.g. to turn filespecs into absolute ones (:p argument), or to cut off head, tail, or file extension.
Comment: Thanks. But I've found :pwd and getcwd() not work in my case. If I am at /abc/, then run "vim def/my.txt", then :pwd and getcwd() all return /abc/dev/, that's not my expectation. But if I just run "vim" at /abc/, then it will return /abc. Generally speaking, I want to get the dir where user run "vim" or "vim the_path_to_file".
Comment: Do you have the mentioned `'autochdir'`, or an equivalent `:autocmd`?! Because Vim doesn't normally behave that way. In any way, you could store Vim's CWD during startup by putting this into your `~/.vimrc`: `let g:cwd = getcwd()`.
Comment: And I've tried a few options with fnamemodify(), found nothing useful:( Yes! Good point @Ingo Karkat! I will examine my ~/.vimrc. I almost there :) Thanks a lot:)
Comment: Oh my god~~~~~~~~~~~~~~~~~You're right ::>_<::  There is "set autochdir" in it (●-●) Thanks a lot Ingo!
Comment: `:pwd` does not work for me but `:!pwd` does. However, I don't know how to execute the `getcwd()` function.


Learning a stochastic pattern in a count TS using DeepAR

Question: I am trying to the learn the following pattern of count time series of vehicle demand every hour.

The count time series is generated from a negative binomial distribution with parameters n = 9 and p = 0.5 every 4 hours. The interval in-between has magnitude = 0.
I would like to know if I can use this paper, Deep Autoregressive recurrent neural network to learn this :
Please see the code below:
https://github.com/JosePeeterson/demand_prediction
simply run main.py to test Deep autoregression. In the test output I can see that the period of 4 hours is not being learnt as well as correct mean prediction output at each time step.
Is there any count time series data that is known to work with this code?
Comment: OK. From what I know of DeepAR, it should definitely be able to capture such multiple seasonalities, given enough data, which it sounds you have. [Of course the forecasts will vary less than the observations](https://stats.meta.stackexchange.com/q/5567/1352), but have you looked at [seasonplots](https://otexts.com/fpp3/seasonal-plots.html) of DeepAR's forecasts with these seasonalities, to see whether the forecasts at least show *some* seasonal patterns?
Comment: What do you mean by "parameters n = 9 and p = 0.5 every 4 hours"? Is your data in buckets of length 4 hours? If so, what should the DeepAR learn, since your predictions will then again be for 4-hour-buckets?
Comment: every 4 hours I sample from a nbinom(9,0.5) the 3 hours in-between is all zeros. The DeepAR should learn the temporal dependencies i.e. period of the spikes as well as the the distribution from which this spike comes from. The prediction can be for the next time step. It should not learn absolute positions but given a window of say 20 time steps it should predict the value of the 21st step as sample from nbinom distribution if it happens to be the 4th step after 3 zeros or zero if it is in-between spikes.
Comment: Ah. Why do you do that? And why do you want the DeepAR to learn that piece of information? If you *know* something, it's always much better to pre- and postprocess data, rather than giving your system a lot of rope and hope it doesn't hang itself with it.
Comment: In the real data there will be many periods and each one will come from a different parameter distrubiton so this information is not known apriori. we just know that the demand comes from a negative binomial distribuion.
Comment: So you won't know that there is a (potentially) nonzero data point only every four periods, and periods 1-3 out of every four will be zero? If so, why do you test DeepAR with synthetic data that does exhibit this regularity? If your real data does not exhibit this, then it's not relevant DeepAR does not detect it, is it? Also, how do you **know** real demand is negbin? Typically, a distribution could be a good *description* of data, but data truly does not really follow a distribution.
Comment: The ACF plot of my count time series data has significant peaks for 24, 36,48, 168 hours. I want to capture this regularity. I wish to have the DeepAR to learn 168 distributions which then be used for predictions within any 168 steps. Does it make sense? For the distribution let's just assume the data comes from there as a starting point.
Comment: Thanks for your inputs @StephanKolassa I shall take a look.
Answer: I have managed to capture this pattern using pytorch DeepAR for two nbinom values (n=9,p=0.5) and (n=4,p=0.75) with period of 8 hours for each. The two signals are interleaved like below.

Run My_demo.ipynb to see the prediction of means of the two frequencies in the following repo.
https://github.com/JosePeeterson/2_freq_nbinom_LSTM/tree/master


Interpreting PCA results

Question: I am running a PCA for quality in a water resource. I have 15 original variables. Running the PCA using Minitab, it turned out that the first PC is responsible for 99.7% of the variation. Looking at the eigenvectors, all the original values have almost the same correlation value with PC1 (about 0.25). What does that mean? Note: I tried to use the log of the data, and the results were very much the same.
Comment: Water quality data tend to be very highly intercorrelated: the first PC of the *raw* data typically accounts for 90+% of all variation. For analyzing chemical composition, one usually bases the PCA on the log data and/or on the correlation matrix and often focuses on the PCs *after* the first.  (Another approach is to standardize the concentrations as percentages of the total in each sample: this can work well provided few samples have missing values.)  If you got the same extreme results with the logarithms, that could be due to how nondetects or low-level values have been processed.
Comment: Did you set "Type of matrix" = Covariance?
Comment: Thanks Whuber.
I got the same extreme results using the log scale with very slight difference. I will also try your suggestion and let you know.
Answer: It means that there is one very large component and that all the variables are roughly equal in its determination.
Since you haven't told us your variables, it's hard to say more, but something similar could happen if your 15 variables were all measurements of length of different parts of a human body. In this case, overall size of the person would be highly correlated to all the inidividual parts.
Comment: That was my thinking, but I was worried since in all researches I have read they use a correlation value >0.5 to consider. and since all my correlation values were <0.5, I did not know how to use it.

My variables are 15 stations that measure water quality along its path.

Interpreting PCA results