Can't fully serialize List<> inheritor with protobuf-net

Question: I'm trying to serialize an existing class which inherits from List<> and has members.
When I serialize it with protobuf-net it default to ListHandling which serializes the elements in the list fine but ignores the members on the list itself. If I use the "IgnoreListHandling=true" with the ProtoContract attribute, the inverse happens: members on the list are serialized but list items are lost.
I'm moving an existing application to protobuf so redesigning these kind of classes would be a last resort.
Answer: In common with several other serializers (including core .NET serializers like XmlSerializer), to protobuf-net, something is either a list xor a leaf. Members of a list are never considered: they only exist to act as a list. The IgnoreListHandling switches between the two modes, but the "both a list and a leaf" scenario is not supported.
Frankly, what you describe sounds like a dubious design choice anyway. Normally you would encapsulate a list, not subclass it. So rather than:
class MyStuff : List<Foo> {
    public int ExtraValue {get;set;}
}

I would strongly advocate that this should be implemented:
class MyStuff {
    private readonly List<Foo> foos = new List<Foo>();
    public List<Foo> Foos { get { return foos; } }
    public int ExtraValue {get;set;}
}

Comment: If you want custom List then preferably implement IList instead of deriving from List
Comment: I personally would have designed it as you say but I'm dealing with legacy stuff. I'll try implementing IList<> while encapsulating the list in the inheritor to make this work without massive changes.
Comment: Implementing from IList has the same result, it is treated as a list just the same.


Continuous functions from a topological space to itself.

Question: Recently I studied the theorem that states that if X is a topological space equipped with the discrete topology, then every function from X to itself must be continuous. I am wondering if the converse is true. If every function from X to itself is continuous, then is the space discrete?
Thank you.
Comment: The space can have the indiscrete topology.
Comment: So, the answer is "no".
Answer: Actually, any function from discrete space to any space is continuous. Dually, any function from any space to indiscrete space is continuous.
It is true that if any function on $X$ is continuous then $X$ is either discrete or indiscrete. If it is not indiscrete then there is some non-trivial open subset $U ⊆ X$.
If there is some subset $A ⊆ X$ which is not open then simply map $A$ into $U$ and $X \setminus A$ into $X \setminus U$. Now we have $f^{-1}[U] = A$, which is a contradiction, as $f$ is continuous.
Comment: This is very clear, thank you.
Comment: @416256 Hello, be sure to formally accept the answer if it was decisive in assisting your question so user87690 can be credited.


How to paginate in Grails?

Question: I am new to grails and I'm trying to achieve pagination in my application.
I have followed the example in the documentation but nothing seems to happen, It cannot render the page navigation buttons. Here's the example code:
def transaction = DataEntry.findAll() as List
    render(model: [transactions: transaction, total: transaction.count ], view: "/Transactions/verify")

then in my view I have put this:
<g:each var="transaction" in="${transactions}">

${transaction.sendersName}

</g:each>

<g:paginate next="Forward"
            prev="Back"
            maxsteps="1"
            controller="approvedTransaction"
            action="index"
            total="${total}" />

any help will be much appreciated!
Comment: Have you tried passing the `params` also as an input to the `paginate` tag? Like params="${params}"
Answer: Check this example
domain class:
class DataEntry{
    String sendersName
}

controller:
class TransactionsController {
    def list() {
        [data: DataEntry.list(params), dataEntryCount: DataEntry.count()]
    }
}

Paginate code:
<g:paginate controller="transactions" action="list" total="${dataEntryCount}" />

OR
<g:paginate next="Forward" prev="Back"
            maxsteps="0" controller="transactions"
            action="list" total="${dataEntryCount}" />

Please refer documentation for more details

How to paginate in Grails?


Learning road map for classical guitar

Question: I have no condition to study classical guitar with a teacher (which I think is the best way to learn) because I'm moving much, and I found online lessons are not suitable for me.
I have read some guitar method books, and it seems that they are quite advanced for me, and I found nowhere to begin.
My question is, is there any learning road map for classical guitar (like in mathematics we have to learn simple arithmetic to understand algebra, etc.). I assume my knowledge in this field is zero.
Comment: Not a clue as to where you are in the world - maybe here there and everywhere! But a start point would be to buy grades 1 and 2 of an examining board's books for classical guitar. Depending where you are, there's a few to choose from. Read and play. This idea means your progress is graded - you don't have to take the exams - but it takes you methodically through from the beginning.
Answer: This is a somewhat broad question, and one which is highly based in opinions.
As a classical guitarist myself, I recommend the Suzuki method, but it is somewhat dependent on having a teacher, and can seem very slow as far as repertoire when starting out. It does however start from zero assumed knowledge and in the longterm sets a great base from which to build up. This is however due to the fact that it is technically meant for children, but there is no real reason that it would not work for an adult.
The Suzuki guitar method has nine books, and goes from very beginner pieces where the focus is on tone, to this.
It is also important, no matter which "curriculum" you chose, that you enjoy the pieces you are playing. After you have played some simple tunes to get a feel for the instrument and have worked on your tone, you should think more broadly about which specific kinds of music do you want to play.

Eg.   Do you want to play more romantic music or more stiff, "Bach-y" music?

Make this decision, then find composers that match it. Or ask here!
If you want something more specific as far as technique, Scott Tennant wrote a series of books called Pumping Nylon, which is essentially a textbook of guitar technique. There are also a lot of important things for classical guitarists beyond technique and repertoire. Things such as nail shape and length are also critical parts of getting the best possible result from your playing.
If you are not going to be able to have a teacher, the overall most important thing is to make sure that you are a harsh critic of your playing; do not let mistakes in things such as tone slide, especially as you start out.
There are also tons of fantastic online resources, the only thing is to make sure they are credible.
My "official" recommendation is that you try the Suzuki method, but feel free to try any pieces that catch your fancy. The one thing to remember is to not get yourself in too deep to a piece that you are not quite ready for yet.
Answer: A lot of kids in the UK are taught with the Guitarist's Way books by Peter Nuttall and John Whitworth.  They are slightly more kid-orientated, but as such start at the very beginning and work upwards using simple tunes and exercises.  You may find them somewhat too basic (all four are pre-Grade 1), but for the price (often under £5), they may be worth looking out for.
A note about exam books, there is (in the UK at least) an Initial Grade exam which was introduced as young children's fingers are often not developed enough for pieces that are equivalent to Grade 1 on other instruments - if you are going the grade route, this book is where to start.  Lots of adults skip the exam, but there is no reason not to learn to play the pieces.
Enjoy!  You won't be playing Segovia overnight, but who cares if you're enjoying yourself.

Learning road map for classical guitar


Lack of rigor when describing prediction metrics

Question: I constantly see metrics that measure the quality of a classifier's predictions, such as TPR, FPR, Precision, etc., being described as probabilities (see Wikipedia, for example).
As far as I know, these are not probabilities but observations of a classifier's predictive behavior estimated during testing: for instance, they measure the rate of observed True Positives, False Positives, and so on.
Wouldn't it be more correct to distinguish these from the actual probabilities? That is, to say that by the Law of Large Numbers, these mesaurements converge to the probabilities. For instance, Precision (the measurement) converges to the Bayesian detection Rate (the actual probability).
Comment: There are numerous such statistics based on confusion matrices. Some of them are probabilities, and some are not.
Answer: These strike me as perfectly reasonable estimates of the parameter of a Bernoulli distribution, which we typically interpret as a probability.
Probability that a classification will be correct (accuracy)
Probability that a positive case will be detected (sensitivity)
Probability that a case asserted to be positive really will turn out to be (precision)
If you want to say that these are just estimates of true probability values (the true Bernoulli parameters), that's fine but also not controversial. We should expect the performance in production to differ at least slightly from what we observe in development.
Comment:  Exactly (+1), some of the statistics computed from a confusion matrix are conditional probabilities.
Comment: @synack: they are a true probability: the probability in the validation set. There is some laziness in not calling them estimates of the value of interest (probability of full population) or not always giving confidence intervals, but this is not the biggest statistical crime of the machine learning community :). Also in many cases, the validation set has millions of rows so the standard error is unlikely to actually be meaningful.
Comment: I've referred to such practices as "slang" a number of times and stand by doing so.
Comment: yes, I agree they are estimates of probabilities, but they are not the true probabilities. My point is precisely that the distinction is important but not sufficiently acknowledged. They say "TPR is the probability that..." when they should say "TPR is *an estimate* of the probability that..."


Why date column doesn't work with group by, return error Subquery returned more than 1 value

Question: I wrote this query it works fine but when I add group by Date to it, then it returns an error:

Subquery returned more than 1 etc

My code:
Declare @FromDate datetime set @FromDate='2014-11-01 09:01:11.927'
Declare @ToDate datetime set @ToDate='2014-11-06 05:01:11.927'
Declare @Day int

Set @Day= (Select Count(*) from Attendance where
  AttendanceDate >= @FromDate AND AttendanceDate < dateadd(day,1, @ToDate )
  AND Attendance.DepartmentShiftHistory_ID=47
  and organization_id=40
  group by Attendance.DepartmentShiftHistory_ID,cast(AttendanceDate as date),User_ID
  )

  print @Day

Comment: So you're grouping by date and the date range you're dealing with covers (parts of) 7 days - and you're surprised that you're getting 7 results rather than 1? What did you think was going to happen here?
Comment: so what can be the solution, i need to group it
Comment: I can't answer that because I don't know *why* you think `group by` is (part of) the solution - I have neither your data nor know your *expected* results. All I've got is a query that is attempting to generate (it appears) a single number and yet is applying a `GROUP BY` clause (where adding one to an existing query can *only* result in possibly splitting a single result into multiple results)
Answer: try with this
Declare @FromDate datetime set @FromDate='2014-11-01 09:01:11.927'
Declare @ToDate datetime set @ToDate='2014-11-06 05:01:11.927'
Declare @Day int

Set @Day= (Select top 1 Count(*) OVER ()  from Attendance where
  AttendanceDate >= @FromDate AND AttendanceDate < dateadd(day,1, @ToDate )
  AND Attendance.DepartmentShiftHistory_ID=47
  and organization_id=40
  group by Attendance.DepartmentShiftHistory_ID,cast(AttendanceDate as date),User_ID
  )

  print @Day

Here i additionally used - top 1 Count(*) OVER ()  i.e. used to get "Count number of records returned by group by statement"
Answer: When you are doing the original query (without grouping), it returns a number like 1337.
When you group it by date, it will return numbers that add up to the original number (1000, 300, 30, 7) and you won't be able to assign that for a variable.
If you wish to have the total number of Days, leave the group by part.
If you would like to have the results of each day, you should insert it to a temp table like
Select AttendanceDate, Count(*)
from Attendance
into #Days
where AttendanceDate >= @FromDate AND AttendanceDate < dateadd(day,1, @ToDate )
AND Attendance.DepartmentShiftHistory_ID=47
and organization_id=40
group by Attendance.DepartmentShiftHistory_ID,cast(AttendanceDate as date),User_ID

SELECT * FROM #Days

Answer: thanks for the replies but none of the solutions worked for me so i tried this and worked
set @Day=(select count(*) from (Select  count(*) 'is' from Attendance where
        AttendanceDate >= @FromDate AND AttendanceDate < dateadd(day,1, @ToDate )
        AND Attendance.DepartmentShiftHistory_ID=@DepartmentShiftHistory_ID
        and organization_id=@OrgID
        group by Attendance.DepartmentShiftHistory_ID,cast(AttendanceDate as date)
        ) as c)


Pymongo find using $in with a list

Question: The folowing expression works fine, returning the values that match the values list:
[...].find({"FieldName":{"$in":["Value1", "Value2", "Value3"]}})

But i have the list of values in a list object, like this:
valuesList = list()
valuesList.append("Value1")
valuesList.append("Value2")
valuesList.append("Value3")

But using the list object, a get no results:
[...].find({"FieldName":{"$in":[valuesList]}})

I Have also tried expanding the list in a formated string, like this:
strList = ', '.join(valuesList)
[...].find({"FieldName":{"$in":[strList]}})

but also, no results.
Note: If i force the list to have only one value, it works. Only when multiple values are suplied, the result is blank.
Any ideas on how to use "$in" in pymongo with a list of values in a list object?
Answer: I believe your problem is the fact that you have a list inside of a list.
Instead of:
[...].find({"FieldName":{"$in":[valuesList]}})
Try:
[...].find({"FieldName":{"$in":valuesList}})

Pymongo find using $in with a list


Click event listener is being repeatedly triggered without any clicks?

Question: I am developing a "Battleship" game with two grids made up of divs and am currently attempting to add a click event listener to all of the divs.
The issue that I am having is that the event listener is being repeatedly triggered (until every single div has been clicked) when I refresh my page and I can't understand why...
Here's the event listener in question:
 let aiGridCells = document.querySelectorAll(".ai-grid__game-cell");
 aiGridCells.forEach(cell => {
    cell.addEventListener("click", humanPlayer.humanAttack(cell.getAttribute('data-ai'),aiPlayer))
 });

Where humanPlayer is an object that has been generated by a factory function:
const humanPlayer = playerFactory('human');

import gameboardFactory from './gameboardFactory';

const playerFactory = (name) => {

    const playerBoard = gameboardFactory();

    const humanAttack = (cell, player) => {   // Where player is opponent
        if (player.playerBoard.gameBoard[cell].id !== 'miss') {
            player.playerBoard.receiveAttack(cell);
        };
    };

    const aiAttack = (player) => {   // Where player is opponent
        const availableCells = [];
        for (let i = 0; i < player.playerBoard.gameBoard.length; i++) {
            if (player.playerBoard.gameBoard[i].id === null) {
                availableCells.push(i);
            };
        };
        const attackCell = Math.floor(Math.random() * availableCells.length);
        player.playerBoard.receiveAttack(attackCell);
    };

    return {
        name,
        playerBoard,
        humanAttack,
        aiAttack
    }

};

export default playerFactory;

and gameboardFactory is:
import shipFactory from './shipFactory';

const gameboardFactory = () => {
    const gameBoard = [];
    const shipYard = [];

    const init = () => {
        for (let i = 0; i<100; i++) {
            gameBoard.push({id: null})
        };
    };

    const checkValidCoordinates = (direction, start, end) => {
        if (direction === 'horizontal') {
            if ((start <= 9) && (end <= 9)) {
                return true;
            } else {
                let newStart = (start/10).toString(10);
                let newEnd = (end/10).toString(10);
                if ((newStart.charAt(0)) === (newEnd.charAt(0))) {
                    return true;
                };
            };
        } else {
            if ((start <= 9) && (end <= 9)) {
                return false
            } else if (start <= 9) {
                let newStart = start.toString(10);
                let newEnd = end.toString(10);
                if ((newStart.charAt(0)) === (newEnd.charAt(1))) {
                    return true;
                };
            } else {
                let newStart = start.toString(10);
                let newEnd = end.toString(10);
                if ((newStart.charAt(1)) === (newEnd.charAt(1))) {
                    return true;
                };
            };
        };
        return false
    };

    const checkIfShipPresent = (direction, start, end) => {
        if (direction === 'horizontal') {
            for (let i = start; i <= end; i++) {
                if (gameBoard[i].id !== null) {
                    return true;
                }
            };
            return false;
        } else {
            for (let i = start; i <= end; i += 10) {
                if (gameBoard[i].id !== null) {
                    return true;
                }
            };
            return false;
        };
    };

    const placeShip = (id, direction, start, end) => {

        if (!checkValidCoordinates(direction, start, end)) {
            return;
        };

        if (checkIfShipPresent(direction, start, end)) {
            return;
        };

        const newShip = [];

        if (direction === 'horizontal') {
            for (let i = start; i <= end; i++) {
                gameBoard[i].id = id;
                newShip.push(i);
            };
        } else {
            for (let i = start; i <= end; i += 10) {
                gameBoard[i].id = id;
                newShip.push(i);
            };
        };

        shipYard.push(shipFactory(id, newShip));
    };

    const receiveAttack = (cell) => {

        console.log(cell)

        if (gameBoard[cell].id !== null) {
            const attackedShip = shipYard.filter((ship) => {
                return ship.id === gameBoard[cell].id;
            })[0];
            if (!attackedShip.hits.includes(cell)) {
                attackedShip.hits.push(cell);
            };
        } else {
            gameBoard[cell].id = 'miss';
        };
    };

    const checkIfAllShipsSunk = () => {
        let allShipsSunk = true;
        shipYard.forEach((ship) => {
            if (ship.isSunk() === false) {
                allShipsSunk = false;
            };
        });
        return allShipsSunk;
    };

    if (gameBoard.length === 0) {
        init();
    };

    return {
        gameBoard,
        placeShip,
        receiveAttack,
        shipYard,
        checkIfAllShipsSunk
    };
};

export default gameboardFactory;

I'm completely lost to what the issue could be and have tried countless things to rectify it. Any suggestions would be hugely appreciated.
Thank you!
Answer: You trying to add actual function call as listener here:
 let aiGridCells = document.querySelectorAll(".ai-grid__game-cell");
 aiGridCells.forEach(cell => {
    cell.addEventListener("click", humanPlayer.humanAttack(cell.getAttribute('data-ai'),aiPlayer))
 });

So on your event listener initialization you actually call your function instead of passing it as a listener.
You can pass it like this instead:
 aiGridCells.forEach(cell => {
    cell.addEventListener("click",  () => humanPlayer.humanAttack(cell.getAttribute('data-ai'),aiPlayer))
 });


Replace a word in a string with another word or sentence

Question: I imported products from my business software to my shop everything worked OK however it only imported part of the description when the description contained characters such as ® and other strange characters.
For example:
Data exported to Shop: X-Ring 10,82 x 1,78 mm BS013 Viton® 75 +/- 5 Shore A schwarz/black
Data imported into Shop: X-Ring 10,82 x 1,78 mm BS013 Viton
After the word Viton everything else was deleted I suppose the character ® was the problem because we are in Europe and the import program did not consider this.
My question is how can I search "Viton" and replace it with "Viton® 75 +/- 5 Shore A schwarz/black"
I cannot change the program nor am I a programmer however I do know how to do a few commands within mysql. I am looking for a command replace "&Viton&" command with "Viton® 75 +/- 5 Shore A schwarz/black"
Thank you very much for your assistance
Comment: Hi, welcome to Stack Overflow. I'm afraid we are a community for programming Q&A, not a self-help service to assist you modifying/fixing some 3rd party code/database. Please make sure to read [how to ask](http://stackoverflow.com/help/how-to-ask) in the help center, before asking.
Comment: @Sherif I tend to disagree a bit with you here. He's not asking us to help fix a 3rd party program or database. He's asking to help fix his own database and it's not like he was asking something that takes more than a min to answer. I agree he should still do his own research before asking, but in this case I don't think it's needed to be so strict about the guidelines.
Comment: `UPDATE your_table SET your_field = REPLACE(your_field, 'Viton', 'Viton®') WHERE your_field LIKE '%Viton%'` Where `®` is the html entity for the symbol. Always backup your data before trying queries though!
Comment: Dear Sir or Madam,

I checked Google for an answer however all answers I found did not seem to fit my needs. I did however discover your Forum / Website through this search.
I am sorry if I violated your forum rules however I thought if I could not find an answer that suits my needs then I can ask the forum. I am not a programmer
nor am I part of a programming company. I am a small company that has nothing to do with software or Hardware just trying to solve a problem myself.

Best regards

Arby
Answer: You may want to use the HTML entity ® or as icecub suggest®  , which will display as the circled R on a web page. Anyway, search replace on a single column like this
Step 1. MAKE A BACKUP OF THE TABLE!
Step 2, execute this query.
update TABLE
set `COLUMN` =
replace(`COLUMN`, 'Viton', 'Viton® 75 +/- 5 Shore A schwarz/black');


If a ring homomorphism is surjective, then the induced map between spectra is a homeomorphism onto its image

Question: Following exercises in Atiyah-Macdonald, I am led to prove the following:
Let $\phi:A \rightarrow B$ be a ring homomorphism, and let $X = \operatorname{Spec}{A}$ and $Y = \operatorname{Spec}(B)$ be the prime spectra of $A, B$, endowed with the Zariski topology. We denote by $\phi^*$ the induced map between spectra $\phi^*:Y \rightarrow X$.
Show that if $\phi$ is surjective, then $\phi^*$ is a homeomorphism onto its image.
I have so far shown that $\phi^*$ is a continuous map. I have also shown that when $\phi$ is surjective, $\phi^*$ is injective. Thus $\phi^*$ is a continuous bijection onto its image. It remains for me to show that $\phi^*$ is an open (or equivalently a closed) map. Any tips on how to go about this ?
Comment: Just a quick comment if you are interested towards algebraic geometry. Such a morphism of rings not only induces the map you mentioned at the level of topological spaces, it also induces a morphism at the level of affine schemes $ (\phi^{*},\phi'):(SpecB,\mathcal{O}_{SpecB})\rightarrow (SpecA,\mathcal{O}_{SpecA}) $ which is a closed immersion. That means that $\phi^*$ is a homeomorphism onto a closed subset, which is the content of your question, and also the morphism of sheafs is surjective.
Answer: Question: "I have so far shown that ϕ∗ is a continuous map. I have also shown that when ϕ is surjective, ϕ∗ is injective. Thus ϕ∗ is a continuous bijection onto its image. It remains for me to show that ϕ∗ is an open (or equivalently a closed) map. Any tips on how to go about this ?"
Answer: @Mr Lolo - there is for any commutative unital ring $A$ and any ideal $I \subseteq A$ a 1-1 correspondence between the prime ideals $\mathfrak{p} \subseteq A$ containing $I$ and the prime ideal $\mathfrak{q} \subseteq A/I$. This is used to prove that the morphism $Spec(A/I)\rightarrow Spec(A)$ is a closed immersion. Moreover (Hartshorne, Corr.II.5.10) one proves that any closed subscheme $Z \subseteq Spec(A)$ arise in this way.
Note: If $\phi$ is surjective and the map $\phi^*:Spec(A/I) \rightarrow Spec(A)$ is open it follows $Spec(A)$ is disconnected: There is a non trivial direct sum decomposition $A \cong A_1\oplus A_2$ and you may write
$$Spec(A) \cong Spec(A_1) \cup Spec(A_2)$$
as a disjoint union of non trivial open and closed affine subschemes.
Comment: @Mr Lolo - when $\phi$ is surjective it follows $B \cong A/I$: There is a short exact sequence $0 \rightarrow ker(\phi):=I \rightarrow A \rightarrow B \rightarrow 0$.
Comment: Thank you for your answer. I am new to most of this, so it will take some digesting of Hartshorne to completely grasp your answer. Could you briefly explain how this applies to $\phi^*:\operatorname{Spec}(B) \rightarrow \operatorname{Spec}(A)$ when $B$ is not a quotient of $A$ ?
Comment: Oh yes of course ! Great thank you.


CentOS new Tiger VNC version

Question: I have Tiger VNC Server 1.3.1 installed on my CentOS7 system.
Is there an easy and quick solution to install the newest version of TigerVNC Server?
Thank you!
Answer: Yes you can use below command to install or update Tiger VNC Server package.
<code>yum -y install tigervnc-server    # To install the Package

yum update tigervnc-server   # To Update the Package
</code>
Follow the below link for more guidance.
http://www.elinuxbook.com/tigervnc-server-configuration-remote-desktop-application-for-linux/
Answer: Updating any packege in CentOS, if you use YUM for installation, for all packages is following:

yum update

For a certain package

yum update package_name

for check is there any available updates

yum check-update

CentOS new Tiger VNC version


Is there a best way to compare different classifiers?

Question: I'm currently analyzing the same data using lasso, elasticnet and random forest classifiers. I'm just wondering if there is a best way to compare these three models(eg. AUROC, accuracy, mcnemar's test), or I should compare multiple features and trying to figure out if they all favour the same model?
Comment: This might be of use: http://stats.stackexchange.com/questions/217466/for-model-selection-comparison-what-kind-of-test-should-i-use/217475#217475
Answer: In machine learning, there is no one algorithm that's always better than others which is as per the "No free lunch theorem". Therefore, one has to try with different set of classifiers and choose the best one.
Now it is also important to statistically compare the classifiers to know whichone is the best one. One way is to carry out one-way ANOVA followed by post hoc tests using Tukey-Kramer method for multiple comparison analysis to determine which pairs of means are significant and which are not. This generates a graph, similar to box plot where two means are significantly different if their intervals are disjoint, and are not significantly different if their intervals overlap.
For more info, refer to  this research paper
More useful links:
http://www.cse.iitd.ac.in/~sumantra/publications/ijmi16_nonmotor.pdf
http://machinelearningmastery.com/compare-machine-learning-algorithms-python-scikit-learn/
Comment: @hirschme They could also be used I guess. Take atleast 100 different partitions of the data and evaluate the classifier metrics. In this case, generally, the metrics are likely to follow normal distribution. If not, then it shows that the characteristics of the training data is changing drastically with partitions.
Comment: Is there a good reason to use ANOVA instead of a non-gaussian assumption (non-parametric) version like Chi-square / Friedman-test? I rarely find classifier output metrics to be even nearly normally distributed.
Comment: What means would you be comparing?
Comment: @rolando2 means of all the classifier metrics that you want to compare. It could be accuracy, AUC, sensitivity and/or specificity.
Comment: You could add these new explanations to your answer.


jQuery tabs, link to another tab from inside

Question: I have jQuery ui tabs and I would like to be able to open a tab from a link (inside or outside the current tab or page)
It does work if the link is in an external page and looks like this:
http://server.com/view.php?id=130#section-2

This correctly open the tab "section-2"
The problem is when the link is in the same page, it does not refresh the page (as it just add the #section-2) so the tab is not selected.
I saw some answers example using ids in the  tag and binding the click in jQuery, but I cannot use this because some of my links are computed and I don't know if they are pointing to inside or outside.
Comment: jQuery ui is a heavy libary, you can write your own simple tabs script and do whatever you want. Check this example: http://stackoverflow.com/questions/11724962/jquery-hover-show-div-toggle/11725216#11725216
Answer: Add the id "section-2-link" to the  tags linked to the tabs (add the '-link' at the end to avoid having same id as the tab content). And then add this to js
jQuery(window).bind('hashchange', function () { //detect hash change
    var hash = window.location.hash.slice(1); //hash to string (= "section-2")
    jQuery('#' + hash + '-link').trigger("click");
});

This detects when the hash on url changes and trigger the click on the link you need (to open the correct tab)


How to transform select options from views exposed filters to clickable link areas?

Question: I have asked more generally in stack overflow
https://stackoverflow.com/questions/49491094/how-to-transform-select-options-to-clickables-link-areas?noredirect=1#comment85985442_49491094
How can I make my exposed filters look like this?
<select data-drupal-selector="edit-field-video-theme-target-id" id="edit-field-video-theme-target-id" name="field_video_theme_target_id" class="form-select"><option value="All" selected="selected">- Tout -</option><option value="9">A*midex</option><option value="11">Bibliothèque</option><option value="10">Relation entreprise</option><option value="8">Université</option></select>

Is it possible to transform select/options to ul/li?
Is it possible to override the template views-exposed-form--videos.html.twig?
Comment: Have you tried [Better Exposed Filters](https://www.drupal.org/project/better_exposed_filters)? If I remember correctly, it has a feature to turn options into clickable links
Comment: i am not that keen anymore to use alpha versions
Answer: It is possible to override the template, you shall just create it in your theme and then clear the cache.
In your new template you can just change the select list to a ul
The template that you want to override may only contain {{ form }}.
Then you must find the preprocess function in the module or theme.
Comment: it does not seem as simple since the template for views exposed form  is {{ form }} . How can i go deep inside?
Answer: There is nothing integrated into drupal at the moment but you can probably use select2Buttons in your theme.
just include it in your theme and in custom javascript you can call
$('select[name=simple-select]').select2Buttons();

Answer: If i understand you correctly you could create a file views-exposed-form--videos.html.twig(I am not sure with the name just check it with twig debug) and add the following code in it
<# add your styled html with attribute name = "field_video_theme_target_id" #>

- Tout -

A*midex

Bibliothèque

Relation entreprise

Université

{{ form|without('field_video_theme_target_id') }}

Comment: it would be good to keep the logic. options are taxonomies from a entity reference field
Comment: kint() or dump() the variable field_video_theme_target_id in the twig file. i think you will be able to display the values there using some loop.


How can I print Views language-specific $field variable values inside a views template?

Question: I am using Views with "Format Show:Content" instead of "... fields."
I have a multilingual website. In the filters section of Views I have Content: language = user's default language. However, Views refuses to honor this filter selection.
I am also using views-view-fields.tpl.php file to output the fields. currently it is calling, for example, $fields->content to output content.
How can I get Views in Show Content format to honor the language filter? I am familiar with needing to add the 'und' key to certain fields at times, but do I need to do that here? Should adding the filter in the view not be enough? If I do need to add the key where does it go?
If you want, you can see the error in the slideshow at http://goniseko.com
Answer: Use dpm() to output $field in your template.
To make PHP not die with an out of memory error, use a static flag to ensure it only prints once.
<code>static $_foo;
if (!$_foo) {
  dpm($field);
  $_foo = TRUE;
}
</code>


Intuition to the Resolution of a fractional factorial design

Question: In design of experiments, is there an intuitive way to understand (and explain) the idea of the "resolution" of the design?
Answer: The concept of resolution is applied to fractional factorial experiments. Following the excellent Statistics for Experimenters: Design, Innovation, and Discovery, 2nd Edition, for a half-design (that is, using one half of a full facorial deign), the resolution is the length (number of letters in) its generating relation. For quarter-design, with two words in its generating relation, it would be the length of the shortest word, and similarly for smaller fractions.
For instance, a full factorial design on three (two-level) factors, denoted A, B, C, we could define a half-fraction by C=AB. Multiplying through with C this is equivalent with e (identity element, or vector of only ones)=ABC, which is the generating relation, of length three, so resolution III. The form C=AB shows that the main effect of C is aliased with the interaction AB, showing that this design is mostly useful if we can assume no interactions.
So, intuitively, we can say

Resolution III, some main effects aliased with two-factor interactions.
Resolution IV, some main effects aliased with three-factor interactions, and some two-factor interactions aliased with other two-factor interactions.
Resolution V, some main effects aliased with four-factor interactions, some two-factor interactions aliased with three-factor interactions, but never with other two-factor interactions, ...


Projection of a function onto another

Question: In a metric space, I can imagine projection of a vector onto another (also called dot product). Or in general any vectors of form $[v_1,v_2,v_3,\cdots]$ I know how to compute their projection onto one another. But for continuous vectors, like when using functions as a vectors, I can't imagine what does dot-product (or inner product) or projection quite means. Can anyone help me with this?
Comment: For instance, one way to define the inner product of two square integrable functions $f$ and $g$ is $\langle f,g\rangle=\int_I f(x)\overline{g(x)}dx$, where $I$ is some (measurable) subset of the domain of two functions and the overline denotes the complex conjugate. Then with an inner product, you can define projection on to vectors.
Comment: @FrankLu, when talking in metric space, I can visualize projection of vector a onto vector b, as how much part of a lies in b. But when talking about functions, I can't quite visualize that. For example sin(x) and cos(x) are orthogonal to each other, $\int_{-\pi}^{\pi} sin(x)cos(x)dx =0$, so it should mean in a time period no component of sin(x) should lie on cos(x) mathematically, but how do I intuitive understand this?
Comment: perhaps this: http://math.stackexchange.com/questions/1414389/what-is-the-geometric-meaning-of-the-inner-product-of-two-functions  will help
Answer: Let's reconsider the familiar vector space $\mathbb R^2$ for a moment, examine the properties of that space and how they might inform an intuition about vector spaces of functions, and try to distinguish good intuition from harmful intuition.
Consider the vectors $(1,1)$ and $(2,-2).$
If you look only at their $x$ coordinates, the vectors appear to be in the same direction.
If you look only at $y$ coordinates, the vectors appear to be opposite.
In fact, the vectors are orthogonal, but to find this from their coordinates you must look at all of their coordinates.
If all you know about a vector is its $x$ coordinate, you know very little about its direction. It could be almost straight up, almost straight down, or anything in between.
Trying to compare functions $f(x)$ and $g(x)$ by looking at only one value of $x$ is worse than trying to find the angles of vectors by looking at only one coordinate. To decide whether functions are orthogonal you have to look at the entire region over which the inner product is measured, and find out whether the functions tend to imitate one another, oppose one another, or neither.
Another property of vectors in $\mathbb R^2$ is that if you project an arbitrary vector onto each of two orthogonal vectors, and then add the two projected vectors, you get back the original vector.
This does not work if the vectors you project onto are not orthogonal.
But it does work for projecting a function onto other functions, provided that the functions you project onto are orthogonal.
(It also may require an infinite set of such functions to project onto, because the typical function vector spaces we look at have that many dimensions.)
Consider the space of continuous real-valued functions $f$ such that $f(x+2\pi)=f(x),$ with the inner product
$$
\langle f,g \rangle =
\frac{1}{2\pi} \int_0^{2\pi} f(x)g(x)\,dx.
$$
The sine and cosine functions are in this space and are orthogonal. Although they are almost always both non-zero, they oppose each other as much as they reinforce each other, and the integral comes out to exactly zero.
For $0<\alpha<\frac\pi2,$ the function $\sin(x+\alpha)$ also is in this space but is not orthogonal to either $\sin(x)$ or $\cos(x).$
Instead, its inner product with $\sin(x)$ is  $\frac12\cos(\alpha)$ and its inner product with  $\cos(x)$ is $\frac12\sin(\alpha).$
But if we take the inner product of $\sin(x)$ with itself, we get $\frac12,$ and the same is true for $\cos(x).$
So if we use the usual formula for projecting a vector $v$ onto a vector $u,$
$$
\left(\frac{\langle v,u \rangle}{\langle u,u \rangle}\right) u,
$$
and use it to project $\sin(x+\alpha)$ onto the sine and cosine functions, we get (respectively)
$$
\cos(\alpha)\sin(x) \qquad \text{and} \qquad \sin(\alpha)\cos(x).
$$
And as we know from the identity for the sine of an angle sum, the sum of these two functions gives us back the function $\sin(x+\alpha).$
So this particular intuition from the vector space $\mathbb R^2$ does carry over at least somewhat into at least one inner product space of functions. If you look at the derivation of a Fourier series for a periodic function, this idea of adding the projections onto orthogonal functions works quite well.

Projection of a function onto another


Go Gin Setting and Accessing context value from middleware

Question: I am trying to set my user context, in the middleware then trying to check if user have permission in other handler functions. But for some reason when I try to access the user from context it is coming back as nils. The middleware code seems to be working, when I pass a valid jwt token, it is showing the user is being set in context in the middleware function. But as soon as I hit getCurrentUser function it says it's nil.
Here is the code:
Middleware
// Middleware wraps the request with auth middleware
func Middleware(path string, sc *cfg.Server, orm *orm.ORM) gin.HandlerFunc {
    logger.Info("[Auth.Middleware] Applied to path: ", path)
    return gin.HandlerFunc(func(c *gin.Context) {
        t, err := ParseToken(c, sc)
        if err != nil {
            authError(c, err)
        } else {
            if claims, ok := t.Claims.(jwt.MapClaims); ok {
                if claims["exp"] != nil {
                    issuer := claims["iss"].(string)
                    userid := claims["jti"].(string)
                    email := claims["email"].(string)
                    if claims["aud"] != nil {
                        audiences := claims["aud"].(interface{})
                        logger.Warnf("\n\naudiences: %s\n\n", audiences)
                    }
                    if claims["alg"] != nil {
                        algo := claims["alg"].(string)
                        logger.Warnf("\n\nalgo: %s\n\n", algo)
                    }
                    if user, err := orm.FindUserByJWT(email, issuer, userid); err != nil {
                        authError(c, ErrForbidden)
                    } else {
                        if user != nil {
                            c.Request = addToContext(c, consts.ProjectContextKeys.UserCtxKey, user)
                            logger.Debug("User: ", user.ID)
                        }
                        c.Next()
                    }
                } else {
                    authError(c, ErrMissingExpField)
                }
            } else {
                authError(c, err)
            }
        }
    })
}

routes
// User routes
func User(sc *cfg.Server, r *gin.Engine, orm *orm.ORM) error {
    // OAuth handlers
    mw := auth.Middleware(sc.VersionedEndpoint("/user/:id"), sc, orm)
    g := r.Group(sc.VersionedEndpoint("/user"))
    g.Use(mw)
    g.GET("/:id", mw, user.Get(orm))
    g.PUT("/:id", mw, user.Update(orm))
    g.POST("/", user.Create(orm))

    return nil
}

handler
func Get(orm *orm.ORM) gin.HandlerFunc {
    return func(ctx *gin.Context) {
        cu := getCurrentUser(ctx)
        if ok, err := cu.HasPermission(consts.Permissions.Create, consts.EntityNames.Users); !ok || err != nil {
            ctx.String(http.StatusUnauthorized, "BAD")
        }
    }
}

addToContext:
func addToContext(c *gin.Context, key consts.ContextKey, value interface{}) *http.Request {
    return c.Request.WithContext(context.WithValue(c.Request.Context(), key, value))
}

getCurrentUser:
func getCurrentUser(ctx context.Context) *dbm.User {
    cu := ctx.Value(utils.ProjectContextKeys.UserCtxKey).(*dbm.User)
    logger.Debugf("currentUser: %s - %s", cu.Email, cu.ID)
    return cu
}

Comment: Add the code for `addToContext` and `getCurrentUser`.
Comment: added those functions
Answer: The problem is that you're storing the user in one context but then you're attempting to retrieve the user from another context. The value *gin.Context and the value *gin.Context.Request.Context are two separate context values.
You're using the Request's context to store the user:
c.Request.WithContext(context.WithValue(c.Request.Context(), key, value))

And then you're using the gin context to retrieve the user:
func getCurrentUser(ctx context.Context) *dbm.User {
    cu := ctx.Value(utils.ProjectContextKeys.UserCtxKey).(*dbm.User)
    // ...

func Get(orm *orm.ORM) gin.HandlerFunc {
    return func(ctx *gin.Context) {
        cu := getCurrentUser(ctx) // here you're passing *gin.Context to the function.
        // ...

So to fix that change the value that's passed in to the getCurrentUser call to:
func Get(orm *orm.ORM) gin.HandlerFunc {
    return func(ctx *gin.Context) {
        cu := getCurrentUser(ctx.Request.Context())
        if ok, err := cu.HasPermission(consts.Permissions.Create, consts.EntityNames.Users); !ok || err != nil {
            ctx.String(http.StatusUnauthorized, "BAD")
        }
    }
}


Is there a standard non-Fux counterpoint method?

Question: The OP for this question refers to a rule for second-species counterpoint which isn't mentioned in Fux's Gradus ad Parnassum. The answer confirms it, and adds yet another rule, referring to "strict Baroque counterpoint".
Is there a standard well-known resource (perhaps like R Strauss' extension to Berlioz's Orchestration) that the answerer may have been referring to, especially with regards to what is considered a "good melody"?
Answer: Fux was of course trying to model Palestrina's style.  That's where all the rules come from, which is of course a little bit of reverse engineering, which means that different theorists have different interpretations of what is allowed, what constitutes common practice and so forth.  Obviously, the rules are different in Lassus or Josquin des Prez, etc.  Furthermore, the pedagogical side of things means that species counterpoint is helpful by dividing up a complex task of free composition into a few specific situations that cover most things you would encounter in the music of Palestrina.
Fux was a pioneer of this approach to teaching composition, but for my money, I like the book by Jeppesen as a much more accurate and approachable tutorial on Palestrina's style. Some people also like Gauldin's books.


How can I set environment variables for a different user

Question: I'm trying to get 2 docker containers started and linked together with a rails app.  This app relies on these environment variables:
POSTGRES_PORT_5432_TCP_ADDR
POSTGRES_PORT_5432_TCP_PORT

When I do env as root I'm getting:
POSTGRES_PORT_5432_TCP_PORT=5432
POSTGRES_PORT_5432_TCP_ADDR=172.17.0.2

When I run it under root I'm not getting any problem and it works.  However the application runs as app user.  When I do env as app:
root@f80f94948393:/home/app# sudo -u app env

I'm not seeing those variables.  I googled around and have altered these files already:
/etc/environment
POSTGRES_PORT_5432_TCP_ADDR="172.17.0.2"
POSTGRES_PORT_5432_TCP_PORT="5432"

/home/app/.profile
POSTGRES_PORT_5432_TCP_PORT="5432";export POSTGRES_PORT_5432_TCP_PORT
POSTGRES_PORT_5432_TCP_ADDR="172.17.0.2";export POSTGRES_PORT_5432_TCP_ADDR

/home/app/.bashrc
POSTGRES_PORT_5432_TCP_PORT="5432";export POSTGRES_PORT_5432_TCP_PORT
POSTGRES_PORT_5432_TCP_ADDR="172.17.0.2";export POSTGRES_PORT_5432_TCP_ADDR

But nothing seems to help.  The variables aren't showing up with app user.
What am I missing here?
Answer: I do not know how you run the program as non-root, bu when you use
sudo, you may use -E (see: man sudo) that should preserve env.
Otherwise you may add those variables into system-wide .bashrc (/etc/bash.bashrc) if you use bash at all.


Create a Cluster Shared Volume with 3 Servers

Question: I'm new to Failover Cluster and everthing that has to do with it. At the moment I have two Hyper-V hosts connected to a VLAN and a third server which I would like to use as a file server so the VMs will be highly available.
The two Hyper-V Hosts are directly connected to the third Server over ethernet. I would like to know if it is even possible to achieve high availability with this setup? I read about SMB3 but I'm not sure if this can work because I don't know that much about it.
I don't need a step-by-step process on what I have to do. I just wanna know if it's possible or not.
Answer: Yes you can, but never use a single storage server to achieve HA. In the described configuration, you will only achieve HA on your compute layer while your storage layer is a SPOF.
Try StarWind VSAN or HPE VSA they both have free and paid versions available. You can build a shared storage from the local DAS using such software. This is called "Hyper-Converged" setup.
Basically, this software will replicate each incoming block of data between two (or three) hosts, which allows you to create a highly available iSCSI target for your Failover Cluster. Should one of your hosts die - you have another one to keep your production up and running.
And don't forget to add the new Cluster Disk as CSV which is the place where VMs should be stored in order to make them HA.
Here's a step by step guidance from StarWind, this will help you to better understand the idea: https://www.starwindsoftware.com/technical_papers/Hyperconverged-scenario-Basic-2-Node-Setup-manual.pdf
Answer: You could use iSCSI.
Read this short guide here:
https://www.howtoforge.com/using-iscsi-on-ubuntu-10.04-initiator-and-target


Successive over-relaxation method for solving partial differential equations and pure Neumann boundary conditions

Question: I've recently posted this question on Computational Science Stack Exchange in hopes of getting some insights on how to deal with ill-conditioned 2D Poisson partial differential equation (PDE) which arises when the boundaries imposed on the edges of the computational region are non-zero finite Neumann boundary conditions. The specifics of the problem revolve around the successive over-relaxation method (SOR) which is used as a proffered numerical solver. Unfortunately, there I received mostly generic answers and comments, or comments which mostly apply to a different type of solvers. It is for this reason I am reaching out to the Mathematics Stack Exchange community for some additional technical details.
Majority of the implementation details (code+discretization scheme) you can find in the link to my original question I provided above. I will here summarize briefly the setup and the problem statement:
The equation I am trying to solve (in 2D) is Poisson PDE $$\nabla(\epsilon\nabla\varphi)=\rho,$$ which is generally supposed to be solved in arbitrary 2D geometry. The discretization and code implementation is based on the finite differences. The PDE should be able to be solved for any combination of the Neumann's and the Dirichlet's boundary conditions, including a case where only Neumann's or only Dirichlet's boundaries exist. Out of the two options, the situation where I only have Neumann boundaries (which is possible in a lot of physical systems) is a problematic one, as it leads to a situation where there is no unique solution for the PDE, being that $\varphi+const$ solves it, and $const$ can be anything. Typically, the Neumann boundaries are defined as: $$\frac{\partial\varphi}{\partial x}(x=X_{0,1}, y)\to G_{0,1}$$ and $$\frac{\partial\varphi}{\partial y}(x, y=Y_{0,1})=H_{0,1},$$where $X_0, X_1, Y_0, Y_1$ are initial and final point along the numerically relevant x-axis and y-axis, respectively, and $G_0, G_1, H_0, H_1$ are the boundary conditions along x and y axis at those places. In general, $G_{0,1} = G_{0,1}(y)$ and $G_{0,1} = G_{0,1}(x)$, but for the sake of argument here, let's keep them constant.
Due to the way how I discretized the equation (in the link to the original post), it turns out that if $G_0=-G_1$ and $H_0=-H_1$ the SOR solver is not able to converge, and it starts stalling until it reaches the maximal allowed number of iterations. Under normal operation, it should converge for significantly lower number of iterations than the maximally allowed, but for this particular scenario this is not the case.
I am lead to believe that the reason for the convergence stall is the fact that the Neumann boundary conditions, which I store in the right-hand side (RHS) of the equation together with the source term, $\rho$, invalidate the requirement that the mean of the RHS should be zero.
For instance, if $G_0=G_1$ and $H_0=H_1$, stall does not arise (at least I have not seen it in the examples I've tested, it might as well be still present and hidden).
It is this problem of the convergence stall I have and I currently do not know how to solve, so I am looking here a possible answer to resolve the issue.
Up to now, I have seen suggestions to replace one of the Neumann boundaries with a Dirichlet one, which simply is not possible for some problems which demand all-Neumann conditions. Another thing was Tikhonov regularization in the form of small positive constant multiplying the $\varphi$ on the left-hand side (LHS) of the Poisson equation as: $$\nabla(\epsilon\nabla\varphi)-\varepsilon\varphi=\rho, \varepsilon>0.$$This seems like an interesting and implementable solution, but I am not sure if there is any special form it takes for SOR. In fact, straight-forwardly adding a small positive value (1e-6 - 1e-3) to the main diagonal term yielded no change in observed behavior.
Thus, any technical insights and fixes you can propose for ill-condition Poisson PDE with pure Neumann boundaries would be rather helpful.
Many thanks in advance!
Comment: I am pretty certain that this comment from Computational Science Stack Exchange is correct and how commercial codes work (picks a point automatically): "The general way to deal with the non-convergence is to add some extra constraint. For example, you could fix a single node in a corner to a Dirichlet value." This is both numerically and mathematically a good, general, and efficient way of handling this. You may get "accidental convergence" in some cases. However,  you might discover that changing the density of your discretization (refining) will make it stop converging again.
Comment: @Jap88, indeed, I fear that accidental convergence is the case in those special situations. It also could be that I am by accident satisfying the extra constraint that the integral of the right hand side is zero.
Regarding the single-node Dirichlet's BC, I've tried something like this already. Unfortunately, this results in some nonsensical solution. Either I am doing something wrong or I am missing something. I will try to document here soon my attempts with all possible approaches I tried, so it is easier to understand the problem.
Answer: The issue, as it seems, revolves around the compatibility condition which the right-hand side of the Poisson equation and the Neumann boundary conditions must satisfy. This is also addressed in this post. If this condition is not satisfied, then the problem is ill-posed, and it simply cannot be solved. Thus one needs to redefine the problem in some way to make it either well-posed or ill-conditioned.
As often suggested, adding a single point in which Dirichlet's boundary condition is specified is a way of redefining a system to a well-posed problem.
Interestingly, one may face the same problem with pure periodic (torus) boundary conditions, as the boundary value problem in that case should also satisfy the compatibility condition in order to be solvable.
So to summarize, the problem was not in the solver algorithm, it is in the problem definition.


Can we modify the weight function of particle filters?

Question: I am doing some experiments on particle filtering and I have a problem calculating the weights. Normally, the weights should be decided based on a function $w_{s_t}=p(z_t|s_t)$, if this distribution is normal, then $w_{s_t}\propto \exp(-1/2(z_t-s_t)'\Gamma^{-1}(z_t-s_t))$, where $\Gamma$ is the covariance matrix.
But in my case, $\Gamma$ is very small in scale. Then all the $w_{s_t}$ are zeros when I compute using Matlab. So I am wondering, can I modify the distribution by changing a different $\Gamma$? For example, let  $\Gamma=I$, an identity matrix, then $w_{s_t}\propto exp(-1/2(z_t-s_t)'(z_t-s_t))$. In this way, the all the weights are non-zero and can be compared.
Answer: Let $x_{s_t}=−0.5\cdot (z_t−s_t)′Γ^{−1}(z_t−s_t)$. I suggest you to:

compute all the log weights $x_{s_t}$, then compute $x_{max}=\max_t x_{s_t}$.
compute the weights as $w_{s_t}=\exp{(x_{s_t}-x_{max})}$.

As the weights are computed up to multiplicative constant this works and allows to exponentiate non too small values so that the weights are computed with a good accuracy (allowing them to be non zero, at least, for the highest one).
I think that it will solve your problem. Changing the formula for the weights without changing the proposal is not correct.
Comment: Thank you for your suggestion and I am testing this method. I found this paper: http://ieeexplore.ieee.org/Xplore/defdeny.jsp?url=http%3A%2F%2Fieeexplore.ieee.org%2Fstamp%2Fstamp.jsp%3Ftp%3D%26arnumber%3D7079001%26userType%3Dinst&denyReason=-134&arnumber=7079001&productsMatched=null&userType=inst. On paper 81, there is a generalized resampling. I am thinking if I set $\Gamma=I$, is it equivalent with applying a generalized resampling. That is, I set $w_{s_t}=\tilde{w}_{s_t}^{\alpha}=(exp(-0.5(z_t-s_t)'(z_t-s_t)))^{\alpha}$, where $\Gamma=1/\alpha I$.
Comment: I quickly read about generalized resampling and I think that you miss the fact that resampling is different from estimating the weights and whatever the way you resample you need to estimate the weights and this can anly be done according to the weighting formula which in your case consists of the likelihood. The solution I give you allow you to compute the weights appropriately (don't forget to mark the answer as accepted if it actually works). Hope it helps.
Comment: I tried your idea. But I got almost all zero weights as well and only one 1, which is the weight of $x_{max}$. In my case, all $x_{s_t}$ are between $-6\times 10^{7}$ to $-2\times 10^7$. What I suggested is, in principle, we calculate the weights first and then we do resampling. But in practice, we do the two steps together.
Comment: Sorry, I am not sure to follow you. What I can say is that the weights must be computed using to the covariance matrix of your statistial model: $\Sigma$. Then you can use another density to resample the particles (as in eneralized resampling). The fact that most of the particles have weights 0 compared to a very few has weights close to one simply says that the 0 weights particles are very unlikely compared to those having weights close to one. So they must have very small weights compared to the other (say it is $10^{-10}$ if you prefer something different from 0). Hope it helps.
Comment: I think I finally solve the problem by using vpa in Matlab. In this way, I can keep the extremely small numbers instead of zero. Thank you for your patient.


Firebase Crash report not appearing in android after Firebase crashlytics update

Question: I am not able to view the Crash Report , after update Firebase crashlytics dependency in Android. Even my Firebase console shows, "You have the latest SDK installed". kindly refer my build details.
build.gradle
buildscript {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.2'
        classpath 'com.google.gms:google-services:4.3.4'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'
    }
}

allprojects {
    repositories {
        google()
        mavenLocal()
        mavenCentral()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(:app)
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.crashlytics'

android {
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    compileSdkVersion 28

    defaultConfig {
        applicationId "com.XXX.XXX"
        minSdkVersion 16
        targetSdkVersion 28
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        renderscriptSupportModeEnabled true
        multiDexEnabled true
    }

    buildTypes {
        release {
            // signingConfig signingConfigs.release
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            // resValue "string", "app_name", "$app_name_release"
        }

        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
            buildConfigField "String", "TYPE", '"DEBUG"'
        }
    }
    flavorDimensions "mode", "key"

    productFlavors {
        lite {
            dimension "mode"
            applicationId "com.xxx.xxx"
            versionCode 23
            versionName "4.4.3"
            manifestPlaceholders = [app_name: "Pro-Inspector"]
        }

        pi {
            dimension "mode"
            applicationId "com.xxx.xxx"
            versionCode 53
            versionName "4.4.3"
            manifestPlaceholders = [app_name: "Pro-Inspector"]
        }

        local {
            dimension "key"
        }

        sandbox {
            dimension "key"
        }

        demo {
            dimension "key"
        }

        dev {
            dimension "key"
        }

        production {
            dimension "key"
        }

        live {
            dimension "key"
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    variantFilter { variant ->
        def modeName = variant.flavors*.name
        def keyName = variant.flavors*.name

        // To check for a certain build type, use variant.buildType.name == "<buildType>"
        // Gradle ignores any variants that satisfy the conditions below

        if (modeName.contains("lnt") && keyName.contains("demo")) {
            setIgnore(true)
        }
        if (modeName.contains("pi") && keyName.contains("dev")) {
            setIgnore(true)
        }
        if (modeName.contains("pi") && keyName.contains("production")) {
            setIgnore(true)
        }
        if (modeName.contains("lnt") && keyName.contains("live")) {
            setIgnore(true)
        }
    }
}

dependencies {
    implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
    implementation 'com.google.firebase:firebase-analytics:18.0.0'
    implementation 'com.google.firebase:firebase-core:18.0.0'
    implementation 'com.google.firebase:firebase-messaging:21.0.0'
    implementation 'com.google.firebase:firebase-auth:20.0.0'
    implementation 'com.google.firebase:firebase-messaging-directboot:21.0.0'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    // RETROFIT
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    // GLIDE
    implementation 'com.github.bumptech.glide:glide:4.3.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.3.1'
    // VIEWMODEL
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel:2.0.0'
    api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'

    implementation 'org.greenrobot:eventbus:3.1.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.android.material:material:1.1.0-alpha02'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.daasuu:EasingInterpolator:1.0.0'
    implementation 'com.google.android.gms:play-services-vision:20.1.2'
    implementation 'com.google.android.gms:play-services-location:17.1.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services-identity:17.0.0'
    implementation 'com.google.android.gms:play-services-location:17.1.0'
    implementation 'com.google.android.gms:play-services-places:17.0.0'
    implementation 'org.adw.library:discrete-seekbar:1.0.1'
    implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1@aar'
    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    androidTestImplementation 'androidx.multidex:multidex:2.0.1'
    androidTestImplementation 'androidx.multidex:multidex-instrumentation:2.0.0'
    implementation 'commons-io:commons-io:2.0.1'
    testImplementation 'junit:junit:4.12'
    implementation project(':pdfviewer')

    //retrofit dependencies
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel:2.2.0'

}
apply plugin: 'com.google.gms.google-services'

Anybody faced this issue already? Can anyone please help me to view crashes in console
Answer: I also faced the same issue and to solve this I did the following steps.

After new Crashlytics SDK were added. Download the new Google-services.json file from the Firebase console (you can get it from Project Settings in Firebase console)

Force a crash for first time.
 throw new RuntimeException("Test Crash");

Run your app.It will crash because we were added above Runtime exception.

Now check on your Firebase console. You can see the crash report
Refer HERE
Comment: For the first time , my Application crashes not displayed in console. After making this crash, my other crashes of the application displayed in console. Thanks .
Note: We need to enable console settings too.
Comment: @Gowrisankari Ravindran What do you mean by "enable console settings"? I have same problem and It could not be solved with this.
Comment: @MohammadRezaLohrasbi Simply make sure your Application (both debug & release)  is Enabled Crashlytics settings in firebase. Not any other special permissions.
Firebase console -> Select Project -> Quality (left side menu ) - >Crashlytics ->Enable
Answer: In my case, I made the silly mistake of doing:
FirebaseCrashlytics.getInstance().setUserId(uid);

where uid was still null.


How session works in coldfusion?

Question: I have some doubts regarding the session and client management in coldfusion.

Note: The behavior is as follows when CFID and CFTOKEN are provided in the URL: If session exists, the CFID and CFTOKEN from the URL are ignored. If the session does not exist, CFID and CFTOKEN from the URL are used to validate the session and the session is used if it is valid. If the session is not valid, a new session is created. CFID and CFTOKEN are regenerated.

This is a statement from adobe ColdFusion online documentation. Below are my questions

How ColdFusion checks if the session exists without the help of CFID and CFTOKEN as in the first sentence?
Suppose we are using ColdFusion session management, if the CFTOKEN and CFID doesn't change after login can we hijack the session?
Comment: Be sure to read about the recommendations regarding ColdFusion sessions and cookies in the [lock down guide](http://wwwimages.adobe.com/content/dam/acom/en/products/coldfusion/pdfs/coldfusion-2016-lockdown-guide.pdf).
Answer: ColdFusion checks for a valid session by checking if CFID and CFTOKEN exist in the cookies scope. If the CFID and CFTOKEN cookies exist, it will use the cookie values to try and validate the session. If it can't validate the session using the cookie values, it will use the URL values to try and validate the session.
Comment: If I understood it correctly, the documentations says this case when cookies disabled. So _If session exists, the CFID and CFTOKEN from the URL are ignored._ this line makes me confuse. If there is no cookies how ColdFusion checks if the session exists?
Comment: ACF uses CFID/TOKEN, or alternately JSESSIONID ( JEE Sessions through CF Admin setting) to maintain session state. Without those variables, ACF can't maintain session state. Do you have a link to the specific docs that are confusing you?
Comment: https://helpx.adobe.com/coldfusion/developing-applications/developing-cfml-applications/using-persistent-data-and-locking/managing-the-client-state.html - In this "Using client and session variables without cookies" this section
Comment: The language isn't clear because of where they placed it. What it should say is: if cookies are enabled and the session exists, the CFID and CFTOKEN on the URL will be ignored. That is the expected behavior of ACF.
Answer: Using client and session variables without cookies
It's possible for users to disable cookies in their browsers. In this case, ColdFusion cannot maintain the client state automatically. You can use client or session variables without using cookies, by passing the client identification information between application pages. However, this technique has significant limitations, as follows:

Client variables are effectively the same as session variables, except that they leave unusable data in the client data store.
Because the client's system does not retain any identification information, the next time the user logs on, ColdFusion cannot identify the user with the previous client and must create a new client ID for the user. Any information about the user from a previous session is not available, but remains in client data storage until ColdFusion deletes it. If you clear the Purge Data for Clients that Remain Unvisited option in the ColdFusion Administrator, ColdFusion never deletes this data.
Therefore, do not use client variables, if you allow users to disable cookies. To retain client information without cookies, require users to login with a unique ID. You can then save user-specific information in a database with the user's ID as a key.
ColdFusion creates a new session each time the user requests a page directly in the browser, because the new request contains no state information to indicate the session or client.

Note: You can prevent ColdFusion from sending client information to the browser as cookies by setting This.setClientCookies variable in Application.cfc or the setClientCookies attribute of the cfapplication tag to No.
To use ColdFusion session variables without using cookies, each page must pass the CFID and CFToken values to any page that it calls as part of the request URL. If a page contains any HTML hrefa= links, cflocation tags, form tags, or cfform tags the tags must pass the CFID and CFToken values in the tag URL. To use J2EE session management, pass the jsessionid value in page requests. To use ColdFusion client variables and J2EE session variables, pass the CFID, CFToken, and jsessionid values in URLs.
Note: The behavior is as follows when CFID and CFTOKEN are provided in the URL: If session exists, the CFID and CFTOKEN from the URL are ignored. If the session does not exist, CFID and CFTOKEN from the URL are used to validate the session and the session is used if it is valid. If the session is not valid, a new session is created. CFID and CFTOKEN are regenerated.
ColdFusion provides the URLSessionFormat function, which does the following:
If the client does not accept cookies, automatically appends all required client identification information to a URL.
If the client accepts cookies, does not append the information.
The URLSessionFormat function automatically determines which identifiers are required, and sends only the required information. It also provides a more secure and robust method for supporting client identification than manually encoding the information in each URL, because it only sends the information that is required, when it is required, and it is easier to code.
To use the URLSessionFormat function, enclose the request URL in the function. For example, the following cfform tag posts a request to another page and sends the client identification, if necessary:
<cfform method="Post" action="#URLSessionFormat("MyActionPage.cfm")#>

If you use the same page URL in multiple URLSessionFormat functions, you can gain a small performance improvement and simplify your code if you assign the formatted page URL to a variable, for example:
<cfset myEncodedURL=URLSessionFormat(MyActionPage.cfm)>
<cfform method="Post" action="#myEncodedURL#">

Comment: I disagree with the first sentence of this answer.  While it's possible for people to disable cookies, I suspect that it happens less often than one would think.
Comment: @DanBracuk I agree with that.

How session works in coldfusion?


In Jade,is there a way to get a widget to float on the left without introducing a css style?

Question: I have a button written in Jade; the button is written into a span. I have a Java Script widget attached to the Jade button.   I am trying to get the widget written in Java Script to float on the left side of a button.  Is there a way to get the widget to float on the left without introducing a css style?
Answer: Jade is a template engine, it does not style elements, so your question is kind of off-topic.
If you want an element to float, you should use inline HTML elements, or as you suggested, CSS styling.
But it does not depend on the template engine, you would use the same solutions if you were using Handlebars, EJS, Mustache or whatever.


Ruby - MySQL server has gone away (Mysql2::Error)

Question: This is a duplicate question. The answers related with this question is not helping me anyway. Please help me out to get rid of this problem.
MySQL Query:
insert_query = %{INSERT INTO my_table (`my_column`) VALUES("#{my_value}");}.gsub(/\s+/, ' ')

client = Mysql2::Client.new(:host => 'localhost', :username => "#{ENV['MYSQLUSERNAME']}", :password => "#{ENV['MYSQLPASSWORD']}")
client.query("USE `my_database`;")
client.query(insert_query)

While inserting the value into my_column, i get an error "`query': MySQL server has gone away" (Mysql2::Error). my_column has MEDIUMTEXT data type and it will store encoded string value in it. If the encoded(using Base64.encode64 in Ruby) string character count is more(more than 1,00,000 or 1,00,00,000) then i am facing an error. But If the encoded string length is less, then it works well. I have tried setting up wait_timeout and max_allowed_packet. But not helping me in anyway!
Thanks in advance!
Answer: To solve that, you should increase the maximal packet size limit "max_allowed_packet" in /etc/my.cnf file (if file doesn't exist, you can create it).
you can set: max_allowed_packet = 128M
and then restart mysql
Comment: did you try to increase `connect_timeout` ?
Comment: Yes. But that too did not work. Do i need to set up those variables into /etc/my.cnf or /etc/mysql/my.cnf ?
Comment: Set: `max_allowed_packet = 128M` in **/etc/mysql/my.cnf** worked for me. Thanks!


Good books about elliptic integralsa, hypergeometric and special functions

Question: Can you please tell me some good books from where I can learn elliptic integrals and special functions like hypergeometric functions?
Answer: Whittaker and Watson, Modern Analysis, is the obvious first choice.
For just identities, there's the DLMF.
Comment: @LeGrandDODOM That's entirely standard in English (or at least Cambridge) books of that period. G.H. Hardy's *A Course in Pure Mathematics* does the same (see p. 28 of https://archive.org/details/coursepuremath00hardrich, for example), and it's all over the Tripos papers of that period, and reviews in the mathematical journals.
Comment: Is it the book where they say "shew" instead of "show" ?


If $g \vert f,$ where $g=(X-1)^2,\ f=aX^{n+2}+bX^n+2,\ a,b\in\mathbb{R}$, determine $q(1)$, where $q\in\mathbb{R}[X]$ is the quotient of $f:g$

Question:
If $g \vert f,$ where $g=(X-1)^2,\ f=aX^{n+2}+bX^n+2,\ a,b\in\mathbb{R}$, determine $q(1)$, where $q\in\mathbb{R}[X]$ is the quotient of $f:g$

This seems like an easy problem, but I'm not quite sure how to find $q(1)$ after determining $a$ and $b$. My logic was:
$$g\vert f \Rightarrow \begin{cases}f(1) = 0 \iff a+b+2 = 0 \\ f'(1) = 0 \iff (n+2)a+n\cdot b=0\end{cases} \Rightarrow a=n, b =-(n+2)$$
Here, however, is where I'm quite stuck. My attempt was to now calculate $$f''(1)=n(n+2)(n+1) -(n+2)n(n-1) = 2n^2+4n$$
which turns out to be very close to the real answer my workbook gives, which is $q(1)=n^2+2n$, but I was never taught if this is the correct approach. It feels more like it just so happened for my approach to be close to the answer, so I don't think I'm correct at all. Any hints towards the rigorous solution are much appreciated!
Answer: Your computations are correct - but if $f = (x-1)^2 q$, then $f' = 2(x-1)q + (x-1)^2 q'$ and $f'' = 2q+4(x-1)q'+(x-1)^2q''$, so $f''(1) = 2q(1)$.


Adicionar sufixo à primeira linha de arquivo de texto usando BAT

Question: Boas pessoal!
Estou editando uns mods do jogo F1C, que usa arquivos de texto para armazenar os dados de IA dos pilotos.
Na primeira linha de cada arquivo vêm o nome do piloto:
Michael Schumacher

... e eu gostaria de adicionar um sufixo no final do nome, mais ou menos isso:
Michael SchumacherRH

É possível fazer isso usando apenas o CMD/.bat (se possível usando um FOR pra fazer isso de uma vez pra todos os arquivos da pasta)?
PS.: Segundo o Notepad++ os arquivos estão sob a codificação UTF-8 (sem BOM)
Answer: Você pode começar fazendo o seguinte. O comando FOR do cmd pode ser usado para isso. Você pode usar a opção /F. Essa opção lê cada linha do arquivo. Envie a saída para outro arquivo com o sufixo já adicionado. Exemplo:
Conteúdo do arquivo Teste.txt:

NOME1
NOME2
NOME3
NOME4

Quero acrescentar a letra RH no final de cada linha. Para isso vou usar o seguinte:
FOR /F "eol=M" %i IN (test.txt) DO ECHO %iRH >> Teste-com-sufixo.txt

Agora o arquivo Teste-com-sufixo.txt ficará assim:

NOME1RH
NOME2RH
NOME3RH
NOME4RH

Isso já é um começo.


Dialogflow Slack Cards

Question: I have a bit of a silly question about the Slack integration of Dialogflow.
When I use a card to the response in Slack, the buttons work perfectly. But they don't type the title nor the postback of the button to the chat. The Botframework from Microsoft works like this and I think it's easier for the user to see what he answered if he scroll up the conversation history.
My question is, is this how it is, or can I change this behavior so that on clicking a card button the text of the button is typed in the chat?
For the moment, I'm only using code to execute functions when needed.
This is the "card" I'm talking about:
Answer: You can't directly change the behavior of the card as this is internal to Slack and/or Dialogflow. There is however a workaround: If you are using a Webhook for fulfillment you can send multiple responses messages back and thus simply include the button text before the actual card. The button text will then only show up after the request is fulfilled (not immediately after the user tapped it), but that seems about the best you can get.

Dialogflow Slack Cards


On the order of the operations of multiplication, division, addition, and subtraction

Question: I was asked if what is the basis of MDAS rule.
(multiplication, division, addition, subtraction).
Will these operations be followed at all times, or can it be changed in some cases?
Comment: Subtraction is just addition with negation on the second element and division is just multiplication with inverse on the second element. Then, multiplication follows addition from the distributive property of fields: $a(b+c)=ab+ac$. Real numbers with addition and multiplications form a field and one of the properties of fields is the distributive property. If you wanted to switch them around, you would have to change the operations fundamentally.
Answer: It equally can be DMAS, DMSA and MDAS. The point is multiplication and division always have higher precedence over addition and subtraction unless there are parantheses. Evaluating a subtraction before or after an addition doesn't change the value of the result. Same thing for multiplication and division.
Answer: If you are trying to compare MDAS against DMAS then they are both equivalent as long as you replace division with inverse of multiplication i.e. replace $x/y$ with $x \times\frac{1}{y}$
For instance: $4/2\times3$ using MDAS rule AND (not replacing $x/y$ with $x \times\frac{1}{y}$) , would be like
$$4/2\times3 = 4/6 = 2/3$$
which is not equal to the answer obtained by using DMAS rule $4/2\times3 = 2\times3 = 6$
But if you replace $x/y$ with $x \times\frac{1}{y}$ then solving $4/2\times3$ would be like
$$4/2\times3 = 4\times\frac{1}{2}\times3 = \frac{12}{2} = 6$$
which is the answer obtained by using DMAS rule i.e. $6$
same goes for Addition and Subtraction operations, that is considering Subtraction as inverse of Addition $a-b = a+({-x})$


Force AWS CloudFront to refresh resources from origin without user requests

Question: I'm deploying a CloudFront distribution for a widely distributed network. I'm using my own server as origin and I've configured the cache expiration to a custom value (say 24 hours). Everything works smooth for the edges used by the countries that generates high traffic and for the resources that are requested more often, but I think the same is not true for a (big) part of the requests which are originated by countries with low traffic.
Since the network have several tens of thousands of resources and, given the organic (long tail) nature of the traffic most of them are accessed just 3-4 times per day per edge. In that case, if my understanding is correct, the first request has bad performances (it is fetched from the origin) while the remaining 2-3 benefits from cloud front. In this scenario roughly 30% of the traffic is not using any CDN caching.
Is there a way to force the edges to autonomously refresh a set of objects regardless of the users requesting them in order to keep them "ready"? I know there'll be an impact on the monthly bill but for the moment I'm focusing on performances so let's assume costs are not important here.
Comment: "Bad performance" is probably something of an overstatement. For long-tail content no one's likely to notice...
Answer: If I read correctly, you want to pre-warm cache. There is no official way to pre-warm cache.
However, you can use list from http://blog.domenech.org/2013/10/amazon-web-services-cloudfront-edgelocation-codes.html to pre-warm.
For d709c28ax59vf.cloudfront.net, it will be:

d709c28ax59vf.ams1.cloudfront.net
d709c28ax59vf.ams50.cloudfront.net
...

You can write a script to pre-warm these domain with Host: d709c28ax59vf.cloudfront.net header.


"Convert" Rayleigh random variable into a Uniform random variable?

Question: I have a nested question of sorts. My first question, is that I am wondering if it is possible to 'convert' a Rayleigh random variable into a uniform random variable, and how one may do this.
Strongly related and dependent on this question though, is: if such a conversion was possible, would 'corrupt data', being defined here as outliers in the original Rayleigh PDF, also remain 'corrupt' outliers in the uniform distribution?
Comment: No, that is not a general principle: @user603 is just assuming the outliers are not "extreme." They might or might not be outliers after the transformation.  What can be said, though, is that if (say) $n$ values were drawn independently and randomly according to a $\chi^2$ distribution and an $n+1$st much larger value were thrown in, then--upon applying this probability transformation--as $n$ gets "large" it is highly likely (but not completely certain) that the $n+1$ resulting values would exhibit no apparent outliers.  ("Large" means bigger than $2$ or so in this case. :-)
Comment: With $N$ that large, for all practical purposes @user603 is absolutely right: you won't see any outliers among the transformed variables.  (The chance of that happening is somewhere around $10^{-200}$ or so, depending on what outlier-detection algorithm you use.)
Comment: a) yes, just use the [cdf](http://en.wikipedia.org/wiki/Cumulative_distribution_function) of the chi2 with 2 degrees of freedom. b) No. They will no longer be outliers.
Comment: @user603 Thank you. Is it a general principle, that outliers in one PDF, will never be outliers in the PDF to which they got converted to, or is this just something specific?
Comment: yes. An outlier has to be a able to drive an estimator to a specific (but arbitrary) value, regardless of the distribution of the majority of the data. A value drawn from a bounded distribution can't do that.
Comment: @whuber Yes - thats exactly my model - I have a $N$ chi-squared drawn variables, (lets say 1000 for argument's sake), and I purposely corrupt say, 5 of them. (Making them extreme outliers). Then, I am wondering how they might act during this transformation. :)
Comment: **Is** a chi-square (2 degrees of freedom) a **Rayleigh** random variable? I always thought it ($X_1^2+X_2^2$) is an **exponential** random variables, and that it is $\sqrt{X_1^2+X_2^2}$ that is a Rayleigh random variable.  Also, since the range of the transformed variable is $(0,1)$, it is kind of hard to get _outliers_ in the transformed data.
Comment: @DilipSarwate As far as I understand it, a Rayleigh RV is a Chi-Squared RV, with k=2 degrees of freedom. (Under relation to other distributions: https://en.wikipedia.org/wiki/Chi-squared_distribution). Chi-Squared with k = 2 is indeed made from $\sqrt{X_1^2 + X_2^2}$, which are gaussian RVs. (Central or Non-central).
Comment: @TheGrapeBeyond I think you are misreading the wikipedia page. It says "If $X \sim \chi^2 \left( 2 \right)$, then $X \sim \mathrm{Exp(1/2)}$ is an exponential distribution. (See Gamma distribution for more.)" and If $X \sim \mathrm{Rayleigh}(1)\,$ (Rayleigh distribution) then $X^2 \sim \chi^2(2)$" which coupled with the statement that $Q = \sum_i Z_i^2$ (where the $Z_i$ are iid $N(0,1)$ random variables matches what I said (viz. $\sqrt{Z_1^2+Z_2^2}$ is Rayleigh, $Z_1^1+Z_2^2$ is exponential) and not what you are claiming.
Comment: @DilipSarwate I see, yes, I mis-read the entries. Thanks for pointing that out. This changes my question a bit. I will edit.
Answer:
Your assertion that "a $\chi^{2}$ random variable (with 2 degrees of freedom; aka Rayleigh random variable)"
  is incorrect: a  $\chi^{2}$ random variable with two degrees of freedom is
  an exponential random variable with mean $2$, and not a Rayleigh random
  variable.

Following up user603's comments and my own comments about distributions,

If $X$ is a $\chi^2$ random variable with two degrees of freedom, then
its CDF is $F_X(x) = [1 - \exp(-x/2)]\mathbf 1_{x\in [0,\infty)}$ and so
if $x_1, x_2, \ldots, x_n$ are samples of $X$, then $y_1, y_2, \ldots, y_n$ are
samples of
a $U[0,1)$ random variable where $y_i = 1-e^{-x_i/2}$, $1 \leq i \leq n$.
If $Z$ is a Rayleigh random variable, its CDF is
$F_Z(z) = [1 - \exp(-z^2/2)]\mathbf 1_{z\in [0,\infty)}$
and so if $z_1, z_2, \ldots, z_n$ are samples of $Z$, then
$w_1, w_2, \ldots, w_n$ are
samples of
a $U[0,1)$ random variable where $w_i = 1-e^{-z_i^2/2}$, $1 \leq i \leq n$.
$\sqrt{X}$ is a Rayleigh random variable, and so if we have samples
$x_1, x_2, \ldots, x_n$  of $X$, then $\sqrt{x_1}, \sqrt{x_2}, \ldots, \sqrt{x_n}$
are samples of a Rayleigh random variable, and regardless of whether we choose to
map $x_i \mapsto 1-e^{-x_i/2}$
or to map $\sqrt{x_i} \mapsto 1-e^{-\left(\sqrt{x_i}\right)^2/2}$, we get the
same $y_1, y_2, \ldots, y_n$ as samples of a $U[0,1)$ random variable.

With regard to your question about outliers, note that the mean of $X$ is $2$
which maps to $1-e^{-1} \approx 0.632$ and so outliers, say any sample larger
than $10$, are mapped into a narrow range $[0.99326\ldots, 1)$. Remember that
sample values close to $0$ are not outliers, since the density of $X$  is
a monotone decreasing function on $\mathbb R^+$ and so values close to $0$
are highly likely and not rare at all.
Comment: Yes. For any continuous random variable $X$, $F(X)$ is uniformly distributed on the unit interval.
Comment: Thanks for your answer Dilip, it clears up a lot. This use of an rv's CDF to go to Uniform rv, is this a 'standard' method that can be applied to any PDF out there? Regarding the last part, yes, for me, the outliers (in the original Rayleigh PDF) are very large values relative to the rest.
Comment: PS I cannot upvote you because I dont have enough reputation apparently...


What is the probability that none of the people call the same office and the probability that all of them call the same office?

Question: Suppose there are $n (n \ge 2)$ offices in a city. Suppose that $k (2 \le k \le n)$ people each independently and randomly call one these $n$ offices for an appointment. What is the probability that (a) none of these $k$ people call the same office and (b) that all of these $k$ people call the same office?
My work:
(a) This is similar to saying $P($all calls are to unique locations$)=\frac{{n \choose k}k!}{{n +k - 1\choose k}}$. There are ${n \choose k}$ ways to pick which offices will receive calls. For each of these scenarios, there are $k!$ ways to determine which caller goes to which office.
(b)$P($all the same office$)=\frac{{n \choose 1}}{{n + k - 1 \choose k}},$ since all people call one office, there are ${n \choose 1}$ ways to choose that office, and ${n+k-1 \choose k}$ total ways for the people to schedule appointments. However, I feel like I am missing additional arguments in the numerator. This answer seems too easy.
Comment: Checking on your progress towards solving the rest. Added a line of R code.
Comment: Thank for checking on my progress. I left a comment with my answer for (b) given your great example. Is my answer for (a) correct, then? Thank you!
Answer: Thank you for showing your work so far. It seems you can use a bit of help.
Suppose there are $n=7$ offices and $k=5$ people.
For (b) we need to choose which office gets all the calls (7 ways)
and then every one of the 5 people needs to choose that office (each
with probability $1/7),$ so that the desired probability is
$7(1/7)^5 = (1/7)^4 = 0.000416.$ (a) I will leave a combinatorial
answer for this part to you.
A simple simulation in R for 10 million replications of this 5-call
experiment in R is shown below: The vector d has 10 million numbers,
each of them the number of distinctly different offices called at
random by 5 people. Each of the 10 million entries of the logical vector d==1 is TRUE if everyone
called the same office, otherwise FALSE; the mean of a logical vector is the
proportion of its TRUEs.
set.seed(903)
d = replicate(10^7, length(unique(sample(1:7, 5, rep=T))))
mean(d==1)
[1] 0.0004186        # aprx 0.00416
7*(1/7)^5
[1] 0.0004164931     # exact
2*sd(d==1)/sqrt(10^7)
[1] 1.293715e-05     # aprx 95% margin of sim err: 0.000013

mean(d==5)
[1] 0.1497841        # aprx probability: 5 distinct offices
prod(7:3)/7^5
[1] 0.1499375        # hmm?

table(d)/10^7
d
        1         2         3         4         5
0.0004186 0.0375117 0.3125584 0.4997272 0.1497841

Note: Steps within the replicate loop:
samp = sample(1:7, 5, rep=T);  samp   # sampling with replacement
[1] 3 3 6 1 4   # offices called by 5 people
unique(samp)
[1] 3 6 1 4     # uniquely different offices called
length(unique(samp))
[1] 4           # nr of different offices called

samp = sample(1:7, 5, rep=T);  samp
[1] 1 7 7 3 3
unique(samp)
[1] 1 7 3
length(unique(samp))
[1] 3

Comment: Were you planning on leaving some work for part (a)? I think you may have switched the labeling.
Comment: First argument of `sample` is population sampled from (list of 7 offices), second argument is number of items sampled (five people calling), third argument changes from default 'without-replacement mode' to 'with-replacement' mode (same office can be called more than once).
Comment: I'm saying that for $n = 7$ offices and $k = 5$ people, $P(\text{5 distinct offices})$ $= (6/7)(5/7)(4/7)(3/7) =  0.1499375$ and that this method generalizes.
Comment: Combinatorial problems are always a challenge for beginners. Then you accumulate a battery of methods of approach. But even experts should probably be banned from writing answers on Monday before coffee.
Comment: Thank you for your work. Unfortunately, I am not too well-versed in R, but I think I understand the point that you're trying to make. I appreciate the effort, as well! I see my error in part (a).
Comment: Thank you. So is (b) $n \cdot (1/n)^k=P(a)$?
Comment: Wow, that solution is much simpler than I anticipated. I appreciate your help. I think that I was over complicating this entire problem!


Problema de Acentuação ao consumir WebService no Windows Server

Question:
Correção

Estou com um problema de acentuação ao consumir WebService no Windows Server.
Tenho apache-tomcat-7.0.63 instalado no windows server 2008, e como SGB, o PostGres 9.4 e com o Java 8.
O erro acontece quando executo fora do NetBeans. Ou seja, se executo fora em qualquer ambiente ele grava os caracteres errados, mas se executo dentro do NetBeans(Depurando ou apenas Executando) ele grava os caracteres normais.

código do web service
<code>@POST
@Path("cliente/sincronizar")
@Consumes("application/json;charset=utf-8")
public Response createClienteInJSON(String param) {
    Gson gson = new Gson();
    ContaCTR contaCTR = new ContaCTR();

    ParamCliente paramCliente = gson.fromJson(param, ParamCliente.class);

    Conta conta = contaCTR.carregar(paramCliente.getToken());

    if (!paramCliente.getClientes().isEmpty() && conta != null) {
        try {
            WsAuxiliar.sincronizarCliente(paramCliente.getClientes(), conta);

            ClienteCTR clienteCTR = new ClienteCTR();
            List<Cliente> clientes = clienteCTR.listar(conta.getContaid(), "codigointerno");
            WsAuxiliar.sincronizarEmail(paramCliente.getEmails(), conta, clientes);
            WsAuxiliar.sincronizarEndereco(paramCliente.getEnderecos(), conta, clientes);
            WsAuxiliar.sincronizarTelefone(paramCliente.getTelefones(), conta, clientes);
        } catch (Exception e) {
            throw new RuntimeException("Falha ao sincronizar Cliente. Erro: " + e.getMessage());
        }
    }
    return Response.status(201).build();
}
</code>
código cliente consumindo web service
<code>    public Retorno sendPostClientes(String token) throws Exception {
    try {
        ParamCliente paramCliente = new ParamCliente();
        paramCliente.carregar();
        paramCliente.setToken(token );

        Gson gson = new Gson();

        String input = gson.toJson(paramCliente);

        URL url = new URL(Configuracao.carregar().getWebserv() + "cliente/sincronizar");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");

        OutputStream os = conn.getOutputStream();
        os.write(input.getBytes());
        os.flush();

        if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
            throw new RuntimeException("Failed : HTTP error code : "
                    + conn.getResponseCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader(
                (conn.getInputStream())));

        String output;
        System.out.println("Output from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
        }

        conn.disconnect();
    } catch (Exception e) {
        return Retorno.criarRetorno(Boolean.TRUE, "Erro ao sincronizar clientes!\n" + e.getMessage());
    }
    return Retorno.criarRetorno(Boolean.FALSE, "Clientes Sincronizado com sucesso!");
}
</code>
Configuração da base de dados Postgres

Desde já um muito obrigado pela ajuda.
Comment: Sim, mas a sua tabela no postgree está UTF-8 ?
Comment: Estou pensando no que possa ser.
Comment: Tenta usar `ISO-8859-1` e ve o que da
Comment: Com o ISO-8859-1 funcionou perfeitamente executando fora do NetBeans mas dentro (Depurando ou simplesmente Executando) parou de funcionar.
Coisa de louco...Coisa de Programador...kkkk
Comment: Vou deixa ISO-8859-1 pois é mais importante funcionar no executável separado de que no NetBeans. Então posso dizer que resolvi parcialmente. Muito Obrigado  Techies. Que Deus lhe recompense.
Comment: Alguém teria uma dica?
Comment: Já olhou as configurações do postgree?
Comment: Peço até desculpa, pois o erro acontece quando executo fora do NetBeans. Ou seja, se executo fora em qualquer ambiente ele vai com os caracteres errados, mas se executo dentro do NetBeans(Depurando ou apenas Executando) ele manda os caracteres normais.
E eu ainda não tenho solução para este erro...
Comment: Sim ele esta UTF-8, coloquei acima, uma imagem com as configurações do banco.
Comment: Estranho... Alguma coisa está passando despercebida, rs
Comment: Talvez o NetBeans esteja configurado como UTF-8
Comment: Por nada, Já que resolveu parcialmente espere um pouco e veja se outra pessoa responda com uma solução melhor, caso ano aconteça não se esqueça de colocar como resolveu seu problema, dessa forma poderá ajudar outras pessoas.
Comment: @JoãoPaulo você pode postar sua solução do problema como resposta abaixo e marcar como aceita. O site funciona diferente de foruns.
Answer: Tenta o seguinte:
<code>@Produces("application/json; charset=UTF-8")
public Response createClienteInJSON(String param) {
...
}
</code>
Espero que funcione
Comment: Mas ele já não está fazendo isso?
Comment: Peço até desculpa, pois o erro acontece quando executo fora do NetBeans. Ou seja, se executo fora em qualquer ambiente ele vai com os caracteres errados, mas se executo dentro do NetBeans(Depurando ou apenas Executando) ele manda os caracteres normais.
E eu ainda não tenho solução para este erro...
Comment: @Techies pelo código postado não, o que tem o *charset* lá é o `@Consumes`. Provavelmente o erro é ao produzir a resposta mesmo. @JoãoPaulo conseguiu resolver só configurando o `@Produces`?
Comment: Na verdade testei da forma que me passou também mas deu o mesmo erro. Mudando o charset inverti o local do erro rsrs... antes funcionava dentro do netbeans e externo não, agora funciona externo mas dentro do NB parou de funcionar... Mas como o executável externo é mais importante, afirmo que consegui contornar o erro. Muito obrigado @BrunoCésar e desculpe a demora no retorno, mas o feriado foi longe da civilização..


Matrix Transpose Well-defined

Question: Let $A$ be a matrix,then both $X=AA^T$ and $Y=A^T A$ are well-defined and symmetrical matrices.
How do I prove this?
Answer: You have a theorem in your book that says $(AB)^T = B^TA^T$, right? If you do, you can say this:
$$
X^T = (AA^T)^T = (A^T)^TA^T = AA^T = X
$$
and likewise for $Y$.
As for well-defined... My best guess would be that transposes are well-defined and products are well-defined, so doing both of them one after another would produce something well-defined.
Comment: The phrase "well defined" here refers to the fact that $A$ and $A^T$ have conforming dimensions so that they can be multiplied together. In general, given an $m\times n$ matrix $A$ and a $p\times q$ matrix $B$, they cannot form a matrix product $AB$ unless $n=p$.

Matrix Transpose Well-defined