Is Jaccard similarity/distance suitable for non-binary, quantitative data?

Question: I have a dataset with each row a country and 10 columns with numerical features like GDP,Electrcity consumption, GNI etc. I am trying to use distance metrics to find similarity between the countries and ultimately cluster them. I have tried quite a few distance metrics like Euclidean, Minkowski, canberra, jaccard etc. In case of jaccard (implementation in pdist in scipy) I don't think the resulting dissimilarity matrix makes sense as I have all 1's in the matrix other than 0 along diagonal. I read more on jaccard and it seems to use set union and intersection in the computation. So am I wrong to apply it in case of continous variables? I have a read a lot on jaccard and it seems to be useful only when data is represented in terms of 0/1 (present/absent). Please guide  :)
Comment: The tl;dr answer is: Don't use it for continuous data. You are very right, it doesn't make sense.
Answer: Jaccard similarity is, in general, valid for any pair of sets https://en.wikipedia.org/wiki/Jaccard_index
Given two sets $A$ and $B$:
$$
J=\frac{|A \cap B|}{|A \cup B|}
$$
No requirement is given about the elements of $A$ and $B$. In general, it can be seen as the relative (Lebesgue) measure, between the intersection and the union of the two sets. Under this interpretation, it may be applied to all pairs of elements of a measurable space $X$. When $X$ is a Borel space, with $\sigma$-algebra $\Sigma$, the measure can be also probabilistic:
$$
J=\frac{\mu(A \cap B)}{\mu(A \cup B)}
$$
given that $A, B \in \Sigma$.
Comment: Sorry I am not clear with this answer. So sets A is 1 row in my ds like 'USA':{0.23,1.3,5.67,1.06} set B is another row 'AR':{1.33,0.4,0.67,5.5} here the set element sare continous features like GDP,GNI, etc as said in my question above. So when we calculate union of A and B or intersection. There will never be any elements in common as these are continous features. So how does jaccard apply in my case.
Comment: The problem is that the Jaccard doesn't capture the similarity you are trying to estimate. As you asked for the applicability of the Jaccard, the answer is yes, it can be applied to any pair of sets.
Comment: You need another similar measure.
Answer: Originally, Jaccard similarity is defined on binary data only. However, its idea (as correctly displayed by @ping in their answer) could be attempted to extend over to quantitative (scale) data. In many sources, Ruzicka similarity is being seen as such equivalent of Jaccard. A screenshot from the document of my SPSS macro <code>!PROXQNT</code> (can be found on my web-page, "Various proximities" collection):

Besides this, one should also keep in mind that in case of binary data, Jaccard sim = Ruzicka sim (= 1 - Soergel dis) = Similarity ratio = Ellenberg sim.
Therefore per backward logic, Similarity ratio and Ellenberg similarity can be considered too, as other candidates for the equivalence towards Jaccard.
Comment: From the formula, clearly, it cannot exceed 1. The data must be nonnegative.
Comment: I think it won't make sense with negative values. Similarity ratio however is suitable with data of any sign. Similarity ratio has some kinship with correlation coef., see https://stats.stackexchange.com/a/22520/3277
Comment: Hi thank you so much for this detailed explanation. I tried to use the soergel distance formula in python to calculate pairwise distances for my matrix. However the distances are not in the range of 0,1. I read somewhere that Soergel distance must be between 0 and 1. Is this correct? Thanks
Comment: I checked an implementation of soergel distance in R, it also won't give a value b/w 0 and 1. So now I am confused. The input are 2 numeric vectors x and y. [link]https://rdrr.io/cran/philentropy/man/soergel.html I just realised my data has some negative values due to scaling. Is this alright? Or is there a strict need for non negative values for soergel?
Comment: Thank you. I didnt know that some metrics don't make sense if we have negative values in dataset. As i used manhattan,euclidean,canberra etc on this data. Is there any good resource which lists what kind of data suits what distance metric. I have tried to look for this however most just give a formula and not much else. Thanks


Multiple relations from many entities to one entitiy in SQL Server (EF core)

Question: Can anybody help me? I want to set constraint to my database for example:

First entity is Triangle (Triangle_Id, Name, Side_size)
Second entity is Square (Square_Id, Name, Side_size)
Third entity is Area (Area_Id, ObjectId, Area_value)
Fourth entity is Circle (Circle_Id, Name, Radius)

How can I add constraints from entities Triangle and Square to Area that I am unable to write any other type of objects in ObjectId column except triangle or square?
I tried to write come FK constraints, but have had an error.

FK_Area_Triangle_ObjectId (area_ObjectId == triangle_Id)
FK_Area_Square_ObjectId (area_ObjectId == square_Id)
Answer: You cannot have two different foreign key constraints on same column, but there are some options as answered here: Foreign Key to multiple tables.

You could simply create two columns in Area, SquareId and TriangleId, and have nullable Foreign Keys to each table. You can also add a constraint, that exactly one of these two columns has to be filled.
Model an entity that acts as a base for both Square and Triangle, and have Area refer to that entity
Comment: Thanks for the advice, but in future, there will be more than 10 entities, and your solution doesn't fit well for me. The example was simplified, the real table has a lot of entities and common values, that's why I'm looking for a method to store only existing values in common table using ObjectId as key.
Answer: Foreign key is defined between two tables. It cannot be made between a table and a view, which would solve your task directly.
What you can do, if to create a scalar function checking for records in both tables and returning 1 if found and 0, if not. And then put a constraint that the function should be 1.
Comment: Thanks for the advice, but your solution doesn't fit well for me. But your answer helped me to find one more problem in my solution (connected with transactions). Thanks a lot!


COV(X,Y) and X,Y Dependency

Question: I know there are already several posts about the relationship between covariance and independence in this forum but I couldn't find the answer to the issue bugging me on those posts.
Let me firstly say I know that:
(1) independence between RVs means covariance = 0, but covariance = 0 does not necessarily mean independency between RVs.
(2) Pearson's correlation coefficient (corrcoef) detects linear dependencies between RVs, so non-linear dependencies might well yield covariance = 0 (a simple example is the parabola one, when RVs are X and Y = X^2).
Now, let X and Y be RVs, where X = A + B and Y = A - B; Here, A and B are also RVs, that could be either dependent and independent, and with zero-mean, variance = 1.
What I want to know is whether X and Y are independent (or dependent).
At first glance I am inclined to say X and Y are dependent because both are functions of the same A and B. I would also say that their relationship seems linear because Y = X - 2B. What is making me confused is that COV(X,Y) = 0, so, corrcoef = 0, as can be seen below.
COV(X,Y) = E[(X - E[X])(Y - E[Y])] = E[XY] = E[(A+B)(A-B)] = E[A^2 - B^2] = E[A^2] - E[B^2] = 1 - 1 = 0
or
COV(A+B,A-B) = COV(A,A) + COV(A,-B) + COV(B,A) + COV(B,-B) = VAR(A) - COV(A,B) + COV(A,B) - VAR(B) = 1 - COV(A,B) + COV(A,B) - 1 = 0
Wouldn't COV(X,Y) = 0 mean that X and Y are either independent or dependent though following a non-linear relationship? But they don't seem independent and they don't seem to have a non-linear relationship. They seem to have a linear relationship, but in such case covariance should be different from 0.
What is the issue here?  I would be glad if someone could shed some light on that.
Comment: If you want a very silly example you can take $A = 0$ and $B=0$, i.e. $A,B$ are "random" variables which always produce the constant value of zero. Then $X=A+B=0$ and $Y = A-B = 0$ also. You can then check that $X$ and $Y$ are independent, indeed, $P(X = x, Y = y) = 0$ unless $x,y = 0$ in which case $P(X=0,Y=0) = 1$, i.e. it is equal to the product $P(X=0)P(Y=0)$.
Comment: @NicolasBourbaki Thank you for your reply. Indeed you pointed out a case in which X and Y are independent. In fact, elaborating a bit on your example, I think that any constant RVs A,B, would result in X,Y being independent... For instance, if A, B are "RVs" that always produce A = B = 2, then (=,=)=0  unless =4,=0 in which case (=4,=0)=1, i.e. it is equal to the product (=4)(=0)= 1x1 = 1. So, how should I interprete your answer, are you saying that X and Y are, in general, dependent and providing one exceptional case (constant RVs) in which they become independent?
Answer:
Wouldn't COV(X,Y) = 0 mean that X and Y are either independent or dependent though following a non-linear relationship?

You answered this yourself

but covariance = 0 does not necessarily mean independency between RVs

An example of a case where X,Y are independent is when $A,B$ are i.i.d normal distributed variables.
An example of a case where X,Y are dependent is when $A,B$ have a joint distribution that is spherically symmetric but which is not a normal distribution.
Below are example plots for the two situations. Covariance is zero for $X$ and $Y$ (and also for $A$ and $B$), and in the first case there is independence but in the second case there is no independence.

In these examples I chose spherical symmetrical joint distributions since for that case the transformations $A+B$ and $A-B$ are just the same as a rotation (and a scaling). The $X$ and $Y$ will have the same dependence as the $A$ and $B$.
Comment: Thanks a lot for the answer and illustrations. So, you are saying that X and Y could be either dependent or independent, as a result of A and B. Sorry, could you clarify why X and Y would be independent if A and B are i.i.d.? Y = X - 2B, so they look dependent to me regardless of A and B relationship.  And, the the real problem I am having is that Y = X - 2B seems a "linear" relationship, which should have been detected by the Pearson corrcoef, which would result in COV(X,Y) not being 0. Is Y = X - 2B a non-linear dependency?
Comment: Or more precisely, are you saying that Y = X - 2B does not mean dependency when A,B are i.i.d; and Y = X - 2B means non-linear dependency, for other types of A,B? Sorry, but I don't quite understand.
Comment: @Robb Say $Y$ and $X$ are independent, and we define $2B = X - Y$ then we can write $Y = X - 2B$, but just that equation doesn't make $Y$ and $X$ dependent.  The expression can be rewritten as $$Y = X - 2B = X - (X-Y) = Y$$ Because $B$ and $X$ are dependent the seamingly dependence of $Y$ on $X$ cancels out. You have an expression with an $X$ on the one side but there is another $-X$ hidden in there in the $-2B$.
Comment: Thank you. I got that Y= X - 2B (resultant from X= A+B; Y= A-B) does not necessarily mean X and Y are dependent by the reason you explained in your comment. But, according to your answer, in case A,B are non i.i.d, then X,Y are dependent. And in such case, the dependency should be given by Y = X-2B. Then, the question becomes: is Y = X-2B a non-linear dependency? I looks very linear to me, but on the other hand COV(X,Y) = 0, as shown above in my post, means X and Y are not linearly dependent. Is there something "under the hood" that makes Y = X - 2B non-linear and that I am missing?
Comment: @Robb *"But, according to your answer, in case A,B are non i.i.d, then X,Y are dependent."* That's only in my example, I am not saying that this must generally be the case. Example let U,V be two iid dice rolls. Let A = 0.5(U+V) and B = 0.5(U-V). Then A and B are not independent and neither identical, but you do have that A+B and A-B are iid.
Comment: *"Then, the question becomes: is Y = X-2B a non-linear dependency? I looks very linear to me, but on the other hand COV(X,Y) = 0,"* This dependency does not mean that Y and X is dependent, it *only* means that Y is dependent on the *combination* X-2B. So COV(X,Y) = 0 makes very much sense because X and Y are not only not a linear dependency, but not *any* dependency.
Comment: Going back to the dice rolls. Let Z = U+V where U and V are independent dice rolls. Then U = Z-V. The variable U is independent from V but not from Z and V together. If I tell you V and Z then you can know what the value is of U. If you compute the covariance then you get COV(U, Z-V)=1
Comment: correction of the last sentence, the correlation is equal to 1, the covariance depends on the values of the dice outcomes.
Comment: "A = 0.5(U+V) and B = 0.5(U-V). Then A and B are not independent and neither identical, but you do have that A+B and A-B are iid. "  Thanks, it became clear to me that X=A+B, Y=A-B can be iid although A,B are not Gaussian iid (e.g., uniform iid from dice rolls). But, although A,B you exemplified are certainly "not identical", following the same logic you presented, I think we cannot say A,B are "not independent". A,B could well be "independent" if U,V have the same structure U = 0.5(M+N), V = 0.5(M-N), where M,N are iid too. Then, U+V=M, U-V=N, making A,B iid, and in turn X,Y are also iid.
Comment: Your second comment intrigued me... "So COV(X,Y) = 0 makes very much sense because X and Y are not only not a linear dependency, but not any dependency". By "not any dependency" do you mean that X,Y are then independent? But I had thought that X=A+B, Y=A-B would be independent (iid) if and only if A,B are also iid. Please, note that in my original post the assumption was that A,B are RVs that could be either dependent or independent. I am clear already that A,B iid leads to X,Y iid. But I am still thinking that A,B being dependent leads to X,Y also being dependent. Am I right on that?
Comment: @Robb $A$ and $B$ do not need to be iid in order for $X$ and $Y$ to be independent. In the comments I gave an example after the text *"That's only in my example, I am not saying that this must generally be the case...."*
Comment: I am good with your 3rd comment.

COV(X,Y) and X,Y Dependency


camelCase ctrl left and right for titanium studio?

Question: so i'm using titanium studio, and i've noticed that it, like jetBrains, comes pre-packaged with the idea that ctrl-left or ctrl-right on a word goes to the beginning or end of that word, and not to the "camel cased" sub-part.
Ugh, here, an example:
|ThisIsCool = new ArrayList();

Assuming that the "pipe" character is the cursor, if i hit ctrl-right once, i'd like it to go to:
This|IsCool = new ArrayList();

And again:
ThisIs|Cool = new ArrayList();

instead, in Titanium studio it just jumps to the = sign.
How do i get Titanium studio to behave right? I assume it is a setting of some sort?
Answer: The key bindings are located in Window->Perferences->Keys.
I experimented with some of the options, but Next Word was the closest I could find that would maybe accomplish what you wanted.  When I bound that, it just did exactly what the default CTRL+Right Arrow was already doing.  There is no 'camel' or 'cap' (for capital letter).  It doesn't appear to me that this function is built into the IDE.  If you look at that section, perhaps something in there will catch your eye and get that working for you.
Otherwise, I would probably hit up the Appcelerator specific forums and perhaps get a developer there to notice it.
Comment: yeah you're right "impossible" is the answer - thanks for trying though!


Dash was not successfully imported. Make sure you don't have a file named 'dash.py' in your current directory

Question: This error showed up randomly after I had been running plotly-dash scripts for weeks.
"Dash was not successfully imported. Make sure you don't have a file named 'dash.py' in your current directory"

I've uninstalled and reinstalled dash (didn't work)
I found a file named dash.py in a Dash file but when I change the name or remove it, it causes other errors to show (didn't work )
"It sounds like something is wrong with the installation of the Dash package. What does the contents of that init.py look like? It should be this:

https://github.com/plotly/dash/blob/master/dash/init.py" I did this too and (didn't work)
Answer: There are two possibilities to solve this:

Check if there is a file 'test.py' in your scripts' folder. Change its name to something else.
Down version of Dash to 1.12.0 or below
(credit: https://github.com/plotly/dash/issues/1143)
Comment: renaming a local file in my root source directory from `test.py` (to `tests.py`) worked for me


Creating sections within a RecyclerView

Question: I have worked with listviews for some time now and as I began to understand them, they come out with recyclerview.  I have a simple working example containing all of the items.  I would like to create sections within the recyclerview using the same layout.  For example, each section is filtered by data (Breakfast, lunch, dinner).  How would I create sections within the recyclerview?  If you need more information, or believe it is a bad question, I will update my question or supply more code.
How I would filter the adapters by breakfast, lunch and dinner:
FoodAdapter mAdapterBreakfast = new FoodAdapter(LogSet.filterBy("Breakfast"), R.layout.row, this);
FoodAdapter mAdapterLunch = new FoodAdapter(LogSet.filterBy("Lunch"), R.layout.row, this);
FoodAdapter mAdapterDinner = new FoodAdapter(LogSet.filterBy("Dinner"), R.layout.row, this);

How I get all of the items in the adapter:
FoodAdapter mAdapter = new FoodAdapter(LogSet.all(), R.layout.row, this);

Here is a working example of all:
Adapter
public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.ViewHolder> {
    private List<LogSet> meals;
    private int rowLayout;
    private Context mContext;
    View v;

    public FoodAdapter(List<LogSet> mMeals, int rowLayout, Context context) {
        this.meals = mMeals;
        this.rowLayout = rowLayout;
        this.mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        v = LayoutInflater.from(viewGroup.getContext()).inflate(rowLayout, viewGroup, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        LogSet meal = meals.get(i);
        viewHolder.countryName.setText(meal.getLiftName());
    }

    @Override
    public int getItemCount() {
        return meals == null ? 0 : meals.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView countryName;

        public ViewHolder(View itemView) {
            super(itemView);
            countryName = (TextView) itemView.findViewById(R.id.foodName);
        }
    }
}

MainActivity
public class MainActivity extends ActionBarActivity {
    RecyclerView mRecyclerView;
    Date mDate = new Date();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_testing_rec);
        mRecyclerView = (RecyclerView) findViewById(R.id.list);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        FoodAdapter mAdapter = new FoodAdapter(LogSet.all(), R.layout.row, this);
        mRecyclerView.setAdapter(mAdapter);
        /*
        FoodAdapter mAdapterBreakfast = new FoodAdapter(LogSet.filterBy("Breakfast"), R.layout.row, this);
        FoodAdapter mAdapterLunch = new FoodAdapter(LogSet.filterBy("Lunch"), R.layout.row, this);
        FoodAdapter mAdapterDinner = new FoodAdapter(LogSet.filterBy("Dinner"), R.layout.row, this);
        */
    }
}

Here is how I would send each List value to the adapter:
Adapter
public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.ViewHolder> {
    private List<LogSet> meals;
    private List<LogSet> breakfast;
    private List<LogSet> lunch;
    private List<LogSet> dinner;
    private int rowLayout;
    private Context mContext;
    View v;

    public FoodAdapter(List<LogSet> mMeals, List<LogSet> mBreakfast, List<LogSet> mLunch, List<LogSet> mDinner, int rowLayout, Context context) {
        this.meals = mMeals;
        this.breakfast = mBreakfast;
        this.lunch = mLunch;
        this.dinner = mDinner;
        this.rowLayout = rowLayout;
        this.mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        v = LayoutInflater.from(viewGroup.getContext()).inflate(rowLayout, viewGroup, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        LogSet meal = meals.get(i);
        viewHolder.countryName.setText(meal.getLiftName());
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView countryName;

        public ViewHolder(View itemView) {
            super(itemView);
            countryName = (TextView) itemView.findViewById(R.id.foodName);
        }
    }

    @Override
    public int getItemCount() {
        return meals == null ? 0 : meals.size();
    }
}

MainActivity minus the all()
public class MainActivity extends ActionBarActivity {
    RecyclerView mRecyclerView;
    Date mDate = new Date();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_testing_rec);
        mRecyclerView = (RecyclerView) findViewById(R.id.list);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        FoodAdapter mAdapter = new FoodAdapter(LogSet.all(), LogSet.filterBy("Breakfast"), LogSet.filterBy("Lunch"), LogSet.filterBy("Dinner"), R.layout.row, this);
        mRecyclerView.setAdapter(mAdapter);
        /*
        FoodAdapter mAdapterBreakfast = new FoodAdapter(LogSet.filterBy("Breakfast"), R.layout.row, this);
        FoodAdapter mAdapterLunch = new FoodAdapter(LogSet.filterBy("Lunch"), R.layout.row, this);
        FoodAdapter mAdapterDinner = new FoodAdapter(LogSet.filterBy("Dinner"), R.layout.row, this);
        */
    }
}

Again, How would I create sections within the RecyclerView with the Breakfast, Lunch and Dinner?
Comment: You can use this SimpleSectionedRecyclerViewAdapter from there: https://gist.github.com/gabrielemariotti/4c189fb1124df4556058
Comment: Have a look at this answer : http://stackoverflow.com/a/34464367/2739684
Answer: You can achieve it with only one adapter from this library: SectionedRecyclerViewAdapter.
First create a Section class to group your items:
class MySection extends StatelessSection {

    String title;
    List<LogSet> list;

    public MySection(String title, List<LogSet> list) {
        // call constructor with layout resources for this Section header, footer and items
        super(R.layout.section_header, R.layout.section_item);

        this.title = title;
        this.list = list;
    }

    @Override
    public int getContentItemsTotal() {
        return list.size(); // number of items of this section
    }

    @Override
    public RecyclerView.ViewHolder getItemViewHolder(View view) {
        // return a custom instance of ViewHolder for the items of this section
        return new MyItemViewHolder(view);
    }

    @Override
    public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyItemViewHolder itemHolder = (MyItemViewHolder) holder;

        // bind your view here
        itemHolder.tvItem.setText(list.get(position).getLiftName());
    }

    @Override
    public RecyclerView.ViewHolder getHeaderViewHolder(View view) {
        return new SimpleHeaderViewHolder(view);
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) {
        MyHeaderViewHolder headerHolder = (MyHeaderViewHolder) holder;

        // bind your header view here
        headerHolder.tvItem.setText(title);
    }
}

Then you set up the RecyclerView with 3 instances of your section class (Breakfast, Lunch and Dinner):
// Create an instance of SectionedRecyclerViewAdapter
SectionedRecyclerViewAdapter sectionAdapter = new SectionedRecyclerViewAdapter();

// Create your sections with the list of data
MySection breakfastSection = new MySection("Breakfast", LogSet.filterBy("Breakfast"));
MySection lunchSection = new MySection("Lunch", LogSet.filterBy("Lunch"));
MySection dinnerSection = new MySection("Dinner", LogSet.filterBy("Dinner"));

// Add your Sections to the adapter
sectionAdapter.addSection(breakfastSection);
sectionAdapter.addSection(lunchSection);
sectionAdapter.addSection(dinnerSection);

// Set up your RecyclerView with the SectionedRecyclerViewAdapter
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(sectionAdapter);

Comment: Be careful. This library use DialogFragment for communication between sections. If your design on Activity (not fragment) it is hard to achieve section system.

Creating sections within a RecyclerView


Short hand to do something like: if($variable == 1 || $variable == "whatever" || $variable == '492') .

Question: I find my self doing this type of IF statement allot.  For example:
if($variable == 1 || $variable == "whatever" || $variable == '492') { ... }

Except for allot of the time, I am comparing the $variable to maybe 4-5 things, sometimes more.  Is there a short hand way to write this?  You can see that repeating $variable == would get redundant.
I would love for this to work, but it doesn't:
if($variable == (1 || "whatever" || 492) { ... }

Answer: You can use this shorthand, but keep in mind that it is less efficient that explicitly listing them all with or clauses:
if(in_array($variable, array(1, 'whatever', '492'))){ ... }

Also if you want to use === instead of == the equivalent is:
if(in_array($variable, array(1, 'whatever', '492'), TRUE)){ ... }

Comment: You probably should have linked the [comparison ===](http://php.net/manual/ro/language.operators.comparison.php) to its manual. Many new programmers don't know what those 3 equal signs mean.
Answer: if(in_array($variable, array(1, "whatever", 492)))
Answer: in_array(...). http://php.net/manual/en/function.in-array.php
Answer: Although this doesn't directly answer the question, I think it's worth adding this method as part of a solution to the above problem:
If you find that something has multiple values, you may find that something like the following is appropriate:
if (true === is_condition_one ( $variable )) {

  // Execute any condition_one logic here

}

function is_condition_one ( $variable = null ) {
  $arrKnownConditions = array (
    // This can be an array from the database
    // An array from a file
    // An array from any other source
    // or an array of hardcoded values
  );

  return in_array ( $variable, $arrKnownConditions );

}

I agree with Godwin and toon81 and PaulPRO, but feel that if you are doing this a lot, you may actually benefit from a refactor as part of your solution.  The refactor above may help you organise this project and others better by defining the purpose of the comparison and letting your code be more readable and abstracting away those hardcoded values to a function. This will probably also help you re-use that check in other parts of your code with greater confidence.
Answer: Another viable alternative is to use a regex.
if (preg_match('^1|whatever|492$', $variable)) { ... }

Answer: Answer in 2023
In the new php update, you can also use your suggested method
$variable = "492" ;
if($variable  == 1 || "whatever" || '492'){
    echo "true";
}

Another example
if($testvar =! 0 && ($variable  == 1 || "whatever" || '492')){
    echo "true";
}


ComboBox object not accessible by me

Question: This is probably easy to solve, but the following cannot be done:
<code>protected void gSelectApplied(object sender, EventArgs e)
{
    ComboBox box = (ComboBox)sender;
}
</code>
Because the ComboBox object is not present in the imported libraries. I went ahead an looked at the Microsoft documentation and I do not have access to the System.Windows.* libraries.
Comment: ComboBox doesn't exist in ASP.NET, only in WinForms.
Answer: You want the ASP.NET DropDownList.

ComboBox object not accessible by me


how to set retrofit connections timeout unlimited?

Question: I want to set Retrofit connection timeout unlimited instead of static timeout
    connection.how can I do it ?
This is my code...
public static Retrofit getRetrofitInstance() {

    if (RetrofitInstance==null) {
        Gson gson = new GsonBuilder()
                .setLenient()
                .create();
        final OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .readTimeout(100, TimeUnit.SECONDS)
                .connectTimeout(100, TimeUnit.SECONDS)
                .build();
        RetrofitInstance = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .client(okHttpClient)
                .build();
    }

    return RetrofitInstance;
}

Comment: not aware of infinite but you can set big value like (24Hour) in  .readTimeout(24, TimeUnit.HOURS) and connectTimeout
Answer: Retrofit does not allow developers to remove timeout completely, but you could set TimeUnit.HOURS to use big value for your timeout. For example:
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .readTimeout(Integer.MAX_VALUE, TimeUnit.HOURS)
            .connectTimeout(Integer.MAX_VALUE, TimeUnit.HOURS)
            .build();

Used Integer.MAX_VALUE for this example, which is big enough value to act as an infinite timeout.

Good luck :)


How to query a list by name using the SharePoint DataView Web Part?

Question: I have multiple DataView Web Parts that are getting items from a list in SharePoint 2010.  The web parts are in a subweb and the data from the list is in the root web.  I can get this web part to work just fine by specifying the ID of the list:
<dsp:dsQuery select="/list[@id='GUID GOES HERE']" resultContent="Both" resultRoot="Rows" resultRow="Row" columnMapping="Attribute">

However!  I cannot use this method of selecting the list by the ID because I will be using export-spweb/import-spweb and moving the subwebs to a different location (this command re-assigns IDs... so after the export/import my web parts break).  What I want to do is select the list by something more definite... like below (which does not work):
<dsp:dsQuery select="/list[@name='LIST NAME GOES HERE']" resultContent="Both" resultRoot="Rows" resultRow="Row" columnMapping="Attribute">

To summarize, I need my dataview web parts to use a dsQuery that goes by list name and not ID.  Has anyone done this before or am I stuck with editing hundreds of web parts' IDs?  That would be awful =)
Any help is appreciated!
Answer: You can do that by changing List GUIDs to List name. Here is an example:
http://salaudeen.blogspot.com/2012/02/how-to-make-dataview-portable.html
Comment: We usually delete link-only answers.  Can you please add enough of an example here so that it answers the question wholely?


A question regarding 'Uniformization' theorem : connection between a topological space and a uniform spaces

Question: This title might be slightly misleading since I saw that the name 'uniformization' theorem is already used in a different context, but my question regards whether a topological space arises from a uniformity.
I know that there is a  metrization theorem  characterizing fully a metrizable topological space. I was wondering whether there is a similar result regarding if a topological space is 'uniformisable', even partially. I have very little acquaintace with uniform spaces, so I would appreciate even simple somewhat 'obvious' answers.
Answer: Yes, such a theorem exists: the topology of a topological space $X$ is induced by a uniform structure if and only $X$ is completely regular; in other words, if it is a $T_{3\frac12}$ space.
Comment: That is, if you want a separated uniformity. Otherwise leave out the $T_1$ part.
Comment: @HennoBrandsma: what is a separated uniformity?


Word comment extraction: help getting numbered headings

Question: I decided to learn VBA two weeks ago, and it's gone rather smooth. Now, however, I've encountered a problem I can't seem to solve on my own.
 I've set up an excel document containing various modules. One of these modules extracts comments from a word document over to the excel sheet - which works as intended.
The problem is, I haven't been able to extract the first numbered header above each comment, which I'd very much like. Currently I have to do this manually after extracting the comments. As an example, I would like to also extract the first header and number above each comment, such as '2.1.1 Title'. If the comment is highlighting the header itself, it should be that header which is extracted as well.
I've tried a variety of things based on what I could find online, but every time I'm met with a variety of bugs I can't seem to fix. I've yet to find something that even sorta works. I did try one method which apparently should work in Word VBA, but I couldn't get it working within Excel.
Does anyone know how I would go about extracting the numbered headers? Any hints or tips will be greatly appreciated.
This is the code I have for the module:
Sub ImportCommentsDOCX()
    Dim wdDoc As Object
    Dim wdFileName As Variant
    Dim i As Integer

    wdFileName = Application.GetOpenFilename("Word files (*.docx),*.docx", , _
        "Browse for file to be imported")
    If wdFileName = False Then Exit Sub '(user cancelled import file browser)
    Set wdDoc = GetObject(wdFileName) 'open Word file
    '1: if no comments'
    With wdDoc
        If wdDoc.Comments.Count = 0 Then
            MsgBox ("No comments")
        End If
        '2; Set excel headers'
        Range("B" & 1).Value = "Number"
        Range("B" & 1).Font.Bold = True
        Range("C" & 1).Value = "Comment"
        Range("C" & 1).Font.Bold = True
        Range("D" & 1).Value = "Highlighted text"
        Range("D" & 1).Font.Bold = True
        Range("E" & 1).Value = "Initials"
        Range("B" & 1).Font.Bold = True
        Range("F" & 1).Value = "Date (*Imprecise)"
        Range("F" & 1).Font.Bold = True

        '3: Extract comments and meta data'
        For i = 1 To wdDoc.Comments.Count
            Range("B" & 1 + i).Value = wdDoc.Comments(i).Index
            Range("C" & 1 + i).Value = wdDoc.Comments(i).Range
            Range("D" & 1 + i).Value = wdDoc.Comments(i).Scope.FormattedText
            Range("E" & 1 + i).Value = wdDoc.Comments(i).Initial
            Range("F" & 1 + i).Value = Format(wdDoc.Comments(i).Date, "dd/MM/yyyy") 'Unreliable: Sometimes gives wrong date'
            'Range("G" & 3 + i).Value = wdDoc.Comments(i).Range.ListFormat.ListString 'Returns empty'
        Next i
    End With
    Set wdDoc = Nothing
    MsgBox ("Extraction has completed")
End Sub

Comment: I think in Word the comments are applicable to the Doc whereas in Excel they are applicable to the Sheet, e.g. `Debug.Print ActiveSheet.Comments.Count`. Presumably you'll be changing where you're opening a word file to using excel?
Comment: Not entirely sure I understand, but yes, the word doc that will be opened will change. Are you saying that, I should debug to avoid the errors I've met previously in using word VBA in excel VBA?
Answer: Here is your code with some adjustments:
Sub ImportCommentsDOCX()
    Dim wdDoc As Object
    Dim wdFileName As Variant
    Dim i As Integer

    wdFileName = Application.GetOpenFilename("Word files (*.docx),*.docx", , _
        "Browse for file to be imported")
    If wdFileName = False Then Exit Sub '(user cancelled import file browser)
    Set wdDoc = GetObject(wdFileName) 'open Word file
    '1: if no comments'
    With wdDoc
        wdDoc.Activate ' Added
        If wdDoc.Comments.Count = 0 Then
            MsgBox ("No comments")
        End If
        '2; Set excel headers'
        Range("B" & 1).Value = "Number"
        Range("B" & 1).Font.Bold = True
        Range("C" & 1).Value = "Comment"
        Range("C" & 1).Font.Bold = True
        Range("D" & 1).Value = "Highlighted text"
        Range("D" & 1).Font.Bold = True
        Range("E" & 1).Value = "Initials"
        Range("E" & 1).Font.Bold = True ' Modified
        Range("F" & 1).Value = "Date (*Imprecise)"
        Range("F" & 1).Font.Bold = True

        '3: Extract comments and meta data'
        For i = 1 To wdDoc.Comments.Count
            Range("B" & 1 + i).Value = wdDoc.Comments(i).Index
            Range("C" & 1 + i).Value = wdDoc.Comments(i).Range
            Range("D" & 1 + i).Value = wdDoc.Comments(i).Scope.FormattedText
            Range("E" & 1 + i).Value = wdDoc.Comments(i).Initial
            Range("F" & 1 + i).Value = Format(wdDoc.Comments(i).Date, "dd/MM/yyyy") 'Unreliable: Sometimes gives wrong date'
            'Range("G" & 1 + i).Value = wdDoc.Comments(i).Scope.ListFormat.ListString 'Returns empty'    ' Modified ' Updated
            Dim wp As Word.Paragraph: Set wp = wdDoc.Comments(i).Scope.Paragraphs(1) ' Updated
            Do While wp.Range.ListFormat.ListString = "" ' Updated
                Set wp = wp.Previous ' Updated
            Loop ' Updated
            Range("G" & 1 + i).Value = wp.Range.ListFormat.ListString ' Updated
        Next i
    End With
    Set wdDoc = Nothing
    MsgBox ("Extraction has completed")
End Sub

Please note my comments: Added and Modified

wdDoc.Activate was required at least on my computer, otherwise the
Range property is empty.
After initials a wrong column was bolded
The original text is referred to by the Range property, not the Scope (which is the content of the comment), so its ListFormat property should be used
The row index was not correct (3 instead of 1)
Comment: Thank you so much for the help. I just ran a test on a document containing 13 comments. It appears the changes you've made extracts the header number when the comment is highlighting the header itself (This is in part what I want, so thank you for that :) ). However, nothing is returned for comments between headers. That is, it does not get the header number for comments found within a section of the document (such as a comment highlighting normal text).
Comment: I made another module which runs through all the paragraphs of a word document. I've tried using this earlier for getting the header numbers. However, I can't figure out which paragraph a certain comment is referencing.
Comment: Refer to the lines with the comment 'Updated.
Comment: Lovely. I had to add some error handling to avoid runtime error 91, but it seems to be working :) Thank you so much. I do get a strange question mark in a box for some of the comments who are made before any numbered header, but that's no biggie, just sorta odd. Once again, thank you.
Answer: Looks working for me:
This requires Microsoft VBScript Regular Expression 5.5
Sub commentaires()

   Dim regexOne As Object
   Set regexOne = New RegExp

   regexOne.Pattern = "^\d+\."

   Dim s As String, s1 As String
   Dim cmt As Word.Comment
   Dim doc As Word.Document

   For Each cmt In ActiveDocument.Comments

      Dim wp As Word.Paragraph
      Set wp = cmt.Scope.Paragraphs(1) ' Updated
      Do While Not regexOne.Test(wp.Range.ListFormat.ListString)
         Set wp = wp.Previous ' Updated
      Loop ' Updated

      s = s & _
        wp.Range.ListFormat.ListString & ";" & _
        cmt.Reference.Information(wdActiveEndAdjustedPageNumber) & ";""" & _
        cmt.Scope & """;""" & _
        cmt.Range.Text & """ " & vbCr

    Next

    Dim f As Integer
    f = FreeFile
    Open "c:\comments.csv" For Output As #f
    Print #f, s
    Close #f

End Sub


Obtendo o caminho completo de um arquivo do cliente em ASP.NET

Question: Do lado do servidor, é possível obter caminho completo de um arquivo enviado por um cliente utilizando a tag <input type="file">?
Por exemplo, se o usuário enviar o arquivo C:\Users\Documents\a.txt, tem como o servidor conseguir a string C:\Users\Documents\a.txt?
Comment: Já tentou `System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName);`? Pode colocar o que você tentou ou um trecho que está tentando fazer?
Comment: filename no caso é o name="" que coloca na tag input certo ?
Comment: por enquanto só fiz o
Comment: Pode ser, mas é uma propriedade que vai ter o nome do arquivo que foi carregado no servidor. Você já viu este exemplo? http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.postedfile(v=vs.110).aspx
Comment: Webforms, preciso somente pegar o path do aquivo que foi selecionado
Comment: O IE pega o caminho completo do cliente
Answer: A partir do servidor não é possível pegar o path de um arquivo submetido pelo cliente, por restrições de segurança.
O máximo que você obterá é o nome do arquivo, seu tamanho, extensão e MIME.
Por exemplo, se o cliente submeter o arquivo C:\A\B\C\Teste.txt, o máximo que você conseguirá no servidor é o nome Teste.txt.
Comment: Eu acho (ou achava) que ele quer o *path* no servidor, se for no lado cliente, como você sugere, aí não tem jeito mesmo. É que pensei só no jeito que dá :)
Comment: @EnzoTiezzi então, com o `move_uploaded_files` você pega o arquivo que foi enviado para o servidor e manda para um *path* que você deseja. É o oposto desta resposta.
Comment: @EnzoTiezzi Você não entendeu o que o bigown disse, vocês estão dizendo a mesma coisa...
Comment: @EnzoTiezzi é, não dá para entender o que você deseja. Você fala em servidor, depois fala em local. Você fala que quer algo igual ao `move_uploaded_files` só que usando ASP.Net, depois fala que vai fazer copy do OS.
Comment: Pois é, a pergunta ficou meio vaga... Mas acho mesmo que é isso :)
Comment: sim, isso mesmo rafa, como posso fazer tipo o PHP que tem o move_uploaded_files ?
Comment: não, move_upload_files só copia o arquivo do path origem pra algum path de desejo(que pode ser um servidor ou não), é somente isso que desejo fazer
Comment: então, no caso só desejo fazer a mesma coisa.
Comment: Então @EnzoTiezzi, se o que você quer é parecido com o `move_uploaded_files` do PHP, como esta resposta responde o que você precisa?
Comment: como seria apenas local, eu fazer meio que uma gambiarra, pegar o path do arquivo, usar um process pra rodar um comando COPY pra uma pasta desejada
Comment: Seguinte, quero pegar um arquivo e fazer a copia do mesmo para outra pasta, como isso é feito??? você pega o path do arquivo origem e faz um COPY para a pasta desejada, isso o move_uploaded_file faz, e é isso que desejo fazer no asp.net, o move_uploaded_file funciona tanto local como em servidor, por isso que tanto faz a maneira, porque no final dos casos será um usuário que fará o upload do arquivo
Answer: Depois de várias alterações na proposta inicial da pergunta eu tenho que dizer que não é possível pegar o path de um arquivo local em um navegador em um serviço que esteja em um servidor a não ser por uma falha de segurança eventual em alguma versão específica, mas isto, em hipótese alguma, deve considerado. Mesmo que este serviço esteja na mesma máquina que o navegador, não é possível sem uma intervenção tão maluca que existem outros meios mais fáceis e corretos para resolver o problema, que é o que importa.
Se há esta garantia que o servidor e o navegador estão na mesma máquina, para que usar um navegador para resolver este problema? Não faz sentido. Deve-se usar a melhor ferramenta para o problema. Não tentar adaptar o problema para a ferramenta. Não podemos nos fixar em um caminho para resolver o problema, devemos achar uma solução para o problema.
Com os indicações que disponho, principalmente em comentários, de como você está fazendo, o melhor que eu posso postar é isso:
<form id="form1" runat="server">
    <asp:FileUpload id="FileUpload1" runat="server" />
    <asp:Button runat="server" id="btnUpload_Click" text="Upload" onclick="btnUpload_Click" />

    <asp:Label runat="server" id="StatusLabel" text="Upload status: " />
</form>

Coloquei no GitHub para referência futura.
Code Behind
protected void btnUpload_Click(object sender, EventArgs e) {
    string fileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
    FileUpload1.PostedFile.SaveAs(Server.MapPath("/Uploads/" + fileName));
}

Coloquei no GitHub para referência futura.
Isso faz exatamente o que você precisa, até onde deu para entender. Claro que você vai ter que adaptar às características específicas do sue código. Mas o centro da questão está aí.
Veja a documentação do método que faz o mesmo que o move_uploaded_files.
Comment: Se for o caso de ler o arquivo basta usar o `FileUpload.FileContent` assim  `using (StreamReader reader = new StreamReader(FileUpload.FileContent, System.Text.Encoding.UTF8))`


What is the rate of convergence of the observed autocorrelation?

Question: How fast would the observed autocorrelation in a sample converge to the true autocorrelation (say, an AR(x) process)? Are there any results like the Central Limit Theorem - which says that the sample mean of a random sample converges to the true mean at a rate of $\frac{1}{\sqrt{n}}$ - or the Berry-Esseen theorem that would apply to the observed autocorrelation?
This question sprung from a minor point around this answer (rate of convergence of the observed autocorrelation vs rate of convergence of the confidence band in an ACF - we do know the latter) and I thought it was sufficiently general to merit its own question.
Comment: The Berry-Esseen theorem says much more than just asserting convergence at rate $1/\sqrt{n}$, this is the job of the Central Limit Theorem. So it is not clear whether you are asking for a CLT for sample auto-correlations, or for the more specific results obtained in B-E theorem.
Comment: @AlecosPapadopoulos Thanks for correcting me. I am asking about a CLT for sample autocorrelation (if there is one).
Comment: @AlecosPapadopoulos I have now amended the question accordingly, thanks again.
Answer: A theorem is $6.7$. in Hall and Heyde (1980) p. 188. For a stationary process, we have
$$n^{1/2}[\hat \rho(j) - \rho(j)] \to_d N(0,v)$$
for autocorrelation of $j$-distance, and in fact, all the autocorrelations converge jointly to a multivariate normal. The authors mention that "results are available also outside the context of stationarity".
Comment: @Candamir In the sense that $[\hat \rho(j) - \rho(j)] = O_p(n^{-1/2})$, yes.
Comment: Thank you! Does this imply a convergence rate of $n^{-1/2}$? Apologies if this is obvious to you.
Comment: See also https://stats.stackexchange.com/questions/207264/root-n-consistent-estimator-but-root-n-doesnt-converge/207281#207281


Multiline regular expression in Autoit3

Question: I am trying to match multi-line HTML source code with a regular expression (using AutoIt). HTML source code to match:

Eat a quarter-pounder with cheese

                100%

5,000–8,000

XP +5

Prerequisites:

                        × 1

                        × 1

                        × 1

                            <form action="/quest/index/i/kdKJBrgjdGWKqtfDrHEkRM2duXVn1ntH/h/c0b2d58642cd862bfad47abf7110042e/t/1336917311" method="post">
                <input type="hidden" id="id" name="id" value="17"/>
                <button class="button buttonIcon btnEnergy">5</button>
            </form>

It is present multiple times on a single page (but items within
...
 vary).

I need to match

Eat a quarter-pounder with cheese
,
the first span 100% and
<input type="hidden" id="id" name="id" value="17"/>.

Expected result (for every occurrence on a page):
$a[0] = "Eat a quarter-pounder with cheese"
$a[1] = "100%"
$a[2] = "17"

What I came up with:
(?U)(?:
\s+
(.*)
\s+
\s+(.*))|(?:<form .*\s+.*<input\stype="hidden"\sid="id"\sname="id"\svalue="(\d+)"/>\s+.*\s+</form>)

But that leaves some array-items empty. I also tried the (?s) flag, but then it only captures first occurrence (and stops matching after).
Comment: I'm not familiar with autoit, but have a look if it has some html/xml support. You'll be much better off using a proper parser.
Comment: Next time, I wouldn't use a regular expression for this purpose. But rather a for loop that iterates on each line of the string and takes action based on whether or not a certain substring is there. It's a bit more flexible.
Answer: I had not to use . to match words or integers, because of the (?s) flag. The correct regex is:
(?U)(?s)
\s+
([\w\s]+)
(?:.*)
\s+(\d+)%(?:.*)<input.* value="(\d+)"/>

Answer: Regular expression to match multi-line HTML source code:

As per documentation;

\R matches newline characters (?>\r\n|\n|\r),
dot . does not (unless (?s) is set).
\s matches white space characters.

Generally some combination is required (like \R\s*?).
Non-capturing groups are redundant (match without capturing instead).
If uniquely enclosed, single characters may be excluded instead (like attribute="([^"]*?)" for text between double-quotes).

Example (contains double-quotes; treat as per Documentation - FAQ - double quotes):
(?s)
.*?
(.*?)
.*?
.*?([^<]*?).*?<input type="hidden" id="id" name="id" value="([^"]*?)"/>

Visual explanation:

If regular expressions should be used on HTML (beyond simple listings like this) is a different question (been, done, T-shirt).

Multiline regular expression in Autoit3


Increment & Repeat a range based on cell values in Google sheets USING FORMULA

Question: I have a range (B1:B7) containing Dates as listed below
1-Jan
1-Jan
1-Jan
2-Jan
2-Jan
2-Jan
3-Jan
I want this range to repeat N times based on a cell value and also increment each value of the range by 7 when the range repeats each time.
Eg : If the value in cell A1 = 3 , I want the date range to repeat 3 times starting from cell A2 and increment the values by 7 each time they repeat.
Expected Result :
1-Jan
1-Jan
1-Jan
2-Jan
2-Jan
2-Jan
3-Jan
8-Jan
8-Jan
8-Jan
9-Jan
9-Jan
9-Jan
10-Jan
15-Jan
15-Jan
15-Jan
16-Jan
16-Jan
16-Jan
17-Jan
Below is the formula I am using to repeat the range. But I couldn't find a way to increment the values by 7 when the range repeats each time.
=query(flatten(transpose(ARRAYFORMULA(split(rept(B1:B7&" ",A1)," ")))),"where Col1 is not null")
Result :
1-Jan
1-Jan
1-Jan
2-Jan
2-Jan
2-Jan
3-Jan
1-Jan
1-Jan
1-Jan
2-Jan
2-Jan
2-Jan
3-Jan
1-Jan
1-Jan
1-Jan
2-Jan
2-Jan
2-Jan
3-Jan
Answer: Given the exact ranges and specs in your post, this formula should work for you in A2:
=ArrayFormula(FLATTEN(TRANSPOSE(FILTER(B:B,B:B<>"")+SEQUENCE(1,A1,0,7))))
FILTER creates a virtual array of only non-null rows from B1:B.
To those dates will be added a SEQUENCE of numbers 1 row by [number in A1] columns, starting with 0 and skipping by 7. In the posted example where A1 = 3, then, this SEQUENCE would be as follows: 0  7  14 (each in a separate virtual column).
Those numbers will be added to every date in the FILTER to form a grid with as many rows as dates and as many columns as the number in A1.
This grid is TRANSPOSEd before the next step, to keep the dates in the order of your original vertical listing instead of deferring to the horizontal additions to each.
The grid is then FLATTENed into one column.
The formula is wrapped in ArrayFormula( ) because it is processing arrays rather than single cells.
Keep in mind that you may need to format the results range (i.e., A2:A) in the date format of your choice. Otherwise, you may see raw dates, which will be numbers in the 44000-45000 range.
Comment: Thanks a lot Erik. Your formula worked like a charm. You have helped me to relieve off my stress which I had for the past 3 days trying to figure it out. Wish you abundance of  happiness.
Comment: Glad to help set your mind at ease. Thank you for your kind wishes.


Report Comparing two Subsets against Aggregate

Question: I have a report I'm writing which represents some customer 'worth' data.
This subset (let's call it T) is broken down into two sub-categories ('A', and 'B').  The issue I'm having is my limited knowledge of Math (or, I've been working on it too long.)
I have a result called 'a' from sub-category 'A' which represents the result of some function on the values from 'T' which are an element of 'A'.
The same applies to sub-category 'B' and result 'b'.  The sum of a + b = t, where t is the result of the same function on all of the values of 'T'.
What I'm trying to calculate are two ratios of 'A' and 'B' (let's call these ratios 'Ra' and 'Rb') based off of a known ratio as seen of set 'T' (Rt).  The purpose of this ratio is to calculate another value, for 'A', 'B' and 'T' (Let's call these 'Va', 'Vb', and 'Vt') the sum of these two values will be Va + Vb = Vt.  Rt and Vt are known as are 'a' and 'b'.
Rt = THEOs / (THEOs + THEOg)
I have tried to calculate the ratios using the same data from T that is present in both A and B, but the resulting Va + Vb ≠ Vt.  Does this likely mean that the way I am calculating the ratio for T, A, and/or B is incorrect?
I can't go into a whole lot more detail due to the sensitivity of the information, but needless to say 'a', and 'b' have to be weighted based off of their representation within T, this is likely the source of my problem and where I should try to find my answer...?
For Context:
There are 10 'Segments', 3 'States', on over 30,000 customers, so each single segment&state = one subset of 'T', which there are sub-categories 'A' and 'B'.  So effectively 30 total sets of T (T(1,1), T(1,2), T(1,3), T(2, 1), ..., T(10, 2), T(10,3))  For the sake of this question, I'm focusing on one version of T to simplify it.
Answer: Turns out it was a complicated bit.  To project the worth of a given sector, it used distinct months for a given set, when the aggregate and subsequent subsets were calculated, because they added up to different month counts, creating a different 'worth' ratio, the aggregate didn't match ($V_{a} + V_{b} \neq V_{t}$).  Since the aggregate represents the full picture and a proper representation of the target audience, I had to approximate the relative time (vs the aggregate) the sub sets represented.
This also took into account response rates, which are known for the subsets and the aggregate's response rate is an aggregation of those.
So the sub-sets' worth figure had to be calculated off of the aggregate and neutralize the response rate that was figured into the aggregate.
$$
\begin{equation*}
W_{a} = \frac{\sum^{THEO}_{a}}{C_{a}*\frac{M_{t}*E_{t}}{C_{t}}}*E_{a}
\end{equation*}
$$
$$
E_{t} = \frac{E_{a} * C_{a} + E_{b} * C_{b}}{C_{t}}
$$
$C_{n} =$ The number of people within a set. Where:
$$
C_{a} + C_{b} = C_{t}
$$
$E_{n} =$ Estimated frequency at which a segment is to respond.  The aggregate months of a subset is not considered, because these subsets need to be a representation of the whole, and their 'counts' are already a part of the whole's data.


Como consumir de diferentes maneiras arquivos JSON no PHP?

Question:
Esse tópico difere de assuntos como: "Como consumir JSON em
  PHP"; "Extrair valor json no php"; "Ler string json em
  php" ou então "Recuperar JSON no PHP"
  Embora exista co-relação em vários assuntos da linguagem PHP, e o formato JSON, ele trata de um problema específico, detalhadamente retratado e resumido.

Em todos os materiais que tratam do assunto de JSON em PHP, não encontro nenhum que cite as diferentes formas de tratar o JSON. Tratam o json como se ele fosse expresso sempre da mesma maneira, o que não é verdade na prática. Então, sempre temos um algoritmo para cada maneira que ele é expresso. Existe uma maneira universal de capturar os dados do json, ou existe uma maneira específica para o segundo caso citado abaixo?
Um exemplo prático seria que isso:
{
   "friendslist":{
      "friends":[
         {
            "steamid":"76561197960265731",
            "relationship":"friend",
            "friend_since":0
         },
         {
            "steamid":"76561197960265738",
            "relationship":"friend",
            "friend_since":0
         },
         {
            "steamid":"76561197960265740",
            "relationship":"friend",
            "friend_since":0
         },
         {
            "steamid":"76561197960265747",
            "relationship":"friend",
            "friend_since":0
         }
      ]
   }
}

Certamente é diferente disso:
[
   {
      "id":"578",
      "valor":"4.00",
      "CLIENTE":{
         "id":"492",
         "nome":"MARIA",
         "sobrenome":"Machado",
         "endereco":"Avenida das Am\u00e9ricas",
         "latitude":null,
         "longitude":null
      },
      "dataCompra":"DATA_AQUI",
      "PRODUTOS":[
         {
            "id":"14135",
            "codigoDeBarras":"7896015516260",
            "nome":"SONRIDOR",
            "detalhes":"500mg cx 60 comp",
            "categoria":"medicamento",
            "quantidade":"2",
            "precoUnitario":".10"
         }
      ],
      "FRANQUIA":{
         "id":"818",
         "nomeFantasia":null,
         "razaoSocial":null,
         "rede":{
            "id":"32",
            "nome":"Sapataria João"
         },
         "endereco":"Rua Acre",
         "latitude":"-22.899079",
         "longitude":"-43.181612"
      }
   }

]

O primeiro caso, até encontro uma forma de leitura
$steamid_player = "76561198112612121";
        $apikey = "APIKEY";

       $amg = file_get_contents("http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=$apikey&steamid=$steamid_player&relationship=friend");
        $decode = json_decode($amg, TRUE);

        foreach ($decode["friendslist"]["friends"][0] as $valor){

            $steamid = $valor["relationship"]->steamid;

            echo $steamid;
        }

Mas no segundo caso, não encontrei exemplos práticos. Consigo fazer no máximo um vardump.
Comment: "Tratam o JSON como se ele fosse expresso sempre da mesma maneira". Ele é sempre expresso da mesma maneira. Ele é um padrão para representar dados e se não seguir esse padrão será um JSON inválido. A diferença entre os JSON apresentados são os dados que eles representam. O que você quer dizer com "maneira universal"? (Seu código PHP não funciona)
Comment: É... Não existe "maneiras" de escrever o mesmo formato em outra estrutura de JSON. Talvez seja interessante dar uma olhada sobre a estrutura de objetos em JS para compreende-lo melhor. :)
Comment: [".... A diferença entre os JSON apresentados ..."] Se tem diferenças os JSON apresentados, JSON não é expresso da mesma maneira,  por definição. Da mesma forma que não existe solteiros casados. E sim, existem diferenças da forma que é "expressa" nos dois casos.
O primeiro caso por exemplo, passa uma coleção de dados expressas e uma sub-coleção em seguida. Ambos arrays, tal que o primeiro array representa uma coleção inteira. No segundo caso, passam 3 arrays interdependentes, sem expressar uma coleção antecedente. O PHP está funcionando normalmente em meu ambiente.
Comment: A quem interessar o problema, o script da resposta não funcionou no PHP5  mas no 7.
Answer: Na verdade a forma de leitura é similar ao primeiro exemplo que você citou. Por exemplo, ao usar o json decode eu posso acessar o array clientes, produtos, etc. Veja um exemplo aplicado a sua situação.
<?php
//a opção true vai forçar o retorno da função como array associativo.
$conteudo = json_decode(file_get_contents('json.json'), true);

foreach($conteudo as $chave => $elementos){
        $cliente = isset($elementos['CLIENTE']) ? $elementos['CLIENTE'] : [];
        $produtos = isset($elementos['PRODUTOS']) ? $elementos['PRODUTOS'] : [];
        $franquia = isset($elementos['FRANQUIA']) ? $elementos['FRANQUIA'] : [];
        $rede = isset($elementos['FRANQUIA']['rede']) ? $elementos['FRANQUIA']['rede'] : [];

        var_dump($cliente);
        var_dump($produtos);
        var_dump($franquia);
        var_dump($rede);

        /**
        As propriedades de $cliente, $produtos, $franquia, etc, podem ser acessadas da seguinte
        maneira:
        $cliente['id'];
        Aqui você pode manipular os dados da forma que desejar (mandar persistir no banco, etc)
        */
        echo $cliente['id'];

        /*******************Exibição generica*******************************/
        exibir('CLIENTE', $cliente);
        exibir('PRODUTOS', $produtos);
        exibir('franquia', $franquia);
        exibir('rede', $rede);
}

function exibir($titulo, $elementos){
    echo '

' . $titulo;
    foreach($elementos as $chave => $elemento){
        if(is_array($elemento)){
            foreach($elemento as $chave => $valor){
                echo '
' . $chave . ' : ' . $valor;
            }
        }else{
            echo '
' . $chave . ' : ' . $elemento;
        }
    }
}

As propriedades id, valor, datacompra podem ser acessadas com instruções equivalentes a echo $elementos['id'];
Answer: JSON é uma forma de serialização de objetos baseada na notação usada para descrever literais de objetos no javascript. Sendo assim, a notação deve ser flexível o suficiente para reproduzir qualquer* tipo de objeto que se pode descrever naquela linguagem.
Sendo assim, qualquer mecanismo que analise javascript ou que o emita precisa ser flexível suficiente para emitir qualquer um dos tipos de dados que, compostos, são usados pelo javascript para construir seus objetos.
Os tipos de dado aceitos pelo JSON são seis:

o objeto nulo null;
os valores booleanos true e false;
números de ponto flutuante de pelo menos 64 bits;
sequências de caracteres de 8 bits, tipicamente em codificação UTF-8;
vetores, que são coleções de valores indexados por inteiros contíguos começando por 0; e
os chamados objetos ou dicionários ou hashes, que são coleções de valores indexados por sequências de caracteres.

Uma biblioteca que analise JSON precisa emitir qualquer um desses seis tipos; por sorte, o PHP tem tipagem dinâmica, então uma única função pode retornar qualquer um dos seis tipos, conforme a necessidade.
Essa função é json_decode($json, true), contanto que o segundo parâmetro seja true para que a json_decode() retorne um Array em vez de um object.
Assim, no seu primeiro exemplo, para encontrar o steamid do seu terceiro amigo, você diria $friends = json_decode($exemplo1, true); echo $friends["friendslist"][2]["steamid"];; para encontrar o sobrenome da cliente no segundo, você diria $sale = json_decode($exemplo2, true); echo $sale[0]["CLIENTE"]["sobrenome"];.
*: Na verdade, o JSON é mais restrito que os literais de javascript no fato de que não é possível incluir literais de função no JSON, enquanto literais  de javascript podem tê-lo.


Can a function generated using JavaScript's eval be optimised?

Question: We all know that using eval() is frought with danger and should really never be used. But let's imagine that you have complete control over the input to eval and it can be used safely.
My question is, if I were to generate a function using eval() like below and then call the generated function many times, would this benefit from compiler/runtime optimizations in browser runtimes such as say, V8?
eval('var myFunction = function() { return 1 * 2 / 3 }')
myFunction()

Answer: I would rather suggest that it has a negative impact on runtime since the function is parsed when eval() is called, not when the document is loaded.
Optimizations by the Javascript Engine (like V8) are not influenced by the way a function is generated.
Comment: Thanks for your answer. I think I understand. Generating the function will be slower with eval because compilation is delayed, but if the function is stored somewhere and used later it can be optimised like any other function
Comment: @ChrisBellew You can edit your own comment. Please don't add another just to fix a typo.


Special case of polytonality, why does it sound like a single key?

Question: I watched Adam Neely's video on polytonality and came across a special case of polytonality. He was playing and singing Mary Had a Little Lamb in 2 different keys.

The keys were a minor third apart and both were major keys.
Here are the pitch classes of the keys used:
C major:
C D E F G A B C
Eb major:
Eb F G Ab Bb C D Eb
The result registers in my ears as being in a single key, C minor.
Why is it that these 2 unrelated keys sound like a single key related to both of them? Does it have to do with both keys being major and them being a minor third apart?
Answer: Eb major is the relative major of C minor. The C major tonality centers your ear on the C root, and throwing Eb major on top of it also points your ear to C minor because of the common tones between the two keys, namely C, F, and G - the roots of the I/i, IV/iv and V/v chords of both C major and C minor respectively, the 3 most important chords in "tonal" harmony. It also is important that the Eb tonality was placed in a higher register, as (for various reasons) your ear will gravitate toward C as being the bass against which Eb is contrasted (as opposed to your ear hearing the Eb tonality as the "bass" tonality). It's a bit of a musical "optical illusion," and not so an extreme version of polytonality, where completely unrelated keys might be put together (e.g., C major and F# major, as in Stravinsky's Petrushka, etc).
Answer: Here's the exact part he's playing:
X:1
L:1/8
M:C
K:C
%%score T B
V:T            clef=treble
V:B            clef=bass
% 1
[V:T] GF       _EF      GG       G2       | FF       F2        G_B      B2
[V:B] C,[E,G,] C,[E,G,] C,[E,G,] C,[E,G,] | D,[G,B,] D,[G,B,]  C,[E,G,] C,[E,G,]
[V:T] GF       _EF      GG       GG       | FF       GF        _E4
[V:B] C,[E,G,] C,[E,G,] C,[E,G,] C,[E,G,] | D,[G,B,] D,[G,B,]  C,4

I've use the signature of C for both parts, which highlights what you're hearing: most of the notes in the melody actually fit perfectly well in the accompaniment's C-major, only a couple of ♭ accidentals are out. As LSM07 said, those ♭ notes are perceived as borrowed from the isotonic minor mode, i.e. C-minor. You might see them as blue notes: in blues, the accompaniment is usually in major but the melody often deviates from the major thirds downwards to make it, well, "blue" (usually with some microtonal bending though).
If you list the resultant harmonies, it's basically this:
X:1
L:1/8
M:C
K:C
%%score T B
V:B            clef=bass
% 1
[V:B] "C"[C,E,G,]2 "cm"[C,_E,G,] "C"[C,=E,G,]3 [C,E,G,]2 | "G7"[D,G,B,F,]2 [D,F,G,B,]2  "C"[C,E,G,] "C7"[C,E,G,_B,] [C,E,G,B,]2
[V:B] "C"[C,E,G,]2 "cm"[C,_E,G,] "C"[C,=E,G,]3 [C,E,G,]2 | "G7"[D,G,B,F,]4   "cm"[C,_E,G,]4

The only thing that's really jarring here is that it actually ends on minor, giving a kind of inverse Picardy Third effect.
Comment: How do you get notes and staves to show up in the post without using images? I have always used images to show the notes and staves in my posts. I am thinking of posting a question about how to have my trio end, specifically whether or not to have the violin do a double stop and am thinking of doing the notes in the gray boxes. But I have no idea how to do that.
Comment: https://music.meta.stackexchange.com/questions/2782/documentation-for-abcjs?cb=1


Como ler um arquivo JSON que está dentro de um pacote?

Question: Preciso der um arquivo no caso *.JSON. Entendo que existe uma biblioteca para isso no caso utilizo a json-simple-1.1.1. Como é necessário fazer a leitura do arquivo primeiro e depois trabalhar com ele.
Minha dúvida é a seguinte:
Guardo o arquivo file.json dentro de um pacote com.app.json e preciso acessar esse arquivo.
Qual seria o método mais eficiente para acessar esse arquivo dentro do pacote?
Observação:
Isso deve valer para arquivos .json, .txt, .xml e outros.
Answer: Me parece que o pacote onde estarão os arquivos será sempre o mesmo. Desta forma, basta utilizar o código abaixo:
Reader in = new InputStreamReader(getClass().getResourceAsStream("/com/app/json/file.json") );
Object o = JSONValue.parse(in);

Caso contrário, você pode escrever uma função que receba o nome do pacote e transforme para um caminho válido dentro do classpath.
Abraços
Comment: Obrigado.
Por que você está utilizando "Object o = JSONValue.parse(in);" é uma forma exemplo?

Estou utilizando a seguinte linha: JSONObject jsonObjeto = (JSONObject) parser.parse(in);
Comment: Exatamente Eduardo, é apenas um exemplo. Você pode utilizar `JSONObject` se preferir. Note também que não é mandatório utilizar a classe `JSONValue`, você pode usar `JSONParser` também.


Looking for a bounded set in a set with finite measure lebesgue.

Question: Let $A\subseteq\mathbb{R}^{n}$ with $\mu^{*}\left(A\right)<\infty$. Show that for each $\varepsilon >0$  there is $A_{\varepsilon}\subseteq\mathbb{R}^{n}$  bounded such that $A_{\varepsilon}\subseteq A$  and $\mu^{*}\left(A-A_{\varepsilon}\right)<\varepsilon$.
Remark: The meausure $\mu^{*}$ is defined by
$\mu^{*}\left(E\right)=\inf\left\{ \sum_{k=1}^{\infty}\mu\left(I_{k}\right)\::\; I_{k}\:\mbox{is a } n\mbox{-celd and }\bigcup_{k=1}^{\infty}I_{k}\supseteq E\right\} $
where
$\mu \left(I_{k}\right)=\prod_{1\leq i\leq n}\left(b_{i}^{(k)}-a_{i}^{(k)}\right).$
The numbers $b_{i}^{(k)}$ and $a_{i}^{(k)}$ are the ends of the $n$-celd $I_{k}$.
Comment: Does $\mu^*$ denote outer measure or measure? In other words, is $A$ assumed to be Lebesgue measurable?
Comment: Use the definition and additivity of $\mu^*$
Answer: I thought for several days on this problem and the following is the proof of this fact:
Let $p\in A$ fixed, we define the sets $A_n$ by:
$A_{n}=\left\{ x\in A\::\: n\leq d\left(p,x\right)\leq n+1\right\} $
Note that $\bigcup_{n\in\mathbb{N}}A_{n}=A$.

Let $\delta>0$ fixed,  there is $\left\{I_{k}\right\}_{k \in \mathbb{N}}$ a sequence of $n$-celds such that $\bigcup_{k=1}^{\infty}I_{k}\supseteq A$  and
$\sum_{k=1}^{\infty}\mu\left(I_{k}\right)<\delta/2+\mu^{*}\left(A\right)$
Furthermore, we can consider $\left\{I_{k}\right\}_{k \in \mathbb{N}}$ a sequence of open $n$-celds such that if $I_{k}\cap A_{n}\neq\phi$ y $I_{k}\cap A_{n+1}\neq\phi$ then $I_{k}\cap A_{j}=\phi$ for all $j \in \mathbb{N}\setminus\left\{ n,n+1\right\} $.

We consider the set:
$M_{n}=\left\{k \in \mathbb{N} \::\: I_{k}\cap A_{n} \neq \phi \right\}$
Then $A_n  \subseteq \bigcup_{k\in M_{n}}I_k$, hence  $\mu^{*}\left(A_n\right)  \leq \mu^{*}\left(\bigcup_{k\in M_{n}}I_k\right )\leq \sum_{k\in M_{n}}\mu\left(I_{k}\right)$. So, we have that
$\sum_{n=0}^{\infty}\mu^{*}\left(A_{n}\right)\leq2\sum_{k=1}^{\infty}\mu\left(I_{k}\right)<\delta+2\mu^{*}\left(A\right)$
Then $\sum_{n=0}^{\infty}\mu^{*}\left(A_{n}\right)$ converge. So, for each $\varepsilon>0$ there is $N>0$ such that if $m>N$ then
$\sum_{n=m+1}^{\infty}\mu^{*}\left(A_{n}\right)<\varepsilon$
Considering $A_{\varepsilon}=\bigcup_{n=0}^{m}A_{n}$,  of the above it follows that:
$\mu^{*}\left(A-A_{\varepsilon}\right)=\mu^{*}\left(\bigcup_{n=0}^{\infty}A_{n}-\bigcup_{n=0}^{m}A_{n}\right)\leq\mu^{*}\left(\bigcup_{n=m+1}^{\infty}A_{n}\right)\leq\sum_{n=m+1}^{\infty}\mu^{*}\left(A_{n}\right)<\varepsilon.$


How to remove auto termination of disconnected RDP session in windows server 2003?

Question: Normally this is not grayed out but on this windows server 2003 it is:

It results in disconnected sessions being terminated after 1 minute.
Can I set this in the registry to "never terminate disconnected sessions"?
(The dropdown box was disabled after installing and uninstalling some 3rd party software, I have no hope of fixing the dialog)

Solution:
See also: http://www.sevenforums.com/tutorials/118889-remote-desktop-set-time-limit-idle-sessions.html
Start the Group Policy Editor:
c:\> gpedit.msc

From http://technet.microsoft.com/en-us/library/cc754272.aspx :
You can also configure timeout and reconnection settings by applying the following Group Policy settings:
Set time limit for disconnected sessions

Set time limit for active but idle Remote Desktop Services sessions

Set time limit for active Remote Desktop Services sessions

Terminate session when time limits are reached

These Group Policy settings are located in the following locations:
Computer Configuration\Policies\Administrative Templates\Windows Components\Remote Desktop Services\Remote Desktop Session Host\Session Time Limits

User Configuration\Policies\Administrative Templates\Windows Components\Remote Desktop Services\Remote Desktop Session Host\Session Time Limits

These Group Policy settings can be configured by using either the Local Group Policy Editor or the Group Policy Management Console (GPMC).
These Group Policy settings will take precedence over the settings configured in Remote Desktop Session Host Configuration. If both the Computer Configuration and the User Configuration policy settings are configured, the Computer Configuration policy settings take precedence.
Answer: If the setting is unavailable on the properties of the RDP protocol then it's being set via Group Policy. You'll need to check the GPO's that apply to the server in question and configure the setting there.
Comment: @mit - Yes, utilize RSOP to find the policy where it's coming from.
Comment: Thank you, this is the solution. Although I could not find anything configured in the GPO I could set my desired value "never terminate disconnected sessions" there and it is also reflected in the grayed out RDP settings dialog then, but still grayed out, but that's not a problem anymore now  :)


Explicit description of classifying space as a "delooping"?

Question: Consider the "classifying-space functor" $\mathscr{B} : \mathrm{TopGrp} \rightarrow \mathrm{Top}$, constructed in the standard way as a geometric realization of a nerve (in TopCat if necessary) of the topological one-object groupoid corresponding to the inputted topological group $G$.
If I'm not mistaken, we may assume we are restricting $\mathrm{Top}$ to some "nice" category of nice topological spaces, closed under e.g. loop spaces, taking classifying spaces of topological groups, etc.

The nLab page on delooping strongly suggests
that $\mathscr{B}$ produces a "delooping" of (the underlying topological spaces of) topological groups in the context of $\mathrm{Top}$ as an $(\infty,1)$-topos with homotopy pullbacks.
I was wondering, is there an explicit description of a weak(?) homotopy equivalence
$$
G \xrightarrow{\sim} \Omega(\mathscr{B}G)
$$
natural (up to "higher homotopy"?) in the topological group $G$?

I can't seem to find an explicit description of the above natural homotopy equivalence, although it's clear why the homotopy groups agree on both sides.
So far, I've tried to apply classifying space theory: since $[G,\Omega \mathscr{B} G] \simeq [\Sigma G , \mathscr{B}G]$,
we are therefore looking for some particular topological principal $G$-bundle on the reduced suspension $\Sigma G$ (up to isomorphism), however I'm not sure how to find such a bundle.

Update: Actually the answer comes from Hatcher's Algebraic Topology, Proposition 4.66; see the answer below.
Answer: Sorry, I realized the answer quickly follows from Hatcher's Algebraic Topology, Proposition 4.66

If $F \rightarrow E \rightarrow B$ is a fibration or fiber bundle with $E$ contractible, then there is a weak homotopy equivalence $F \rightarrow \Omega B$.

applied to the universal bundle $G \rightarrow\mathscr{E}G\rightarrow \mathscr{B}G$.


When a regular $F_{\sigma}$ set open?

Question:
A regular $F_{\sigma}$ set is a set $S \subset X$ such that S is a union of a sequence of open sets whose interiors contain $S$ i.e. $S=\cup_{1}^{\infty} F_n= \cup_{1}^{\infty} {F_n}^{\circ}$.

My question is when an open set is regular $F_{\sigma}$ set?
AS clearly every regular $F_{\sigma}$ set open, does the converse hold in all metrizable spaces or some other particular type of topological spaces? Also is there any relation between $F_{\sigma}$ set and regular $F_{\sigma}$ set?
Comment: I'm fairly sure that in every metric space $(X,d)$ this is correct, for if $O$ is an open set, then it is $F_{\sigma}$-set, by setting for example, $F_n=\{ x\in O: d(x, X\setminus O) \geq \frac{1}{n} \}$. Then $int(F_n)=\{ x\in O: d(x, X\setminus O) > \frac{1}{n} \}$ and thus $$O=\bigcup_{n\in\mathbb{N}}F_n =\bigcup_{n\in\mathbb{N}}int(F_n)$$
Comment: They way you define a regular $F_\sigma$ is just saying that is an open set.

So you must mean something different?
Comment: Or are your $F_n$ closed instead? that would make more sense as they cannot be open in your definition (that would add nothing).
Answer: Using the correct definition

A regular $F_{\sigma}$ set is a set $S \subset X$ such that S is a union of a sequence of closed sets $F_n$ whose interiors contain $S$ i.e. $S=\cup_{1}^{\infty} F_n= \cup_{1}^{\infty} {F_n}^{\circ}$.

Then it's obvious that a regular $F_\sigma$ set is in particular an $F_\sigma$ (as witnessed by $S=\bigcup_n F_n$) and open (because $S=\bigcup_n F_n^\circ$, a union of opens). Not all open $F_\sigma$ sets will be regular $F_\sigma$ in general but as noted in the comments, this is the case in any metrisable space $X$, using the sets $F_n = \{x \in O\mid d(x,O^\complement) \ge \frac1n\}$ for an open set $O$. Also in regular hereditarily Lindelöf spaces this will be the case.
Comment: Thanks. You are right and makes sense.

When a regular $F_{\sigma}$ set open?


When is it appropriate to use a likelihood evaluation rather than least squares fitting?

Question: I realise this might be a very open ended question, and there probably isn't a straight forward answer, but here goes:
I have been learning more about Likelihood evaluation (LLE, MLE,LRE) techniques. Especially in the context of extracting parameter estimates and errors on those parameters from distributions. I have also been playing with using a likelihood evaluation techniques as a means of fitting a theoretical curve/model to data.
I have found this is especially useful if I know the noise on the data is non-Gaussian, and I also know the details of the distribution it comes from.
So my question is when is it best to use a likelihood evaluation over more conventional fitting methods like least-squares?
Is it a case that likelihood evaluations are simply a more modern solution? Are they intrinsically better? Superficially a least-squares algorithm looks like a very specific form of likelihood evaluation which assumes Gaussian statistics.
Is there an argument to abandon least-square fitting methods altogether and exclusively use likelihood methods?
Answer: Hi: If you have a linear model, then there is a closed form solution for the coefficients and these will be the same ones that would result if you assumed a normal distribution for the error term ( of the linear model ) and then maximized the resulting likelihood function.
In all other cases ( or atleast most that I know of ), non-linear models or non-gaussian errors or correlated errors of some kind, you'll need to maximize the likelihood because there is no closed form solution like least squares. A lot of these cases fall under the class of generalized linear models. In these cases, using least squares is not appropriate.
So, linear models with normally distributed errors is kind of a lucky case in the sense that doing least squares ( i.e: OLS ) is the same as maximizing the likelihood.
Maximizing likelihoods is often more complicated and more computationally intense and there can be numerical issues to deal with. That's why OLS is convenient.
Comment: Hi: the decision is pretty easy actually. If It's an  OLS model, then use the closed form solution of OLS. Other than that case, I can't see where one would use closed form solution of OLS. The likelihood would always be preferred because it's not an approximation. It's exact.
Comment: So to paraphrase you a little, it would be fair to say: In most non-linear problem cases you would want to use a likelihood approach. However the trade-off is that this is computationally demanding, and that in a lot of cases while OLS is "worse" its not so much worse that it's worth the trade-off in computational demand.

So it's up to you to decide whether your problem specifically requires likelihood methods, or if you can make do with OLS.


How to split an ASP.NET project into different editions with different modules

Question: Suppose that there's an ERP System that holds the following modules:

Personnel
Time and Attendance
Payroll
Social Care
Training

This ERP system is built using a layered architecture of ASP .NET web forms (DAL, BLL, BVL, GUI). The backend is SQL Server and is accessed through EF. There's ONE database holding all the tables of all modules, and a lot of these tables are co-related. There's ONE GUI project for all modules. But each module is put in a separate folder.
My target is to create different editions with different modules. For example (Personnel + Time and Attendance + Payroll), or (Personnel + Payroll + Social Care), etc.
The question is: is there a guide or a best-practice to achieve this target? How to maintain published code, how to isolate DB tables that are not needed?
Comment: Starter:  Database side, I would create schemas to encapsulate different functionality.   That way you can have them in one database, but have a seperation, and know exactly when you cross those boundaries lines.
Comment: If you're concerned just about licensing, you can have the configuration in db encrypted (ie. UserLicenses table where there will be UserID and encrypted list of modules user has access to).
Comment: Do you have a log in system? From your question it seems like each edition would have its own set of modules? Edition 1 would have modules Personnel, Time/Attendance, and Payroll, while Edition 2 would have Personnel, payroll, and social care? How are you determining which edition to use? Are you using Editions as revisions? Wouldn't it be more simple to design some sort of log in system and you make the decision of which module to display off of the users permissions?
Comment: @Brandon J
There's already a login system. Currently I use it to allow/deny access to specific modules. The problem is, the security configuration are all stored in the DB, so any one who has access to the DB server may give himself the permission to access all the modules if he wish.
Comment: Sounds to me like you have a system that works already. If the security concern now is "Some db admins may do stuff they shouldn't", then will you remove that concern with the "Several editions" plan?
Answer: Put the module code in different class libs and use dependency injection to tie the modules together.
Answer: You can have 1 database, separate class library projects for each of the module and a single presentation layer.


Uniform convergence of series involving sin x: $\sum_{n=1}^\infty \frac{\sin x}{1+n^2x^2}$

Question: True or False: The series
$$\sum_{n=1}^\infty \frac{\sin x}{1+n^2x^2}$$
converges uniformly on $[-\pi,\pi]$.
Appreciate comments on attempt below, especially if it's incorrect!
Attempt at Solution:
False.
An infinite series $\sum_{n=1}^\infty f_n$ of real-valued functions on a metric space $E$ converges uniformly if and only if, given any $\epsilon \gt 0$, there exists an integer $N$ such that for any $n \gt m \ge N$,
$$|f_{m+1}(x)+f_{m+2}(x)+\dots+f_n(x)|\lt\epsilon$$
for all $x\in E$. Now let
$$f_n(x) = \frac{\sin x}{1+n^2x^2}$$
For small enough $\epsilon \gt 0,\ \sin \epsilon$ ~ $ \epsilon$. So in particular, $\sin \frac{\epsilon}{m} \gt \frac{\epsilon}{2m}$ for any positive integer $m$.
Choose $\epsilon$ small enough such that the above holds and also
$$\frac{1}{1+16\epsilon^2}\gt \frac{2}{3}$$
Now let $N$ be any positive integer and let $x = \frac{\epsilon}{N} \lt \pi$. For this fixed $x$, $f_n(x)$ is strictly decreasing as $n \to \infty$. So we get
$$|f_{N+1}(x)+f_{N+2}(x)+\dots+f_{4N}(x)|$$
$$\gt 3N (f_{4N}(x))$$
$$= 3N \frac {\sin \frac{\epsilon}{N}}{1+16N^2(\frac{\epsilon}{N})^2}$$
$$\gt 3N \frac {\frac {\epsilon}{2N}}{1+16\epsilon^2}$$
$$= (\frac{3}{2})(\frac{1}{1+16\epsilon^2})(\epsilon)$$
$$\gt \epsilon$$
Thus, the series does not converge uniformly on $[-\pi,\pi]$.
Answer: Your question is simple: Is my proof correct? I have read your proof, and my answer is also simple: Yes!


Powerful independence test for variables of unknown distribution

Question: I'm looking for the ideal independence test of two varaibles of unknown distribution, i.e. a non-parameteric test. Would choose between alternatives based on statistical power.
Few options that came to my mind are Kendall Tau and a test based on Spearman's rho. Chi-squared is an option, although power is a function of an additional parameter (binning), which makes it less compelling.
I wonder what other options are out there and how different options compare in terms of statistical power.
To give more color, I work in trading/finance, where forecasting relationships tend to be just as weak that it is difficult to find them. Once they are stronger, they quickly weaken to adhere to efficient market and no free lunch.
Relationships between variable do not have to be monotonic, but continuity of conditional mean or finite number of non-nontinuities is reasonable to assume.
We can assume iid-ness and typical sample size is 250 - 2500.
Comment: What's "strong independence"? (or if you meant a strong test of independence, what's a "strong test"?). What do you mean by "strength"? Are you talking about power? Against what alternatives?
Comment: @Glen_b, yes, I mean power, thanks for noting. I hope its easier to interpret now, I'm not sure about your last question though.
Comment: There's an infinite number of ways for things to be dependent. Measures like Spearman and Kendall correlations measure particular (and quite similar) types of dependence (and so have good power in tests when the form of dependence is like the kind of thing they measure) -- but there's all manner of dependence that neither of them pick up. So the question is ... what kinds of dependence do you want power to identify? The kind(s) that those two things can pick up? Or something else, perhaps something more general or something more specific?
Comment: I completely agree, we can't have a test which finds all kind of dependencies, I'm looking for ideas though which work often well in practice. Like it happens very rearly that a test of pearson correlation would result in a stronger p-value than Spearman, hence I prefer Spearman (unless I really need to test only linear correlation, which is not the case now). Because the distributions are unknown, Spearman and Kendall work fine as they only look at rankings. I wonder if there is anything more interesting here...
Comment: You could have a sequence of tests which as n grows would will have power against any form of dependence, but the problem is it will tend to have relatively lower power than one suited to the kind of dependence you want power against. When you say "I wonder if there is anything more interesting here", you still have not identified what kinds of performance would be interesting to you. *No* test will "work well in practice" against dependence it doesn't have power against, and so again, *what forms of dependence do you want power against*?  ... ctd
Comment: (ctd)... For example are you *only* interested in monotonic association? Or would more general functional association be important -- e.g. if the relationship was first increasing and then decreasing, would that be important to find, or not? Or ...what if there was a mix of two subpopulations of roughly equal size, one with a linear increasing association, one with a linear decreasing association (producing an "X" shaped relationship between the two variables), would that be important to find? ... and so on. ... We can't tell you what things you want power against.
Comment: Out of curiosity, do you have a typical sort of sample size? My advice at n=30 would often tend to be quite different from advice at n=30000.
Comment: Hi @Glen_b, useful classifications indeed... To give more color, I work in trading/finance, where forecasting patterns tend to be just as weak that it is difficult to find them. Once they are stronger, they quickly weaken to adhere to efficient market and no free lunch. Unfortunately relationships do not have to be monotonic, but continuity of conditional mean or finite number of non-nontinuities is reasonable to assume. We can assume iid-ness and typical sample size is 250 - 2500.
Comment: Mark -- that's important information that would be good to include in your question.
Answer: You may be interested in Hoeffding's independence test, which can be calculated using the R function hoeffd in the Hmisc package, and uses a test statistic resembling that of the Crámer-von Mises goodness of fit.
The test is consistent, provided we restrict the alternative hypothesis to the case where the two variables are dependent with a continuous joint distribution function; in other words, it is "powerful" against all such alternatives, given a large enough sample.
Another possibility is to construct a contingency table by splitting the range into bins and then apply the $\chi^2$ test for independence.
Comment: Hoeffding's test just fits the purpose. More ideas here: http://stats.stackexchange.com/questions/73646/how-do-i-test-that-two-continuous-variables-are-independent
Answer: The test described in Heller, Heller and Gorfine (2012) detects any form of dependence and is powerful in many dependence situations. The R package to use it is 'HHG' and function 'hhg.test'. Documentation here:
https://cran.r-project.org/web/packages/HHG/HHG.pdf
Another popular method is the distance covariance by Székely and Rizzo (2009), with the R package 'energy' and function 'dcov.test'. Documentation found here:
https://cran.r-project.org/web/packages/energy/energy.pdf
Comment: Thanks! HHG: https://arxiv.org/abs/1201.3522 and Szekely, RIzzo: https://projecteuclid.org/download/pdfview_1/euclid.aoas/1267453933 in more detail...


Perform action on logout,

Question: I would like to add javascript on logout. I tried using hook_user_logout but the javascript doesn't get added.
Even adding something as simple as drupal_set_message doesn't result in a message  being displayed.
I know the hook is firing because I can add a watchdog message in the hook and see it in the logs. The watchdog message is about the only thing I tried that DID work.
Curious about other options that may or may not have results, I tried looking at Actions and Triggers and Rules. I basically decided to try to do something simple on logout, like add a message. But even those modules don't work! I was actually really suprised when Rules didn't work.
I can add messages and do actions elsewhere. Has anyone else had problems with hook_user_logout? And does anyone know if it is possible to add javascript with that hook?
Is this some sort of problem involving drupal_goto? Hmmm.
I am on the verge of just adding JQuery to every page to check every link to see if it is a logout link and then adding a click event. It will work for my purposes, but it is such a hack. I would prefer not to.
Comment: What do you mean by "add javascript on logout", really? You want to include JS file on the first page user will encounter after logging out? What exactly are you trying to **achieve**?
Comment: Well, it's a personal project I was working on. I was writing a drupal module to connect to a restful api service, and authentication is sent via client side. My strategy is to use a jwt token and store it in local storage and use that to authenticate with the api. The jwt would be set on login, and then get erased on logout. Everything was working great until I hit the logout point.
Comment: I suppose I could store the token in $_SESSION or something and add it to settings on page load .. but... bleh.. I wanted to use local storage, gosh dang it
Answer:
Even adding something as simple as drupal_set_message doesn't result in a message being displayed.

That's the  expected behaviour - in the logout hook, you're still inside the authenticated user's session. Once they're logged out, you're not any more. So messages intended for that user are no longer there, because that session has been destroyed.
You should implement a logout/token expiry resource in your API, and invoke that in the logout hook. Then you don't need to remove the token held in local storage, as it will not be valid any more.
Comment: Hey that sounds like a good idea. I'll need to look into that.

Perform action on logout,


jQuery - modify the prompt/alert functions

Question: I need an advice, if it's worth it to downlaod a jQuery plugin (such as Impromptu), or if it's easier to make my own code just to modify the "prompt" efect. All I need is something like the first example of THIS.
Or is there any other way, how to show a box of text in the midle of the screen, that stays there even when I move scroll and to fade the background a bit, while the box is shown?
Answer: If Impromptu has the function you need, why reinvent the wheels?
If you just need a box to show text and be able to do non-modal(ie, just overlay and you can still have the others functional, jqueryUI dialog surely does.
Comment: Because I'd like to know how to make such a thing myself. I just haven't found any tutorial on that thing, so I'm not sure if it's not too hard ... :-/
Comment: Impromptu is about 300 lines of fairly dense code.  So I guess you'll have to decide which is more important...getting your application running or learning a new skill.  To do it properly you will need to know JQuery, Javascript, and CSS styling.


Why run-time populated array does not work on NgModule declarations?

Question:
While fixed array works?

I would like to use this extractor of components from routes:
function* getRoutesComponents(routes: Routes) {
    for (const route of routes) {
        if (route.component) {
            yield route.component;

            if (route.children) {
                yield* getRoutesComponents(route.children);
            }
        }
    }
}

@NgModule({
    imports: [SharedModule, RouterModule.forChild(ROUTES)],
    declarations: getRoutesComponents(ROUTES)
})
export class ProductModule {}

So I can avoid missing a component declaration in declarations property. Missing a component in declarations would result to error: NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'
Comment: I have tried to replicate your scenario in a sample app here https://stackblitz.com/edit/angular-component-ngjjen?file=app%2Fapp.module.ts and it is working fine only.. ```childcomponent``` and ```appcomponent``` are pushed into ```a``` and it is loaded..
Comment: @ManirajMurugan interesting your example works. I'm using this example: https://github.com/DeborahK/Angular-Routing. Perhaps there's some  angular or typescript settings on that project that makes the angular or typescript reads the NgModule statically
Answer: To enable runtime population of components for declarations, we need to disable Angular's AOT. This can be done by setting the ng serve or ng build's --aot to false.

However, disabling AOT would cause two major inconveniences. First, we cannot use constants as keys on objects anymore. Second, when AOT is disabled, despite fullTemplateTypeCheck is set to true, Angular will still build the project even if the names binded to ngModel have typo or spelling mistakes.


Trouble Detecting Invalid Write

Question: The problem I'm getting is that I'm getting heap corruption messages during deletion of binary tree nodes. The message says:

HEAP[lab4.exe]: HEAP: Free Heap block 5788c0 modified at 5788e8 after
  it was freed Windows has triggered a breakpoint in lab4.exe.
This may be due to a corruption of the heap, which indicates a bug in
  lab4.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while lab4.exe has
  focus.

It sounds like I'm writing to a block of memory that has been freed. Valgrind seems to confirm this with messages like:

Invalid write of size 4
  at 0x8049C65:> BinTree::removeTree(BinTree::Node*) (in/net/metis/home2/alexo2/lab4/a.out)...
  ==9681==  Address 0x402ab50 is 0 bytes inside a block of size 12 free'd
  at 0x40054B4: operator delete(void*) (vg_replace_malloc.c:346)
  by 0x8049C61: BinTree::removeTree(BinTree::Node*) (in
  /net/metis/home2/alexo2/lab4/a.out)
  ...

When I trace through the program, the heap corruption messages begin usually in a parent class or base class destructor. I've been trying to trace this but I have no idea where the problem is. I never use delete on these nodes until the destructor.
I suspect the problem has something to do with the way I'm deleting or keeping track of the binary tree. Here's some code I'll post, not sure if it will help with finding a solution.
So, a class object is dynamically allocated and returned by a function. This object is kept track of with pointers until it finally is inserted into the node of a binary tree.
At the end of the program when everything is being deleted, the destructor is called:
void BinTree::makeEmpty()
{
    if ( root != NULL ) {
        removeTree( root );
    }
    root = NULL;
}

void BinTree::removeTree( Node *curr )
{
    if ( curr == NULL )
        return;

    removeTree( curr->left );
    removeTree( curr->right );

    delete curr->data;
    delete curr;

    curr->data = NULL;
    curr = NULL;
}

In some function, this is the call that creates and returns the dynamically allocated object:
Item *aMovie = factory.createMovie( code.c_str() );

On only some, not all, of the nodes, when delete curr->data is reached, the destructor of the object it's pointing to is called, then the parent's destructor, and finally the base class destructor (all of them are empty). Sometimes it's in the parent destructor, sometimes the base class destructor that the heap corruption message is shown.
Any suggestions on what the problem might stem from?
Answer: This:
delete curr->data;
delete curr;

curr->data = NULL;
curr = NULL;

is wrong. You shouldn't write to curr->data after you deleted curr. Not even NULL.

Trouble Detecting Invalid Write