"Could not find schema information for the element" - but my schema file does contain information for the element

Question: I'm trying to work with an application that i don't have the source code for.  I'm trying to interface in some data in an XML file.  i believe my file matches the applications required schema correctly, but i get the message "Could not find schema information for the element" for every element in my file.  I've decomplied the applications code and rebuilt it in visual studio, and i get the error myself.
I'm going to go ahead and just dump the code... Its pretty long, but i'm starting to think its a pretty bone head mistake on my part.
The XML to be imported:
<WorkOrders>
    <WorkOrder>
        <Action>SAVE</Action>
        <UserDef1>NotRequired1</UserDef1>
        <UserDef2>NotRequired2</UserDef2>
        <UserDef3>NotRequired3</UserDef3>
        <UserDef4>NotRequired4</UserDef4>
        <UserDef5>NotRequired5</UserDef5>
        <UserDef6>NotRequired6</UserDef6>
        <UserDef7>-1</UserDef7>
        <UserDef8>-2</UserDef8>
        <AutoRelease>N</AutoRelease>
        <BuildInstructions>Not Required BuildInstructions</BuildInstructions>

        <Company></Company>

        <DueDate>12-31-2011</DueDate>

        <FinishedItem>SERIAL_TEST</FinishedItem>
        <QtyToBeBuilt>12345</QtyToBeBuilt>

        <Warehouse>PPLant</Warehouse>
        <WeightUm></WeightUm>
        <WOAllocMethod></WOAllocMethod>
        <WorkOrderDetails>
            <Action>SAVE</Action>
            <UserDef1>NotRequired1</UserDef1>
            <UserDef2>NotRequired2</UserDef2>
            <UserDef3>NotRequired3</UserDef3>
            <UserDef4>NotRequired4</UserDef4>
            <UserDef5>NotRequired5</UserDef5>
            <UserDef6>NotRequired6</UserDef6>
            <UserDef7>-1</UserDef7>
            <UserDef8>-2</UserDef8>
            <AllocationRule>WorkOrderAllocation</AllocationRule>
            <BuildLevel>1</BuildLevel>

            <Company></Company>
            <ComponentItem>SERIAL_TEST</ComponentItem>
            <FromLocation></FromLocation>-->

            <QtyNeededPerItem>10</QtyNeededPerItem>

            <Warehouse>PPLant</Warehouse>
        </WorkOrderDetails>
        <WorkOrderId>ExampleWorkOrderID001</WorkOrderId>
        <AllocationRule>WorkOrderAllocation</AllocationRule>

    </WorkOrder>
</WorkOrders>

The schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="WorkOrderDownload" targetNamespace="http://www.asdf.com/asdfNET/Interface" elementFormDefault="qualified" xmlns="http://www.asdf.com/asdfNET/Interface" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2008">
    <xs:include schemaLocation="InterfaceEntity.xsd" />
    <xs:element name="WorkOrders" nillable="false" type="WorkOrderList" />
    <xs:complexType name="WorkOrderList">
        <xs:sequence>
            <xs:element minOccurs="1" maxOccurs="unbounded" name="WorkOrder" nillable="true" type="WorkOrder" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="WorkOrder">
        <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="1" name="AutoRelease" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="BuildInstructions" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="BuildLocation" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="Company" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="DimensionUm" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="DueDate" type="xs:dateTime" />
            <xs:element minOccurs="0" maxOccurs="1" name="Error" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="FinishedItem" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="InterfaceEntity" type="InterfaceEntity" />
            <xs:element minOccurs="0" maxOccurs="1" name="InternalWorkOrderNum" type="xs:int" />
            <xs:element minOccurs="0" maxOccurs="1" name="ItemClass" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ItemColor" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ItemCost">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="ItemDescription" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ItemHeight">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="ItemLength">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="ItemSize" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ItemStyle" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ItemValue">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="ItemWeight">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="ItemWidth">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="PlannedUnitBuildTime">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="QtyToBeBuilt">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="1" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="QtyUm" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="RevisionNum">
                <xs:simpleType>
                    <xs:restriction base="xs:int">
                        <xs:minInclusive value="1" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="VolumeUm" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="Warehouse" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="WeightUm" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="WOAllocMethod" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="WorkOrderDetails" type="WorkOrderDetailList" />
            <xs:element minOccurs="0" maxOccurs="1" name="WorkOrderId" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="WorkOrderDetailList">
        <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="unbounded" name="WorkOrderDetail" nillable="true" type="WorkOrderDetail" />
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="WorkOrderDetail">
        <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="1" name="AllocationRule" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="BuildLevel">
                <xs:simpleType>
                    <xs:restriction base="xs:int">
                        <xs:minInclusive value="1" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="BuildSequence">
                <xs:simpleType>
                    <xs:restriction base="xs:int">
                        <xs:minInclusive value="1" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="Company" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ComponentItem" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="FromLocation" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="IncQtyAmount" type="xs:double" />
            <xs:element minOccurs="0" maxOccurs="1" name="IncQtyEligible" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="IncQtyMinAmount">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="IncQtyType" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="InterfaceEntity" type="InterfaceEntity" />
            <xs:element minOccurs="0" maxOccurs="1" name="InternalWorkOrderNum">
                <xs:simpleType>
                    <xs:restriction base="xs:int">
                        <xs:minInclusive value="0" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="LogisticsUnit" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="Lot" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="ParentLogisticsUnit" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="QtyNeededPerItem">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:minInclusive value="1" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element minOccurs="0" maxOccurs="1" name="QuantityUm" type="xs:string" />
            <xs:element minOccurs="0" maxOccurs="1" name="Warehouse" type="xs:string" />
        </xs:sequence>
    </xs:complexType>
</xs:schema>

the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;

namespace WorkOrderInterfaceValidation
{
    class Program
    {
        static void Main(string[] args)
        {
            helper h = new helper();
            h.main();
        }
    }

    class helper
    {
        StringBuilder _valErrorMsgs;

        public helper()
        {
            _valErrorMsgs = new StringBuilder();
        }

        public void main()
        {
            try
            {
                string error = "No error";
                Console.WriteLine("hello world");

                ValidateSchemaWithURI("C:\\Program Files\\software\\asdf\\2010\\Interface\\Input\\ExampleWorkOrder001.xml",
                    "http://www.asdf.com/asdfNET/Interface",
                    "\\\\localhost\\asdf\\Schemas\\Interface\\WorkOrderDownload.xsd",
                    out error
                    );

                error += " err";
                Console.WriteLine(error);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadKey();
        }

        public XmlReader ValidateSchemaWithURI(string inputUri, string targetNamespace, string schemaPath, out string error)
        {
            //StringBuilder _valErrorMsgs = new StringBuilder();
            XmlReader reader = null;
            XmlReader reader2;
            try
            {
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.Schemas.Add(targetNamespace, schemaPath);
                settings.IgnoreWhitespace = true;
                settings.ValidationType = ValidationType.Schema;
                settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
                settings.ValidationEventHandler += new ValidationEventHandler(this.SchemaValidationEventHandler);
                reader = XmlReader.Create(inputUri, settings);

                foreach (var v in settings.Schemas.Schemas())
                {
                    foreach (var e in ((XmlSchema)v).Attributes)
                    {
                        e.ToString();
                    }
                }

                while (reader.Read())
                {

                }
                reader2 = reader;
            }
            catch (XmlException exception)
            {
                _valErrorMsgs.Append(exception.Message).Append(";");
                Console.WriteLine(exception.Message);
                reader2 = null;
            }
            finally
            {
                error = _valErrorMsgs.ToString();
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return reader2;
        }

        private void SchemaValidationEventHandler(object sender, ValidationEventArgs args)
        {
            this._valErrorMsgs.Append(args.Exception.Message).Append(";");
        }
    }
}

The error message:

XmlException: Could not find schema information for the element 'WorkOrders'.;Could not find schema information for the element 'WorkOrder'.;Could not find schema information for the element 'Action'.;Could not find schema information for the element 'UserDef1'.;Could not find schema information for the element 'UserDef2'.;Could not find schema information for the element 'UserDef3'.;Could not find schema information for the element 'UserDef4'.;Could not find schema information for the ....
Answer: I think you're missing the namespace. Try:
<WorkOrders xmlns="http://www.manh.com/ILSNET/Interface">

Comment: I'm having the same issue though my xml and xsd both contain the same target namespace as you defined. any ideas?


Inner join and average in SQL

Question: I'm new to SQL thus the question. I'm trying to query the following. Given the CITY and COUNTRY tables, query the names of all the continents (COUNTRY.Continent) and their respective average city populations (CITY.Population) rounded down to the nearest integer.
The table schemas are City: id, name, countryside, population
Country: code, name,continent, population

I've written the inner join, but can't seem to figure out the way to get the avg city population. This is my code.
SELECT COUNTRY.CONTINENT
FROM COUNTRY
INNER JOIN ON
COUNTRY.CODE = CITY.COUNTRYCODE;

Any help appreciated.
Answer: Ok. Here is the solution.
Select Country.Continent, floor(Avg(city.population))
  From Country
     Inner Join City
        On Country.Code = City.CountryCode
  Group By Country.Continent;

Here, We have to group by Continent so as to have a result set for continent being the key identifier and then applying AVG function to the population for the cities belonging to this continent.
Comment: Not passing the test case, but no error logs. If you have the time you can look this link up. https://www.hackerrank.com/challenges/average-population-of-each-continent
Comment: fixed it for you. Enjoy and submit it.
Comment: Then accept it as answer. An upvote will not do any harm either.
Answer: SELECT
    COUNT(*) over (partition by c.Code)
    ,SUM(ci.Population)/COUNT(*) over (partition by c.Code)
FROM Country c
INNER JOIN City ci on ci.CountryCode = c.CountryCode
GROUP by c.CODE

I have not tested this so I apologize if it needs a little tweaking.   The concept here is to group by country code since you are looking for an average of population within specific or individual country codes.
Answer: select COUNTRY.CONTINENT,floor(avg(CITY.POPULATION))
from CITY,COUNTRY
where CITY.CountryCode=COUNTRY.Code
group by COUNTRY.CONTINENT;

This is the most basic sql query.
Idea: A continent has several cities and we have to find the average population of cities. We have to make group of continents and find their average cities population.
NOTE: For this question (HACKERRANK PROBLEM), ROUND() function will give out wrong answer.
Answer: select CONTINENT ,floor(AVG(CITY.POPULATION))
from CITY,COUNTRY
where COUNTRYCODE IN (Select CODE ,from COUNTRY and GROUP BY COUNTRY.CONTINENT);

what is wrong in my code
Comment: As it's currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).
Comment: If you have a new question, please ask it by clicking the [Ask Question](https://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. - [From Review](/review/late-answers/30829408)

Inner join and average in SQL


Passed array as parameter and don't work

Question: I have a JavaScript function with calls a picture gallery. I get the img's name in my DB with php, and trying to pass the results as a parameter to the js function, so it will load the imgs on my page. It should load 4 images, but he's assuming the values , when it should be , , and etc... How could i do it ? Here's my JS function:
function galerias(query){

        var imgs = document.querySelector("#gallery");
        var x = 1;

            imgs.innerHTML += "
";
            imgs.innerHTML += "
";
            imgs.innerHTML += "
Galeria "+x+"
"

        for(var i = 0; i < query.length; i++){
            imgs.innerHTML += "";

             x++;
        }

        imgs.innerHTML += "
";
        imgs.innerHTML += "
";
        imgs.innerHTML += "

Veja mais

";

}

PHP DB query:
function consultarDados($query){
    $dbResult = array();
    $conexao = mysql_connect($this->host, $this->usuario, $this->senha);
    mysql_select_db($this->banco, $conexao);
    $rs = mysql_query($query, $conexao);
        while($rows = mysql_fetch_assoc($rs)){
            //array push insere valores do $rows ao final do array $dbResult
            array_push($dbResult, $rows);
        }
    return $dbResult;
    mysql_close($conexao);
}

This is how i made the query in the pictures page:
include 'connectDB.php';
$conexao = new connectDb();
$galeria_1= $conexao->consultarDados('select * from portfolio where gal= 1 and theme= 1');

$parametroGal = array();
foreach($galeria_1 as $result){

        array_push($parametroGal, $result['nome']);
    }

And how i pass the value as parameter to the JS function, on my window.onload:
<?php
        echo'galerias("'.$parametroGal.'");';
?>

This results:

    //that way it just give me as result the word array, since $parametroGal is an array

//i need to get the value of that array, like this:

    //the result of the array, the results of the query in the DB

Comment: It might actually work if you had some
Comment: In your javascript code, it doesn't look like you're using your 'query' parameter as a list.
Answer: Have you tried something like this:
<?php
        echo'';
?>

Edited
Comment: `, ` he stated in first  some lines
Comment: They might have already echoed out a script tag before that part of the php code
Comment: don't you thing explode is needed and loop is required. implode convert it in a string by combining all values and that is his problem.
Comment: @trixtur It's just the same, the function is working and the query is also working, but not properly. It's not bringing the pictures as it should. It is passing all array results as img src, and it should bring 4 img's tag with one array result in each.
Comment: yep I overlooked that.
Comment: @anuseranother I changed my code a little. If you use some "glue" you can split up your parameters.
Comment: Yup i come to know why you said that. i added an answer. Please try
Comment: @trixtur it just giver the result ''


combine specificity and

Question: I am performing classification on an imbalanced dataset (70% negatives).
If a prediction is negative I take a specific action otherwise an opposite one. As in both cases some costs are implied, I want to assess how good the model is at detecting each class.
To do so, I am calculating TP/(TP+FP) and TN/(TN+FN), along the logloss.
Questions:
1- Is my intuition correct in judging these two metrics the most relevant for judging how reliable the model's predictions are?
2- The costs behind each decision are not constant, but they roughly follow different distributions, one for positives and one for negatives. Let's say two gaussians N(1,2) and N(1.5,3). How can I account for this?
Comment: What do you mean about the costs not being constant? Do you mean that FP incurs a cost of $2$ whole FN incurs a cost of $20$ (to make up some numbers)?
Comment: They depend on a variety of factors, therefore they are not constant. For sake of argument let's say that the cost for FP is a draw from a certain distributions and FN's from another one. I edited the question
Answer: It seems like you have a probability $p_1$ of making one kind of mistake, which incurs a cost that is distributed according to $X_1\sim N(1,2)$, and you have another probability $p_2$ of making a mistake that incurs a cost that is distributed according to $X_2\sim N(1.5,3)$. (How you incur negative cost upon making a mistake is a mystery to me, but I can roll with it.
Then your distribution of costs incurred would be $p_1X_1+p_2X_2$.
However, I do not think your probabilities are sensitivity and specificity, which condition on the outcome that you do not know. (If you knew it, you would not be making mistakes in predicting it.) You might find yourself interested in the probabilities of misclassification given each type of classification (related to PPV and NPV). Better still might be to use the predicted probabilities, particularly if those predictions are calibrated (they might not be) and reflect the true probability of event occurrence.
Comment: side note: the problem has to do with placing orders to a national dispatcher of a certain utility. in broad strokes, sometimes even if you get the position wrong turns out you are making their life easier, so you get rewarded
Comment: My initial idea was actually to draw costs for each output probability and bootstrap estimate the total cost. I think this would give an idea of how robust the model is wrt to the (not well calibrated) probabilities
Comment: how do you define PPC and NPV? aren't they the ones I mention? (I am not good with metric names)
Comment: Perhaps consider posting a new question about the problem you want to solve. Right now, it sounds like you have issues to resolve and have ideas to solve them, so you are asking about those possible solutions instead of asking about the root problem. @shamalaia

combine specificity and


Alphabet Regex Pattern?

Question: If I have a letter say "w" and I want to it to match only against a few characters in the alphabet for example " the letter a, d and then h to q and w only. How can I achieve this?
All I have so far is : ^[h-qH-Q]+$
I assume its pretty easy but i'm not really a regex expert...
Comment: regex is probably overkill/the wrong tool for this
Comment: Does that letter, say "w", have to be alone in the line?
Comment: the letter that will be passed into the regex could be any letter it just needs to match a, d then between h or q or w. If c was to be passed in then it wouldn't match. That's kind of what I meant.
Comment: regex101.com that is a good site to just play around with regexes, it tells you what they are doing too :)
Answer: Try this regex:
<code>^[aAdDh-qH-QwW]$
</code>
It will only match single letters on the input line.
Hoping this is what you mean.

Alphabet Regex Pattern?


Value e ID no DropDown Cascata

Question: Referência que pode ajudar a entender o código.
DropDown Cascata
Essa parte aqui eu passo os valores que vai ser adicionado no segundo DropDown
var classesList = this.GetClasses(Convert.ToInt32(CanalMassivo));
    var classesData = classesList.Select(m => new SelectListItem()
    {
        Value = m.idSegmento.ToString(),
    });

    var states = classesData.Select(m => m.Value).ToList();
    return Json(states, JsonRequestBehavior.AllowGet);

Na parte Value = m.idSegmento.ToString() e o valor que aparece no DropDown quanto o valor que o controller recebe.
Como poderia fazer para passar a descrição no DropDown e o controller receber o valor do id ?
Tentei assim
        Text = m.descricao.ToString(),
        Value = m.idSegmento.ToString(),
    });

    var states = classesData.Select(m => m.Text).ToList();

Mas gera esse erro
There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'idCanalIndicadoresMassivo'.

Comment: Poste como está sua `view` com o `DropDown`. Provavelmente você está utilizando `idCanalIndicadoresMassivo` quando deveria ser apenas `Value`.
Comment: Randrade, Obrigado. Poderia acessar aqui ? http://pt.stackoverflow.com/questions/100716/dropdown-cascata que tem todo o inicio do meu codigo, View, Controlle, Model, JavaScript
Answer: Se você quer utilizar o SelectListItem() altere sua action para isso:
var classesList = this.GetClasses(Convert.ToInt32(CanalMassivo));
    var classesData = classesList.Select(m => new SelectListItem()
    {
        Value = m.idSegmento.ToString(),
        Text = m.descricao
    });
    //Não selecione somente o texto, você precisará dos dois.
    return Json(states, JsonRequestBehavior.AllowGet);

E em sua chamada ajax, onde povoa o DropDown, você altera para passar o idSegmento no value e a descricao no option, desta forma:
   $.each(data, function (i, state) {
         //Create new option
         var option = $('<option value="'+state.Value+'">' +state.Text+ '</option>');
         //append state states drop down
         stateDropdown.append(option);
   });

Desta forma você irá visualizar a descrição, e o DropDown terá o value de idSegmento.
Comment: Randrade.! Perfeito.!! Muito Obrigado pela ajuda.!!

Value e ID no DropDown Cascata


Show that the set of some rotations $S_v$ is a coset of $H_v=\{T\in G:Tv=v\}$

Question: I am stuck while solving the following problem:

Problem (Source: University of California, Berkeley - Prelim exams)
Let $G$ be the group of orthogonal transformations of $\mathbb{R}^3$ to $\mathbb{R}^3$ with determinant $1$. Let $v\in\mathbb{R}^3$, $|v|=1$, and let $H_v=\{T\in G\mid Tv=v\}$.
(a) Show that $H_v$ is a subgroup of $G$.
(b) Let $S_v=\{T\in G\mid T\text{ is a rotation through $180^\circ$ about a line orthogonal to $v$}\}$. Show that $S_v$ is a coset of $H_v$ in $G$.

I easily solved step (a), so I know that $H_v$ is a subgroup of $G$. If I find a matrix $A\in G$ such that $S_v=AH_v$, then I succeed to show that $S_v$ is a coset of $H_v$ in $G$. However, I don't know how to find $A$.
My notes:

Take $T\in S_v$, then $T^2$ is a rotation through $360^\circ$ about a line, so $T^2$ is the identity. Especially, $Tv=-v$. Thus $T$ have an eigenvalue $-1$ associated with $v$, while elements in $H_v$ have an eigenvalue $1$ associated with $v$.
In the post Prove that the set $\{f\in \mathfrak G|f(p)=w\}$(where $w$ is a $r$th root of unity) is a coset of the subgroup $\{f\in \mathfrak G|f(p)=1\}$., I got the statement that if $f$ is a group homomorphism and $b\in \operatorname{Im}f$, then $f^{-1}(b)$ is a coset of $\ker f$.
Answer: Hint, since you say you don't know how to find $A$: $H_v$ is a subgroup, so $I \in H_v$ (where $I$ is the identity matrix). You're trying to find $A$ such that $S_v = AH_v$; since $I \in H_v$, this implies $A \in S_v$. (And in fact, you can take any such $A$). Therefore, what you want to show is that given any $A \in S_v$, $B \in H_v$, then $AB \in S_v$.


Elastic Beanstalk: Deploy Django for mac, CANNOT install EB

Question: I'm trying to set up Elastic Beanstalk for Django in Mac according to Amazon's tutorial:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html
it's fine until Step 3: Configure AWS Elastic Beanstalk:
when i go to the 3rd substep "From your directory where you created your local repository, type the following command."
<code>eb init
</code>
The error is
<code>(djangodev)Lee-Jamess-MacBook-Pro:~ h0925473$ git init
Reinitialized existing Git repository in /Users/h0925473/.git/
(djangodev)Lee-Jamess-MacBook-Pro:~ h0925473$ alias eb="python2.7/Users/h0925473/AWS_EB/eb/macosx/python2.7/eb"
(djangodev)Lee-Jamess-MacBook-Pro:~ h0925473$ eb init
Traceback (most recent call last):
  File "/Users/h0925473/AWS_EB/eb/macosx/python2.7/eb", line 17, in <module>
    from scli import core
  File "/Users/h0925473/AWS_EB/eb/macosx/python2.7/scli/core.py", line 24, in <module>
    from scli import command, cli_parse, config_file, prompt
  File "/Users/h0925473/AWS_EB/eb/macosx/python2.7/scli/command.py", line 16, in <module>
    from lib.utility import misc
  File "/Users/h0925473/AWS_EB/eb/macosx/python2.7/lib/utility/misc.py", line 22, in <module>
from scli.constants import OSSpecific, ServiceDefault, TerminalConstant
  File "/Users/h0925473/AWS_EB/eb/macosx/python2.7/scli/constants.py", line 374
    ParameterName.RdsEngine,
                       ^
SyntaxError: invalid syntax
</code>
Can anyone tell me what i did wrong? Why SyntaxError?
Answer: The reason seems I didn't set the mysql correctly.
please reference to another question


VBA in query error evaluating false part of IIF

Question: I have the following column in a query.
iif(Len([Field1])=0,0,Asc(Mid([Field1] & "",Len([Field1]))))

The idea is that it should return the ASCII value of the last character in a string field.
The problem is that if Field1 is blank the statement errors with the following message: "Invalid procedure call or argument (Error 5)". If the field is blank it should return 0.
Comment: Well don't forget that at times complier [doesn't short circuit within IIF() statement](http://stackoverflow.com/questions/13357344/vb6-iif-isnullrs-true-replace/13357439#13357439). So in your case evaluate `field1` to be not null...
Comment: @bonCodigo You're correct for `IIf()` in VBA code.  However `IIf()` *does* short-circuit when used in a query.
Comment: @HansUp agreed with you. Rick if your `IIF()` gonna get overly long, then you may want to consider a `UDF` with `case`...relatively fast and keep clarity of your query.
Answer: Assuming blank means either Null or an empty string, you can concatenate an empty string to [Field1], and if the combined length is 0, return 0.
The Right() function is more direct than Mid() to get the last character.
SELECT IIf(Len([Field1] & "")=0,0,Asc(Right([Field1],1)))
FROM YourTable;

Answer: By all means you have HansUp's answer to go ahead. :)
..At any point of this querying voyage, your query with IIF gets very very long... ;) here a head start with a UDfunction that uses REGEX. In your case the most important aspect is to validate the input - not much of getting the ASCII value. Since your concern mainly on last character, what if your Field1 contains alphanumeric value and if your last character happens to be digit, special character instead of String. Well, just to be safe, we could validate that in the following funciton which will respond only to Strings. Another advantage is that you can re-use this function within your db.
Perhaps this really is complicating your process :D
Option Compare Database
Option Explicit

 Public Function GetASCII(strField1 As String) As Integer
    Dim regex As Object
    Dim strTemp As String

    Set regex = CreateObject("vbscript.regexp")

    '--assume strField1 = "hola", you may enter different types
    '-- of values to test e.g. "hola1, hola$ , hola;

    With regex
        .IgnoreCase = True
        .Global = True
        .Pattern = "[a-zA-Z]+"

        '--check for null
        Select Case IsNull(strField1) '-- validates any other datatype than String
            Case True
                GetASCII = 0
            Case Else
                Select Case IsError(strField1)
                   Case True
                      GetASCII = 0
                   Case Else
                      Select Case IsEmpty(strField1)
                          Case True
                             GetASCII = 0
                             '--check if entire string is String
                             '--only (no special characters, digits)
                             '--you may change this to only check the
                             '----last character if your Field1 is alphanumeric
                          Case Else
                             Select Case .Test(strField1)
                                 Case True
                                    strTemp = Mid(strField1, Len(strField1), 1)
                                    GetASCII = Asc(strTemp)
                                 Case Else
                                    GetASCII = 0
                             End Select
                      End Select
                End Select
        End Select
    End With
    Set regex = Nothing
 End Function

Note: Thought this would be helpful in the long run :) An Access Query Primer Article.
Comment: @HansUp you may add `Dim strNull as String` , don't assign a value; and use that String variable within the `Select case IsNull(strNull)`. It returns true for null. So in VBA Excel, Access you can have null for Strings it seems.... I have also mentioned that in anycase if the `Field1` happens to be contain a `alphanumeric` or perhaps a `numeric`.
Comment: Rick said he wants "*the ASCII value of the last character in a string field*" ... a **string** field.  Don't re-define his question just to make your answer fit.  ;-)
Comment: No, strNull can not contain Null when declared as string. If you try this assignment, you will trigger error #94, '*Invalid use of Null*'
: strNull = Null
Comment: I tried to help you see a VBA string variable can never contain Null.  If you declare `strNull` as string, it will be initialized as an empty string ("") not a Null.  If you don't assign anything, `strNull` will remain "".  So `IsNull(strNull)` will be equivalent to `IsNull("")` ... and will return False.  A VBA string variable can never contain Null under any circumstances.
Comment: @Rick one of these days if you need to use a funciton, you may check this answer out ;) and even get it customized or improved accordingly.
Comment: You declared strField1 As String. A string can never be Null, so this part of the function is not useful: '--check for null Select Case IsNull(strField1)
Comment: @HansUp my comment says **, don't assign a value**. So why do you assign null? just show an error? ;) Coz I wouldn't know why one would want to assign NULL in the first place...
Comment: @HansUp I thank you for explaining things here :) And I had no time to get back earlier. The puzzle I had, because there was no `deliberate null` assinging in the code. I ran the code by pointing to a random cell with no values(literally empty), and for `IsNull()` it reutnrs `false`... for `IsEmpty()` it reuturns `false`. So I agree with you. But I would still want to keep `IsNull` for other data types, in anycase the user happens to enter one other than a `String`. You see my answer is not posted to compete with yours. It was an alternative, in the event `IIF` are train like long :)


Cannot get tag's text even if setting a NamespaceContext

Question: I am new to xpath , and I have never dealt with xml on java. I want to get values from a xml. The tags may be preceded by mgns1: or not. So I wrote this code :
private List<String> parse(Node node, String file) throws XPathExpressionException {

    XPath xpath = XPathFactory.newInstance().newXPath();

    xpath.setNamespaceContext(new NamespaceContext() {

        public String getNamespaceURI(String prefix) {
            return prefix.equals("mgns1") ? "urn:edeveloper.Fournisseurs1031af" : null;
        }

        public Iterator<?> getPrefixes(String val) {
            return null;
        }

        public String getPrefix(String uri) {
            return null;
        }
    });

    Node node_codreg = (Node) xpath.evaluate("mgns1:CODREG", node, XPathConstants.NODE);

    ...

}

I tried with a xml which does not have the mgns1:. But at runtime I get no ListNodes ! So what is wrong ?
edit :
here is an example of an xml :
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Fournisseurs>

  <JournalExtract>2</JournalExtract>

  <Record>
    <STATUTRECORD>S</STATUTRECORD>
    <CODFOUR>148</CODFOUR>
    <RAISOC></RAISOC>
    <ADRFOUR></ADRFOUR>
    <CPVILLE></CPVILLE>
    <CODPAYS></CODPAYS>
    <TELEPHONE></TELEPHONE>
    <TELEX></TELEX>
    <FAX></FAX>
    <EMAIL></EMAIL>
    <SIRET></SIRET>
    <CONDPAIE></CONDPAIE>
    <MODPAIE></MODPAIE>
    <LIVR></LIVR>
    <REMISE>0.00</REMISE>
    <DEVISE></DEVISE>
    <CLASSE></CLASSE>
    <DELMOY>0.00</DELMOY>
    <TVAIC></TVAIC>
    <MOTCLE></MOTCLE>
    <DTEAGR>00/00/0000</DTEAGR>
    <CODREG></CODREG>
    <MTMINFAC>0.00</MTMINFAC>
    <MTMINFRANCO>0.00</MTMINFRANCO>
    <ZL01></ZL01>
    <ZL02></ZL02>
    <INDQUAL></INDQUAL>
    <CERTIF></CERTIF>
    <DTEVALMIN>00/00/0000</DTEVALMIN>
    <DTEVALMAX>00/00/0000</DTEVALMAX>
    <RAISOCREGL></RAISOCREGL>
    <ADRREGL></ADRREGL>
    <CPVILLEREGL></CPVILLEREGL>
    <PAYSREGL></PAYSREGL>
    <DOMBQE></DOMBQE>
    <CODEBQE></CODEBQE>
    <CODGUI></CODGUI>
    <COMPTE></COMPTE>
    <RIB></RIB>
    <TYPETVA></TYPETVA>
    <IBANPAYS></IBANPAYS>
    <IBANCLE>00</IBANCLE>
    <IBANCOMPTE></IBANCOMPTE>
    <CODEBIC></CODEBIC>
    <ROUTAGECDE></ROUTAGECDE>
    <ACHSYSFRTVA>false</ACHSYSFRTVA>
    <URL></URL>
    <REMINCPXNET>false</REMINCPXNET>
    <NOTMANSYST>false</NOTMANSYST>
    <PROSPECT>false</PROSPECT>
    <FOUPREF>false</FOUPREF>
    <FOUPPAL></FOUPPAL>
    <DTEMODTRI>00/00/0000</DTEMODTRI>
    <NUMDUNS></NUMDUNS>
    <CODLGFOU></CODLGFOU>
    <NOALIMAUTSF>false</NOALIMAUTSF>
    <AUTCDECH>false</AUTCDECH>
    <SEUILEPDIF>false</SEUILEPDIF>
    <MTMAXCDECH>0.00</MTMAXCDECH>
    <MTMAXCC>0.00</MTMAXCC>
    <MTMAXCCHCT>0.00</MTMAXCCHCT>
    <CP></CP>
    <VILLE></VILLE>
    <CPREGL></CPREGL>
    <VILREGL></VILREGL>
    <CAMINST>0.00</CAMINST>
    <CAMAXST>0.00</CAMAXST>
    <OCCASION>false</OCCASION>
    <ID_EXT></ID_EXT>
    <TAXE2></TAXE2>
    <TAXE3></TAXE3>
    <TAXE4></TAXE4>
    <DTECREDEM>00/00/0000</DTECREDEM>
    <BDC_ELEC>false</BDC_ELEC>
    <TYPE_FORM></TYPE_FORM>
    <FORMAT>0</FORMAT>
    <MODE_ENV></MODE_ENV>
    <MAIL_DEST></MAIL_DEST>
    <ADR_FTP></ADR_FTP>
    <USR_FTP></USR_FTP>
    <PWD_FTP></PWD_FTP>
    <PATH_DEP></PATH_DEP>
    <RECEPT_AUTO>false</RECEPT_AUTO>
    <PERIODICITE></PERIODICITE>
    <NOCCGEN>false</NOCCGEN>
  </Record>

</Fournisseurs>

Comment: You'll need to supply an example of the XML you are querying. It's quite possible nodes are in a namespace even if they don't have a prefix.
Answer: You are looking for elements named mgns1:CODREG, where mgns1 represents the namespace urn:edeveloper.Fournisseurs1031af.
In the XML document you have shown us, there are no elements in namespace urn:edeveloper.Fournisseurs1031af. So why would you expect your expression to select anything?
Moreover, you're only looking for direct children of the supplied node and you haven't told us what this node is. Perhaps you want to be looking for all descendants, not just direct children?


Cookies and Jar Problem

Question: STATEMENT
Bowl 1 contains 30 vanilla cookies and 10 chocolate cookies. Bowl 2 contains 20 of each. Now suppose you choose one of the bowls at random and, without looking, choose a cookie at random. The cookie is vanilla. What is the  Probability that it came from Bowl 1?
$P(\text {choosing Bowl 1}) = \frac 12$
$P(\text {choosing a vanilla cookie from Bowl 1}) = \frac {30}{40}$
Since events are independent, $ = \frac 12 \times \frac {30}{40} = \frac 38$  .. and this answer is wrong.
Answer: This is a good example of Bayes Rule:
$$P(B_1|V)=\frac{P(V|B_1)P(B_1)}{P(V)}$$
Your calculation gives $P(V|B_1)P(B_1)=P(B_1\cap V)$, but the denominator needs to be calculated as well:
$$P(V)=P(V|B_1)P(B_1)+P(V|B_2)P(B_2)$$
A toy example: Bowl 1 contains 1 vanilla, Bowl 2 contains 1 chocolate. Say, we select a random bowl and select a random cookie. If the chosen cookie, is vanilla, what is the probability that it's chosen from Bowl 1?
Your way gives $1/2\times1=1/2$, but actually it's certain, i.e. probability is 1, that the cookie is from Bowl 1. Keep in mind that what you're asked is $P(B_1|V)$, not $P(B_1\cap V)$.
Note: $V|B_1$ is not an event. This notation makes sense inside $P(.)$ expression. So, you should define your events carefully and express the question in terms of these events.
Comment: $V$ and $B_1$ are not independent. The odds of choosing a vanilla cookie depends on what bowl chosen.
Comment: I could have calculated it using Baye's Theorem. Even the denominator can be expanded to:  $P(A) = P(A|B)P(B) + P(A|B^c)P(B^c)$

But the point is which part of the statement  shows they are dependent events?
Comment: The probability you're asked is $P(B_1|V)$. But, you're calculating $P(B_1\cap V)$. So, multiplying them ($P(V|B_1)$ and $P(B_1)$) will not give you what is asked on the question. It's not a dependence/independence issue.
Comment: So, conditional probability can be applied to independent events?
Comment: I can't follow you. What does 'applying conditional probability' mean?
Comment: Baye's theorem is used/applied when one event is affecting the other.  If P(A | B) = P(A), then events A and B are said to be "independent", which seems to be the case here.
Comment: You can apply Bayes theorem any time. If the events are independent, applying Bayes theorem gives you $P(A|B)=P(A)$ already.
Comment: Exactly. Then as per Baye's theorem, if P(A|B)=P(A) then B is not affecting A. So in this case here too both jars have equal probabilities of 1/2 to be chosen, that ain't affected by anything.
Comment: Ok, let me be clearer: The second probability you give is $P(V|B_1)$, which means Bowl 1 is already chosen, so it's on the given side. $V|B_1$ is not an event. The given sign doesn't make any sense in set notation. It makes sense inside the probability expression. Here, $V$ and $B_1$ are your events. And, you need to formulate the question in terms of these events.

For example, how can you formulate "What is the Probability that it came from Bowl 1" based on your event definitions? Why are you multiplying them? What does $(V|B_1)\cap V$ mean (it doesn't actually, but acc. to you it means)?
Comment: Yes,  V and B1 are the events and since they are independent, hence their probabilities can be multiplied.

(V|B1)∩V  is a mixture of set theory and Probability notation.  It is like  $A^c = 1 - P(A)$ which actually doesn't mean anything because we have to map set-theory to Probability, all of it, hence the correct notation will be $P(A^c) = 1 - P(A)$. For your case  it should be  $B1 \cap V$ or $V \cap V$
Comment: So, if we choose B1 then there is is higher probability of getting vanilla cookies compared to choosing B2. Is this what we call dependence?
Comment: Yes, that's the logic.
Comment: @Arnuld is it clear now?
Comment: yeah, understood. Thanks man :-) . For independent events, we can simply multiply the probabilities, but for dependent events, we need to use Baye's Theorem to get the probabilities right

Cookies and Jar Problem


Who owns a player that is on loan?

Question: Does a club still own a player when they loan him to different club?
For example, I know Chelsea loaned Fernando Torres to AC Milan, where he was disastrous and now is loaned to Athletico Madrid.
So is he still a Chelsea player or was he loaned from AC Milan to Athletico?
Answer: The team who loans a player from another team doesn't own them, but they usually pay his wages. Often teams will loan out players who are too young/inexperienced to play for their main team, since they can gain experience and they don't have to pay their wages.
If Team A sign a player, but he's too young/inexperienced to play for them, they will often him out to other teams on loan. So say they loan him out to Team B, this means Team A still own the rights to him, but while he's on loan, they don't have to pay the wages because Team B will pay the wages.
Although, the case of Torres is a little different. Torres was on loan from Chelsea since the start of the season, however in the mid-season transfer window, Milan got Torres on a free transfer deal, so Milan are now the owners of him. As soon as the deal was completed, they loaned Torres to Atletico Madrid, in exchange for Alessio Cerci.
Unusually in this situation however, instead of Milan paying the wages of Cerci, and Atletico paying the wages of Torres, as is fairly usual for a loan deal, Milan are paying the wages of Torres, and Atletico are paying the wages of Cerci.
Torres gets paid £4m/year and Cerci gets paid £2.5m/year
Comment: The math doesn't work out well for Milan. Not sure why they went for Torres. Or they might have been looking for Cerci but they landed Torres first. Whatever, I just want a good game and Torres to be at his prime again.
Comment: @rageit it's like the Marcos Rojo deal between Manchester United and Sporting Lisbon. Man United were so desperate for Rojo, they not only paid £16m for Rojo, but also loaned Nani out to Sporting for the entire season, and will pay his wages as well. I guess Milan just did whatever they had to do to get rid of Torres and get Cerci.
Comment: @cantsay That played out pretty well but it was unfortunate for Rojo to get injured. Anyway I'd like Torres to get back to his previous self.
Answer: To quote from Wikipedia:

Fernando José Torres Sanz [...] is a Spanish professional footballer who plays for Italian club Milan, on loan from English club Chelsea [...]. He will make a permanent move to Milan effective from 5 January 2015 but will be loaned to Atlético Madrid.

So as of right now (2nd January 2015) he is a Chelsea player, but he will be an AC Milan player from 5th January.
Comment: Alright I get it. He would be a Milan player.
Comment: I have edited my question.
Comment: I'm editing the question to make the Torres question a specific example of the more general question. That way this question will still be useful in the future when he moves on or retires.

Who owns a player that is on loan?


How to use default taxonomy with a mixture of terms and content?

Question: My site has a structure like this, which seems a natural way to use taxonomy:
Food (term)
  - Fruit (term)
  -- Apple (content)
  -- Pear (content)
  - Bread (content)
  - Cheese (content)
The problem arose when I wanted an top-level overview page of Food. Logically (to me) that would mean showing Fruit, Bread and Cheese since these are the direct descendants of Food. But the default taxonomy term page for Food only shows Bread and Cheese, because it only shows content. It doesn't seem like you can show taxonomy terms in views, so overriding the view was not enough and I ended up doing some jiggery-pokery. As a fan of clean logical simple sites I would rather stick close to the defaults. What am I doing wrong?
Answer: You probably want to replace the taxonomy/term/## page with a page view of content in that term and "attach" another view to the header that lists the child "taxonomy terms".
That way you them alongside your content as a browsable tree or as a list of "folders" above the content in that folder.
Comment: I didn't know you could have a view of terms - ta. What you suggest is a workaround though, and would not work in my case. The terms would all have to appear together, and the content all together. But my client has their own particular order that they want things to appear in, and that means mixing terms and content. Thanks though


Is the characterization of Hausdorff spaces in terms of ultrafilter convergence equivalent to the ultrafilter lemma?

Question: It can be easily proven using the ultrafilter lemma that if every ultrafilter on a topological space converges to at most one point, then the space is Hausdorff. My question is is whether this statement implies the ultrafilter lemma.
It certainly implies some fragment of it, for instance it implies that every infinite set has a nonprincipal ultrafilter (the cofinite topology on an infinite set is not Hausdorff and also has the property that every principal ultrafilter converges to a unique point).
Apologies if this is in the consequences of AC book… I've temporarily lost access to my copy.
Comment: I can't see it on the list of Form 14 in Consequences.
Comment: Also didn't find anything remotely similar elsewhere in the book. Herrlich's also seem to focus more on compactness properties.
Comment: @Asaf thanks for looking. Yeah, the analogous characterization of compactness is definitely equivalent to UL (don't recall if Herrlich proves that one… probably).
Answer: Yes, this is equivalent to the ultrafilter lemma.  Let $F$ be a proper filter on a set $X$, which we may assume to not be contained in any principal ultrafilter.  Consider the space $Y=X\sqcup\{a,b\}$ with the topology that a set is open iff either it contains an element of $F$ or it contains neither $a$ nor $b$.  (This is the topology "generated" by saying the filter $F$ converges to both $a$ and $b$, i.e. the finest topology with that property.)  This space is not Hausdorff, since $a$ and $b$ do not have disjoint neighborhoods.  However, any other two points of $Y$ do have disjoint neighborhoods (here we use the assumption that $F$ is not contained in any principal ultrafilter to ensure that $a$ and $b$ can be separated from the points of $X$).
Now suppose there is some ultrafilter $G$ on $Y$ that converges to two different points, which can only be $a$ and $b$.  This means that $G$ contains every neighborhood of both $a$ and $b$, so it contains $A\cup\{a\}$ and $A\cup\{b\}$ for each $A\in F$.  It follows that $G$ contains every element of $F$, so the restriction of $G$ to $X$ is an ultrafilter on $X$ that contains $F$.
Comment: I wonder if there's a direct proof, without working towards a contradiction. It kind of feels like this proof is as direct as it gets. Very nice!


Determine a cutpoint value of a univariate continues variable with and without modelling

Question: I have a very simple (medical) data set with one continues independent variable X(a biomarker measurement) and y - the dependent outcome variable (binary, disease/non-disease). The question is to find the optimal cutpoint to separate two groups.
My first instinct was to use a logistic regression with 10-fold cross validation and computed metrics of interest for each fold (AUC, PPV, NPV, Se, Sp, LR+, LR-). But after doing some reading, I realised that I can use directly the independent variable X as the ranking variable (this is what exactly logistic regression does, maps input variable to ranking probabilities, please correct me if I'm wrong). Obviously I've got slightly different results and thus two questions:
QUESTION 1: How to extract the cutpoint from k-fold cross-validated logistic regression?
AFAIK, cross validation is used to roughly estimate the generalisation error and fine tune the hyperparameters (if there are any). Every cross validation fold produces a surrogate model. Once the hyper parameters are tuned, then all data used to fit the model. From this model, one can extract the cutpoint (inverse logistic transformation).
QUESTION 2:
Is there a conceptual difference between direct use of the independent variable and mapping through cross-validated logistic regression?
Answer:
QUESTION 1: How to extract the cutpoint from k-fold cross-validated logistic regression?
AFAIK, cross validation is used to roughly estimate the generalisation error and fine tune the hyperparameters (if there are any). Every cross validation fold produces a surrogate model. Once the hyper parameters are tuned, then all data used to fit the model. From this model, one can extract the cutpoint (inverse logistic transformation).

Small but important note on the procedure: you may use cross-valdiation to estimate generalization error xor for hyperparameter tuning. I.e., once you've used the CV results for hyperparameter tuning, the respective test cases have become part of training the final model and are not independent any more and cannot be used to estimate generalization error. Look up nested cross validation for more information.
Now, the cutpoint is just a hyperparameter, so it is determined during hyperparameter tuning. E.g. in the inner loop of a nested CV setup.
In other words, from the point of view of the outer cross validation (the one used to estimate generalization error), you determine a number of surrogate models with possibly varying cutpoints.
Checking the stability of the auto-tuned cutpoints across the outer surrogate models should be one point of your validation (or rather, verification) procedure.
The final model is trained on all data, and this training again performs the inner CV auto-tuning of the cutpoint.

QUESTION 2: Is there a conceptual difference between direct use of the independent variable and mapping through cross-validated logistic regression?

There is no conceptual difference between cross validation auto-tuning of the cutpoint directly on x and cross validation auto-tuning of the cutpoint on a logistic regression on x.
Logistic regression predicts posterior probability, though. Thus, you can check whether it is well calibrated, i.e. whether the claimed posterior probabilities are reasonably close to the observed probabilities.
You cannot do a similar check on the direct cutoff on x, as that way you do not examine the case whether the assignment is certain or not.
It is up to you to decide whether your application needs the information about a gray zone or how close the decision was, and whether this is better achieved via the logistic regressions predicted probabiliy or directly by x (e.g. a medical doctor* may find the x information more useful).
* assuming that is who gets medical biomarker results. Btw, over here (Germany), only approbated medical doctor are allowed to actually give a diagnosis. Thus, clinical lab results are e.g. reported as x together with its cutoff (normal range) and the summary information whether it is inside/outside the normal range/positive or negative (depending on the marker/analyte).


Slices from keys of a multidimensional dictionary

Question: I need to assign and retrieve slices of data using two keys, and I do not a priori know the values for one of the keys.
Specifically, I'm downloading and processing text data files that list float values by year and duration (e.g., 1 hour). The duration keys are predetermined, but the years are not. The data are provided sequentially, one line at a time (not tabular, in other words).
Because I don't know all the years in a given file, so far I've tried using defaultdict(dict). Here's my sample code.
from collections import defaultdict
a = defaultdict(dict)

a[2006][2]=0.024
a[2004][2]=0.157
a[2000][1]=0.64
a[2005][2]=0.346
a[2003][2]=0.165
a[2003][6]=0.8
a[2007][12]=0.642
a[2003][1]=0.664
a[2002][6]=0.579
a[2004][1]=0.829
a[2001][6]=0.344
a[2003][3]=0.508
a[2003][12]=0.66
a[2002][1]=0.923

:a

defaultdict(dict,
            {2006: {2: 0.024},
             2004: {2: 0.157, 1: 0.829},
             2000: {1: 0.64},
             2005: {2: 0.346},
             2003: {2: 0.165, 6: 0.8, 1: 0.664, 3: 0.508, 12: 0.66},
             2007: {12: 0.642},
             2002: {6: 0.579, 1: 0.923},
             2001: {6: 0.344}})

I need to do three things.

Retrieve all the year keys. Remember I don't know them ahead of time.
For each year, retrieve the duration key:value pairs. I figured that one out.
: a[2002]

{6: 0.579, 1: 0.923}

For each duration, retrieve the year key: value pairs. I'm stuck on this one.

I appreciate any help you can offer. If I should be doing this in numpy, pandas, or something else, feel free to redirect me. Keep in mind I don't know the year range ahead of time, and even if I did there are random gap years with no data.
Comment: not sure I'm understading...why cant you just do dict.keys() to get the keys?
Answer: Not sure what you're looking for, but for getting all the year keys and their values you can iterate over that dictionary, by doing like this:
for i in a:
    print(i, a[i])

Output:
2006 {2: 0.024}
2004 {2: 0.157, 1: 0.829}
2000 {1: 0.64}
2005 {2: 0.346}
2003 {2: 0.165, 6: 0.8, 1: 0.664, 3: 0.508, 12: 0.66}
2007 {12: 0.642}
2002 {6: 0.579, 1: 0.923}
2001 {6: 0.344}

Comment: @IndianaBones *output for key 1 might look something like this:*, look like what?
Comment: Thanks! That actually takes care of my first and second 'need'. I'll have some code that checks the key:values pairs for each year, and modifies the values under certain circumstances. But I have no idea how to efficiently do the next step, which is retrieve all the values associated with the second key. For example, the output for key **1** might look something like this:
`
{2000: 0.64, 2002: 0.923, 2004: 0.829, 2003: 0.664}
`
Or something else I can parse. But maybe I'm asking too much of a dictionary here, so numpy/pandas alternatives are welcome.
Comment: Zamir, see my repost. I'm brand new to stack exchange and I didn't realize there was an editing time limit.
Answer: from collections import defaultdict
a = defaultdict(dict)

a[2006][2]=0.024
a[2004][2]=0.157
a[2000][1]=0.64
a[2005][2]=0.346
a[2003][2]=0.165
a[2003][6]=0.8
a[2007][12]=0.642
a[2003][1]=0.664
a[2002][6]=0.579
a[2004][1]=0.829
a[2001][6]=0.344
a[2003][3]=0.508
a[2003][12]=0.66
a[2002][1]=0.923

print(a)

"""

defaultdict(<class 'dict'>, {2006: {2: 0.024}, 2004: {2: 0.157, 1: 0.829}, 2000: {1: 0.64}, 2005: {2: 0.346}, 2003: {2: 0.165, 6:0.8, 1: 0.664, 3: 0.508, 12: 0.66}, 2007: {12: 0.642}, 2002: {6:0.579, 1: 0.923}, 2001: {6: 0.344}})

"""

# Retrieve all the year keys. Remember I don't know them ahead of time.

for item in a:
  print(item)

"""
2006
2004
2000
2005
2003
2007
2002
2001
"""

# For each year, retrieve the duration key:value pairs. I figured that one out.

for year in a:

  dur_key_val = a[year]

  print(year,'=>',dur_key_val)

# For each duration, retrieve the year key: value pairs. I'm stuck on this one.

durationDict  = {}

for year in a:

  dur_key_val = a[year]

  for inner_key in dur_key_val:

    duration = dur_key_val[inner_key]

    durationDict[duration] = { year:inner_key }

print(durationDict)

"""
{0.024: {2006: 2}, 0.157: {2004: 2}, 0.829: {2004: 1}, 0.64: {2000: 1}, 0.346: {2005: 2}, 0.165: {2003: 2}, 0.8: {2003: 6}, 0.664: {2003: 1}, 0.508: {2003: 3}, 0.66: {2003: 12}, 0.642: {2007: 12}, 0.579: {2002: 6}, 0.923: {2002: 1}, 0.344: {2001: 6}}
"""


Connecting two networks VPN different IP Schemes

Question: I have a client with two networks in two buildings and they want to access each others resources.  Right now site B connects to site A via a VPN over a T1 line.  They want to get rid of the T1 and go to our local cable provider which offers a 50mb down 5mb up package.  Site B's ip scheme is 192.168.1.x and site A's scheme is 192.168.0.x.  We have 2 Watchguard XTM 25's and are ready to use them to pin up the VPN.
In summary I have all the parts ready to do connect the two networks, my question to the community is what do I need to watch out for and do I need any specific routes on the firewalls to allow traffic to move from the .0 network to the .1 network and vice-verse.
Unfortunately this is my first time to do something like this and I'm kinda on my own!
Answer: Many of the details of how to set things up here are specific to your Watchguard box. I've never worked with those devices, so I'll speak in generalities. I'll also assume that you've figured out how to configure a site-to-site VPN tunnel between the Watchguards (which I'll refer to as "routers" from here on out).

A site-to-site VPN tunnel needs to be established between routers
A static route needs to be set on Site A's router to route traffic destined to 192.168.1.0/24 through the VPN to site B
A static route needs to be set on Site B'S router to route traffic destined to 192.168.0.0/24 through the VPN to site A
Firewall rules between sites should be set up using a "default deny" policy, which requires you to explicitly specify Access Lists for what IP addresses and ports are open between sites. For instance, if Site A users only need access to a file server and a printer in Site B, firewall rules should be put in place that only permit that traffic, and no other traffic. This limits collateral damage if, perchance, a workstation gets infected with a virus, it would not be able to spread through the VPN to systems in the other site.
You probably want some sort of monitoring mechanism to alert you if the tunnel drops

Steps 2 and 3 will likely be set up automatically by the router when you configure the VPN tunnel.
Be aware that intra-site network performance will likely suffer quite a bit after this change. It's true, the available bandwidth of the cable connections is higher than the T1. However, your latency will likely increase by an order of magnitude (which is a huge deal for protocols like CIFS, which are very chatty and suffer greatly over high-latcency connections), and the reliability of the WAN will go down significantly. Even if these are "business class" cable internet connections, they're of a different class of service than a T1 is.


How to solve the recurrence $T(2k)+(2k-1)(2k-2)T(2k-2)=(-1)^{k-1}\cdot 2\cdot(2k-2)!$?

Question: I have to solve the recurrence $T(2k)+(2k-1)(2k-2)T(2k-2)=(-1)^{k-1}\cdot 2\cdot(2k-2)!$ with $T(2)=2$.
I find this recurence when I tried to calculate $\left.[(\arctan{x})^2]^{(n)}\right|_{x=0}$ (the n-th derivative).
And I'm solving it as following:
$y=(\arctan{x})^2$
$(1+x^2)y'=2\arctan{x}$
then differentiate both sides for $2k$ times and $2k-1$ times respectively,  $y^{(2k+1)}(0)+2k(2k-1)y^{(2k-1)}(0)=0$ and $y^{(2k)}(0)+(2k-1)(2k-2)y^{(2k-2)}(0)=(-1)^{k-1}2\cdot(2k-2)!$.
Looking into $y'(0)=0$ and $y''(0)=2$, then we have
$y^{(2k-1)}(0)=0$.
But I don't have any idea to calculate the derivates of even orders, except calculate it one by one.
So my question is, how to solve the recurence or how to solve this problem in a wiser way.
===============================================
Now I re-calculate this problem using Leibniz formula, and my answer is
$T(2n+2)=(-1)^n 2(2n+1)!\sum\limits_{k=0}^{n} \dfrac{1}{2k+1}$,
Putting $n=0,1,2$ my answer is excatly the value of $[(\arctan{x})^2]^{(2n+2)}$ at $x=0$.
And my answer contains $1+\frac{1}{3}+\cdots+\frac{1}{2n+1}$, so I believe I cannot improve the form without importing special function like $psi$ or any others.
Thanks for you all.
Comment: Here's a start: divide both sides by $(2k)!$, and make the substitution $U(2k)=\frac{T(2k)}{(2k)!}$.  Then the recurrence becomes $U(2k)+U(2k-2)=\frac{(-1)^{k-1}}{k(2k-1)}$.
Answer: Since what you want is
$(\arctan^2(x))^{(n)}$,
I have derived the formula for
$(\arctan(x))^{(n)}$
below.
Combined with
Leibnitz's formula
$(fg)^{(n)}
=\sum_{k=0}^n \binom{n}{k}f^{(k)}g^{(n-k)}
$,
so
$(f^2)^{(n)}
=\sum_{k=0}^n \binom{n}{k}f^{(k)}f^{(n-k)}
$,
this can give a formula for this.
$x^2+1 = (x+i)(x-i)
$
so
$(x^2+1)^n = (x+i)^n(x-i)^n
$
so
$\dfrac1{(x^2+1)^n} = \dfrac1{(x+i)^n(x-i)^n}
$
$\begin{array}\\
\dfrac{d^n \arctan(x)}{dx^n}
&= \frac12 (n-1)!i (-1)^n ((-i + x)^{-n} - (i + x)^{-n})
\qquad\text{(according to Wolfy)}\\
&= \frac12 (n-1)!i (-1)^n \left(\dfrac1{(-i + x)^{n}} - \dfrac1{(i + x)^{n}}\right)\\
&= \dfrac{ (n-1)!i (-1)^n}{2(x^2+1)^n} \left(\dfrac{(x^2+1)^n}{(-i + x)^{n}} - \dfrac{(x^2+1)^n}{(i + x)^{n}}\right)\\
&= \dfrac{ (n-1)!i (-1)^n}{2(x^2+1)^n} \left((x+i)^n - (x-i)^n\right)\\
&= \dfrac{ (n-1)!i (-1)^n}{2(x^2+1)^n}\sum_{k=0}^n x^k\binom{n}{k}(i^{n-k}-(-i)^{n-k})\\
&= \dfrac{ (n-1)!i (-1)^n}{2(x^2+1)^n}\sum_{k=0}^n x^{n-k}\binom{n}{k}(i^{k}-(-i)^{k})\\
&= \dfrac{ (n-1)! (-1)^n}{2(x^2+1)^n}\sum_{k=0}^{2k+1 \le n} x^{n-(2k+1)}\binom{n}{2k+1}2((-1)^{k+1})
\qquad\text{(see below)}\\
&= \dfrac{ (n-1)! (-1)^n}{(x^2+1)^n}\sum_{k=0}^{2k+1 \le n} x^{n-(2k+1)}\binom{n}{2k+1}(-1)^{k+1}\\
\end{array}
$
I'll stop here.
Here's the formula for
$i^k-(-i)^k$.
$i^k-(-i)^k
=0 (k=0),
=i-(-i) = 2i (k=1),
=i^2-(-i)^2=0 (k=2),
=i^3-(-i)^3=-2i (k=3)
$
so
$i(i^k-(-i)^k)
=0 (k=0, 2),
=-2, 2 (k=1, 3)
=2(-1)^{(k+1)/2} (k=1, 3)
$
Answer: Hint.
This recurrence equation making $2k=j\;$ is equivalent to
$$
T(j)+(j-2) (j-1) T(j-2)=-2 i^j (j-2)!
$$
with solution
$$
T(j) = -i^j (j+1)! \left(c_2 (-1)^j+c_1+(-1)^{2 j+1} \Phi (-1,1,j+1)+\psi ^{(0)}(j+1)\right)
$$
Comment: what is the $\psi$ and $\Phi$?
Comment: @闫嘉琦  $\psi^{(0)}\;$ is the PolyGamma(0,j+1) function and $\Phi$ is the LerchPhi(-1,1,j+1) function.


Regex para pegar palavra entre duas palavras ou "/"

Question: Alguém pode me ajudar, gostaria de pegar apenas a palavra entre resourceGroups e providers e atribuir a uma variavel em javascript.
/9c2a1079-35f0-4298-9eb3-7f63903f2ae1/resourceGroups/pegarEssaPalavra/providers/

Comment: Mas é sempre o penultimo ? Ou é sempre o que está entre as palavras `resourceGroups` e `providers` ?
Comment: I ae Brother... seria sempre o que está entre resourceGroups e providers
Answer: Você pode tentar algo como:
var caminho = "/9c2a1079-35f0-4298-9eb3-7f63903f2ae1/resourceGroups/perarEssaPalavra/providers/";
var separado = path.split('/');
var palavra = split[split.indexOf("resourceGroups") + 1];

A palavra que busca estará na variável palavra.
Porém, da forma que fiz, obrigatoriamente, a palavra que está buscando deve ficar sempre após a palavra resourceGroups no seu path.
Isso porque com o split, eu separo o seu caminho pelas / e depois busco o índice em que a palavra resourceGroups está e adiciono mais 1, resultando na palavra que busca.
Answer: Pode usar uma regex com .split() depois converter a array em string com .join():

var string = "/9c2a1079-35f0-4298-9eb3-7f63903f2ae1/resourceGroups/perarEssaPalavra/providers/";
var resultado = string.split(/.*resourceGroups\/|\/providers\//).join('');

console.log(resultado);

Explicação:
A regex .*resourceGroups\/|\/providers\/ vai quebrar a string em tudo que vier antes até resourceGroups/ ou a partir de /providers/, isolando a palavra perarEssaPalavra. Porém a array resultante desse split possuirá valores vazios:
["", "perarEssaPalavra", ""]

Com .join('') eu converto a array para string ignorando o que for vazio, resultando em perarEssaPalavra.
Usando indexOf() com substring():
Outra forma sem uso de expressões regulares é o simples .indexOf() dentro de um .substring():

var string = "/9c2a1079-35f0-4298-9eb3-7f63903f2ae1/resourceGroups/perarEssaPalavra/providers/";
var resultado = string.substring(string.indexOf("resourceGroups/")+15, string.indexOf("/providers"));

console.log(resultado);

Como a string resourceGroups/ tem tamanho fixo, basta pegar a sua posição na string e somar +15 (referente ao tamanho da string) até a posição da string /providers.
Comment: Vlw Dvd... consegui, apenas uma pequena modificação no Regex para pegar tudo apos a palavra Provider.
Comment: var resourceUri = consumos[1].instanceData.resourceUri;
        console.log(resourceUri);

        var resultado = resourceUri.split(/.*resourceGroups\/|\/providers.*/).join('');
        console.log(resultado);
Answer: Essa regex /\/resourceGroups\/(.*)\/providers\// pegará o que está entre /resourceGroups/ e /providers/ por meio de um grupo.
Funcionando

let texto = `/9c2a1079-35f0-4298-9eb3-7f63903f2ae1/resourceGroups/pegarEssaPalavra/providers/`

const expressao = /\/resourceGroups\/(.*)\/providers\//

console.log(texto.match(expressao)[1]);
Comment: Vlw meu brother... deu certo só fiz uma pequena alteração no Regex para pegar tudo após o provider, porque tem mais itens após eu simplifiquei a uri
Comment: /.*resourceGroups\/|\/providers.*/
Comment: @FernandoAntunes bacana, bom demais ter conseguido.
Answer: Um regex para isso pode ser da seguinte forma:
.*\/([^/]+)\/[^/]+

Sendo que nesse caso ele sempre pegará o penúltimo grupo entre as barras, se adicionar 'teste/' ao final, a expressão retornará 'providers'.
Em javascript:
const regex = /.*\/([^/]+)\/[^/]+/;
const str = `/9c2a1079-35f0-4298-9eb3-7f63903f2ae1/resourceGroups/cte/pegarEssaPalavra/providers`;
let m;

if ((m = regex.exec(str)) !== null) {
    // The result can be accessed through the `m`-variable.
    m.forEach((match, groupIndex) => {
        console.log(`Found match, group ${groupIndex}: ${match}`);
    });
}

Veja o exemplo aqui:
https://regex101.com/r/v60aQS/1


VI Editor on Ubuntu using VIM Short Cuts?

Question: I installed Ubuntu and I tried to use the terminal's vi editor.   The editor is using a different set of short cut keys that I'm not familiar with.  Someone told me it's probably using the VIM short cut keys.
How do I make it use the normal vi short cut keys?   For example, I want
i - insert
:q - quit
etc...
How do I tell vi to use this set of commands instead of vim?
Another problem:  For example, when I hit "back space", I expect vi to Delete, instead of just move the cursor back.  When I hit the arrow keys, random letters show up.  There are other really quirky things like this that i'm not use to because I've been using the "normal" vi editor.
Comment: What is the command you are typing?
Answer: Update:
From what you said about the backspace and the arrow keys, that sounds like it could be the terminal, not the editor.  So your editor is not getting the right keys.  Are using a particular xterm? are you on the same machine? Are you using screen?

Vi and VIM should have the same shortcuts.  Are you sure you are not using an Emacs editor like nano ( the ubuntu default).  That would have shortcuts like ctrl-x to exit.
What does 'echo $EDITOR' from the shell tell you?
Comment: it prints  an empty line
Comment: I'm not sure, i just isntalled ubuntu for the first time.  I'm a new linux user.   From Gnome, i go to Applications>Terminal.  Then in terminal, i type vi to start up the editor.
Comment: Rik sounds like his answer is more on the right track to me ...
Answer: You may be using a different clone or a cut down version of vim.  Ubuntu by default uses vim-tiny if I remember correctly.  You can find out which one is being used by checking the link "/etc/alternatives/vi"**.  If it points to /usr/bin/vim.tiny you have a very minimal vim installed.  If it points to some other file you can use "dpkg -S filename" to figure out where it came from.
To install a different "clone" use apt-get or another package management tool.  I suspect that vim-gnome or vim-full may more to your liking.  If one or both of the above are already installed but you have the link
** Many utilities and programs like mail, vi, java, awk, etc. are linked through /etc/alternitives/.  For example on my system /usr/bin/cc is a link to /etc/alternatives/cc which is a link to /usr/bin/gcc.  This allows a common set of tool names to be used with different packages that provide the same functionality.
I hope this helps
Comment: perfect, i did a sudo apt-get install vim-full
Comment: that might have accidentally fixed the problem (perhaps by overwriting a messed up /etc/vim/vimrc), but vim-tiny and vim-full both use the same key bindings - they ARE both vi clones after all...the differences in the two packages are not in how they work, but in how many vim enhancements have been compiled in to /usr/bin/vi
Comment: Actually the vimrc file used by vim.tiny contains 2 commands.  The first sets where libraries are.  The second sets compatible.  the other vim packages use a different /etc/vim/vimrc file set that call addtional files under /usr/share/.

My mention of using vim-full is based on my experience of vim-tiny not always playing well with differing terminals for X11.  It is possible to configure vim.tiny to work with more terminals but the vim-full meta-package has the configuration already there.
Answer: vim uses the same shortcuts... i is insert and :q is quit, is setting set nocompatible in .vimrc going to help?


React Native FlatList Reorder

Question: So, i', using flatlist in my application, an I set the number of columns equal to two. All ok.
But its ordering this way:
1 2
3 4
5 6
There is someway to render this way ?
1 4
2 5
3 6
Comment: Please see [ask], then revise your post title to ask a clear, specific question. Also revise your post to include some code.
Answer: You can't have the display you want. Flatlist renders the items depending order of your data with numColumns or by default.
In order to have your display, you can use flexWrap: 'wrap' style, but unfortunately you can use it with Flatlist.
In case if you don't need a Flatlist to display your data, this below the updated code from the Flex Wrap documentation.
import React, { useState } from "react"
import { View, TouchableOpacity, Text, StyleSheet } from "react-native"

const data = [
  "orangered",
  "orange",
  "mediumseagreen",
  "deepskyblue",
  "mediumturquoise",
  "mediumslateblue",
  "purple",
  "blue",
  "black",
  "pink",
  "red",
  "green",
  "gray"
]

export const App = () => {
  const [flexWrap, setFlexWrap] = useState("wrap")

  return (
    <PreviewLayout
      label="flexWrap"
      selectedValue={flexWrap}
      values={["wrap", "nowrap"]}
      setSelectedValue={setFlexWrap}
    >
      {data.map((value, index) => {
        return (
          <View
            key={`List_${index}`}
            style={[styles.box, { backgroundColor: value }]}
          >
            <Text style={styles.textBox}>{index}</Text>
          </View>
        )
      })}
    </PreviewLayout>
  )
}

const PreviewLayout = ({
  label,
  children,
  values,
  selectedValue,
  setSelectedValue
}) => (
  <View style={{ padding: 10, flex: 1, marginTop: 50 }}>
    <Text style={styles.label}>{label}</Text>
    <View style={styles.row}>
      {values.map(value => (
        <TouchableOpacity
          key={value}
          onPress={() => setSelectedValue(value)}
          style={[styles.button, selectedValue === value && styles.selected]}
        >
          <Text
            style={[
              styles.buttonLabel,
              selectedValue === value && styles.selectedLabel
            ]}
          >
            {value}
          </Text>
        </TouchableOpacity>
      ))}
    </View>
    <View style={[styles.container, { [label]: selectedValue }]}>
      {children}
    </View>
  </View>
)

const styles = StyleSheet.create({
  container: {
    flex: 1,
    marginTop: 8,
    backgroundColor: "aliceblue",
    maxHeight: 400
  },
  box: {
    width: 50,
    height: 80,
    justifyContent: "center",
    alignItems: "center"
  },
  textBox: {
    color: "white",
    fontWeight: "bold"
  },
  row: {
    flexDirection: "row",
    flexWrap: "wrap"
  },
  button: {
    paddingHorizontal: 8,
    paddingVertical: 6,
    borderRadius: 4,
    backgroundColor: "oldlace",
    marginHorizontal: "1%",
    marginBottom: 6,
    minWidth: "48%",
    textAlign: "center"
  },
  selected: {
    backgroundColor: "coral",
    borderWidth: 0
  },
  buttonLabel: {
    fontSize: 12,
    fontWeight: "500",
    color: "coral"
  },
  selectedLabel: {
    color: "white"
  },
  label: {
    textAlign: "center",
    marginBottom: 10,
    fontSize: 24
  }
})

React Native FlatList Reorder


What does it mean for an ODE to be conservative?

Question: What does it mean for an ODE to be conservative?
For example, I already read somewhere that the equation
$$w\cdot y''-y+y^{2k+1}=0,$$
with $w>0$ and $k\in \mathbb{N}$ constants fixeds, is conservative. In practice, what does this mean?
Comment: Is a constant fixed.
Comment: Is $w$ a constant or a variable?  Perhaps the independent variable?
Comment: Do you mean a conservative system?
Comment: No, ODE conservative. But, what means conservative system?
Answer: Given the differential equation
$wy'' - y + y^{2k + 1} = 0, \tag 1$
we may multiply it through by $y'$:
$wy'y'' - yy' + y^{2k + 1}y' = 0, \tag 2$
and observe that
$\left ( \left ( \dfrac{w}{2} y' \right )^2 \right )' = wy''y', \tag 3$
and
$\left ( -\dfrac{y^2}{2} + \dfrac{y^{2k + 2}}{2k + 2} \right )' = - yy' + y^{2k + 1}y'; \tag 4$
then (2) may be written
$\left ( \left ( \dfrac{w}{2} y' \right )^2 \right )' + \left ( -\dfrac{y^2}{2} + \dfrac{y^{2k + 2}}{2k + 2} \right )' = 0, \tag 5$
or
$\left ( \left ( \dfrac{w}{2} y' \right )^2 -\dfrac{y^2}{2} + \dfrac{y^{2k + 2}}{2k + 2} \right )' = 0; \tag 6$
thus,
$\left ( \dfrac{w}{2} y' \right )^2 -\dfrac{y^2}{2} + \dfrac{y^{2k + 2}}{2k + 2} = C, \; \text{a constant} \tag 7$
along the solution curves $(x, y(x))$ of (1).  That is, the quantity on the left of (7) is a conserved quantity of the equation(1); hence we deem (1) a conservative ordinary differential equation, since the function
$F(y, y') = \left ( \dfrac{w}{2} y' \right )^2 -\dfrac{y^2}{2} + \dfrac{y^{2k + 2}}{2k + 2} \tag 8$
is invariant in value on the solution curves.
In general, a conservative second-order equation or system is one for which a function such as $F(y, y')$ exists.  For these $F(y, y')$, it follows that
$\dfrac{\partial F(y, y')}{\partial y} y' + \dfrac{\partial F(y, y')}{\partial y'}y'' = \dfrac{dF(y, y')}{dx} = 0, \tag 9$
and thus $y(x)$ satisfies the deifferential equation (9).  We may in fact invoke these principles to construct differential equations corresponding to many different $F(y, y')$; for example, if
$F(y, y') = \cos y + e^{y'}, \tag{10}$
then we have
$- y' \sin y + e^{y'}y'' = 0, \tag{11}$
or
$y'' = e^{-y'}y'\sin y. \tag{12}$
Comment: Great answer! Thanks!
Comment: @GuilhermedeLoreno:  my pleasure, sir; and thanks for the "acceptance".  Cheers!


Creating Pay and Configure Products on Drupal Commerce

Question: I am using Commerce Product Option (https://drupal.org/project/commerce_option) module to create a customisable product.
I want a way in which the user can checkout and make payment for the product and then be allowed to customise it. What would be the ideal set of Rules for this scenario?
Answer: This module set only supports customizing the product prior to checkout. Achieving customization after checkout will require custom module development.


Nodejs: url.parse issue with arrays inside query

Question: http://domain.com/action?params[]=1&params[]=2&params[]=3

returns:
query: { 'params[]': [ '1', '2', '3' ] }

params[] as name instead of params?
After PHP it's kinda surprise.
jQuery serialization is adding [] on parameters btw.
Are you guys wrote a helper for this or I'm just doing it wrong?
Answer: This seems like expected behavior to me; I would be more surprised if the querystring parser removed part of the name.  That is, the module is doing exactly what I would expect from a parser which simply splits name/value pairs by '&' and name/value by '=' (and unescapes special characters).
var qs = require('querystring');

qs.parse('params=1&params=2&params=3'); // Name should be "params"
// => { 'params': ['1', '2', '3'] }

qs.parse('params[]=1&params[]=2&params[]=3'); // Name should be "params[]"
// => { 'params[]': ['1', '2', '3'] }

Comment: Mate i'm using jQuery and params serialization is taken by it. It's sending this params[]=1&params[]=2&params[]=3 type of query.
Comment: I have found a module for this. Question is closed. :)
Comment: A little observation is that, naturally, if you pass only one parameter using params=1 it will not be parsed as an array.
Answer: This module does parsing as required:
https://github.com/visionmedia/node-querystring
There is another one for complex arrays if this doesn't work:
https://github.com/jazzychad/querystring.node.js
Both found here:
https://github.com/joyent/node/wiki/modules
Comment: Yes indeed. The default Node.js decided not to implement the feature for params with multiple values, but TJ's module solves that.
Comment: Guess Ry shouldn't be bothered with such misc issues atm.
Comment: Yeah probably it's ok to leave this out of the core and into a separate module.


Random number generation and collision check

Question: I was working on a random number generator in NodeJS, I use Math.random() which gives a random number between 0 and 1. I can get a whole number between 0 and X numbers using the following function:
Math.floor(Math.random() * ( X - 0 + 1) + 1)

Now I noticed something. If I want lets say 99 unique numbers I need to keep my maximum range of numbers (X) to at least 9999, i.e double the number of digits. This works where required unique numbers are 999 (3 digits) and when X is at least 999999 (6 digits), and so on.
I don't know why, but this gives me least amount of collisions. Is there a mathematical reason behind this or something? Like is there a rule which says something similar?
Regards
Comment: Your parentheses are unbalanced.
Comment: The result is the probability of having at least one collision, so yes - smaller the better.
Comment: Most likely they are too big. You exercise now is to prove (mathematically) that doubling the digits of "space" size makes the collision probability $P(k,n)\leq \frac{1}{2}$ where $n$-"space" size, $k$ - sample size. Knowing that $$P(k,n)=1-\frac{n!}{(n-k)!\cdot n^k}$$
For example $P(99,9999)=0.385379...$
Comment: oooohhhh i get it. Thanks!
Comment: Didn't you mean to write << If I want lets say *99 unique numbers* I need to keep my *maximum range of numbers (X)* to ***at least 9999*** >>?
Comment: @rtybase actually no... well kinda yes. I didn't think about it that way. Yeah. At least 9999. I have updated it to atleast. Thanks!
Comment: @echo_salik ok ... one more question, have you tried to calculate the [collision probability](https://math.stackexchange.com/questions/3492584/whats-the-probability-of-generating-an-existing-account-id/3492618#3492618) given the number of samples $99$ and the "space" size of $9999$?
Comment: @rtybase umm... no... i have not. I'll try it out. Is there a calculator out there which woul do something like this?
Comment: Compare these 3 values for the sample size $99$: [with "space" size $99999$](https://www.wolframalpha.com/input/?i=1-99999%21%2F%28%2899999-99%29%21+*+99999%5E99%29) vs [with "space" size $9999$](https://www.wolframalpha.com/input/?i=1-9999%21%2F%28%289999-99%29%21+*+9999%5E99%29) vs [with "space" size $999$](https://www.wolframalpha.com/input/?i=1-999%21%2F%28%28999-99%29%21+*+999%5E99%29) ... larger the "space" the better.
Comment: so smaller the result better the collision avoidance?
Comment: I am getting an error for the numbers I am using, I guess they are too big.
Answer: Further to the comments, let's try to find some bounds for the probability of having at least one collision
$$P(k,n)=1-\frac{n!}{(n-k)!\cdot n^k} \tag{1}$$
where $k$ is the sample size and $n$ is the "space" size, $k<n$. For more details see Birthday Paradox wiki article and this question.

Proposition 1. We have
  $$1-e^{-\frac{(k-1)k}{2n}}\leq P(k,n)\leq 1-e^{k-1-n\log{\frac{n-1}{n-k}}} \tag{2}$$

First of all
$$\frac{n!}{(n-k)!\cdot n^k}=\left(1-\frac{1}{n}\right)\left(1-\frac{2}{n}\right)\left(1-\frac{3}{n}\right)...\left(1-\frac{k-1}{n}\right) \tag{2a}$$
Now, using
$$e^{-\frac{x}{1-x}}\leq 1-x \leq e^{-x}, x\in[0,1)$$
and indeed each $\frac{i}{n}\in[0,1)$, for $i=1..k-1$, we have from $(2a)$
$$e^{-\frac{1}{n-1}-\frac{2}{n-2}-...-\frac{k-1}{n-(k-1)}}\leq
\frac{n!}{(n-k)!\cdot n^k}\leq
e^{-\frac{1}{n}-\frac{2}{n}-...-\frac{k-1}{n}}\iff\\
e^{\sum\limits_{i=1}^{k-1}\frac{n-j-n}{n-j}}\leq
\frac{n!}{(n-k)!\cdot n^k}\leq
e^{-\frac{1}{n}\left(\sum\limits_{i=1}^{k-1}i\right)}\iff$$
$$e^{k-1-n\left(\sum\limits_{i=1}^{k-1}\frac{1}{n-j}\right)}\leq
\frac{n!}{(n-k)!\cdot n^k}\leq
e^{-\frac{(k-1)k}{2n}} \tag{2b}$$
Using integral test as a technique, it's easy to show
$$\sum\limits_{i=1}^{k-1}\frac{1}{n-j}\leq\int\limits_{n-k}^{n-1}\frac{1}{x}dx=\log{\frac{n-1}{n-k}}$$
Multiply by $-n$, add $k-1$, apply this to $(2b)$ and we have
$$e^{k-1-n\log{\frac{n-1}{n-k}}}\leq
\frac{n!}{(n-k)!\cdot n^k}\leq
e^{-\frac{(k-1)k}{2n}} $$
Multiply by $-1$, add $1$ and we have $(2)$.

A few observations. We have
$$k=\underbrace{99..9}_{t \text{ times}}=10^t -1$$
and
$$n=\underbrace{99..9}_{2t \text{ times}}=10^{2t} -1=\left(10^t -1\right)\left(10^t +1\right)=k(k+2) \tag{3}$$

Now let's plug $(3)$ into $(2)$ ant take the limit when $k\to\infty$.
$$1-e^{-\frac{(k-1)k}{2n}}=
1-e^{-\frac{(k-1)k}{2k(k+2)}}=
1-e^{-\frac{k-1}{2(k+2)}}\to 1-\frac{1}{\sqrt{e}},
k\to\infty \tag{4a}$$
For the other side (to make it simple), I will use Taylor series and the fact that $e^x$ is continuous:
$$k-1-n\log{\frac{n-1}{n-k}}=
k-1-k(k+2)\log{\frac{k^2+2k-1}{k^2+k}}=\\
k-1-k(k+2)\log{\left(1+\frac{k-1}{k^2+k}\right)}=\\
k-1-k(k+2)\left(\frac{k-1}{k^2+k}-\frac{1}{2}\left(\frac{k-1}{k^2+k}\right)^2+O\left(\frac{1}{k^3}\right)\right)=\\
k-1\left(1-\frac{k(k+2)}{k^2+k}\right)+\frac{1}{2}\frac{k(k+2)(k-1)^2}{(k^2+k)^2}-O\left(\frac{1}{k}\right)=\\
-\frac{k(k-1)}{k^2+k}+\frac{1}{2}\frac{k(k+2)(k-1)^2}{(k^2+k)^2}-O\left(\frac{1}{k}\right)
\to -1 + \frac{1}{2} = \\
-\frac{1}{2}, k\to\infty$$
As a result
$$1-e^{k-1-n\log{\frac{n-1}{n-k}}} \to 1-\frac{1}{\sqrt{e}},
k\to\infty \tag{4b}$$

From $(2)$, $(4a)$, $(4b)$ and squeezing

Given $(3)$ or $n=k(k+2)$ we have:
  $$P(k,n) \to 1-\frac{1}{\sqrt{e}}, k\to\infty \tag{5}$$

Which is less than $0.4$, so there is "less than half" chance to obtain a collision.


Use Bias with apachesolr module

Question: I want to use Apache Solr in my site build with Drupal7.
The server is UP, simples searches are working but I can't boost a field with bias.
For example, I boosted the title (or label in the administration page), giving him a 5 in the select field.
After re-index the node, I searched and the order of the result still the same.
I tried to create a little module with apachesolr's hook to watch the document it send to solr server.
hook_apachesolr_index_documents_alter():
[_fieldBoosts:protected] => Array
(
[id] =>
[site] =>
[hash] =>
[entity_id] =>
[entity_type] =>
[bundle] =>
[bundle_name] =>
[path] =>
[url] =>
[language] =>
[path_alias] =>
[label] =>
[content] =>
[teaser] =>
[ss_name] =>
[tos_name] =>
[ss_name_formatted] =>
[tos_name_formatted] =>
[is_uid] =>
[bs_status] =>
[bs_sticky] =>
[bs_promote] =>
[is_tnid] =>
[bs_translate] =>
[ss_language] =>
[ds_created] =>
[ds_changed] =>
[ds_last_comment_or_change] =>
[is_comment_count] =>
[type_name] =>
[created] =>
[changed] =>
[last_comment_or_change] =>
[comment_count] =>
[name] =>
[tos_content_extra] =>
[access__all] =>
)

All the data are empty.
This is a screenshot of my module setting page.
screenshot http://img338.imageshack.us/img338/7984/drupalsolrconf.png
Answer: To verify the boost values are included in your queries, tail the Solr request.log file.  You'll see things like &qf=label%5E5.0 (%5e is a caret ^, which marks the boost value).
Another useful trick for optimizing the scores is to include the score in your themed results output.  You may find the boosts are affecting the scores, but aren't high enough to substantially change the ranking.  This can be added with a small hook:
function hook_preprocess_search_result(&$variables) {
  if (user_access('administer search')) {
    $variables['title_suffix'] = '[score: ' . $variables['result']['score'] . ']';
  }
}

Answer: The settings page you are referring to controls query-time boosts, not index-time boosts. So perhaps you can find the effective boosts better in a query-modifying hook.
Comment: This also means that you do not need to reïndex content after changing the bias settings!

Use Bias with apachesolr module


jquery output looping and can't get getjson values out

Question: I have the following code:
    var weatherstations =
       [{"Name":"city1","Code":"CODE1"},
        {"Name":"city2","Code":"CODE2"},
        {"Name":"city3","Code":"CODE3"},
        {"Name":"city4","Code":"CODE4"},
        {"Name":"city5","Code":"CODE5"}];

      $.each(weatherstations, function(key,value) {
        //console.log(value.Name); // shows the city in the console log

         $.getJSON('http://www.domain.com/getweather-json.php?weatherstation=' + value.Code, function(result){
            $.each(result, function(index, item){
          console.log(item.clouds); // shows cloud variable in console log

    //        $('#wx').append('
'+item.temp+'

'+value.Name+'

'+item.clouds+'

'+item.wind+'

');
            }); //.each json call
         }); //.getjson
      }); //.each weatherstations

The problems I'm running into is.. that I do not get 5 lines (IF I have that $(wx) line uncommented), but 20: Four for each city.
On top of that.. the console.log(item) gives me ALL the data back from the json. If I do console.log(item.clouds), then I get "undefined" back.. Why is this?
JSON example: {"clouds":"mostly cloudy","conditions":"","temp":"12°F","wind":"varies 2 mph"}
(when I view the json in that url, I see a few empty lines and then the json.. not sure if that causes the 4x city that shows up)
Answer: Not sure why the .each wouldn't work.. and why it would return 4 lines each time.
I changed the getJSON code to:
$.getJSON('http://www.domain.com/getweather-json.php?weatherstation=' + value.Code, function(result){

        $('#wx').append('
'+result.temp+'

'+value.Name+'

'+result.clouds+'

'+result.wind+'

');
}); //.getjson

And now it gives me the feedback I needed.


Computing standard basis vector from 3x4 matrix

Question: I need to compute Arrow securities $e_1 = (1,0,0), e_2 = (0,1,0)$ and $e_3 = (0,0,1)$ as a linear combination of the $r_1, r_2, r_3, r_4$ that are represented as the columns in the following matrix:
$$ \begin{pmatrix}
  1 & 2 & 2 & 6 \\
  1 & 0 & 1 & 3 \\
  1 & 0 & 1 & 1 \\
 \end{pmatrix}$$
I tried to solve this by augmenting the Identity matrix on the right and than solving it by writing it in row echelon form. I got the following result:
$$\left(\begin{array}{cccc|ccc}
  1 & 0 & 1 & 0 & 0 & -1/2 & 3/2\\
  0 & 1 & 1/2 & 0 & 1/2 & -5/4 &3/4\\
  0 & 0 & 0 & 1 & 0 & 1/2 & -1/2\\
 \end{array}\right)$$
From the solution manual, I know that:
$$ \begin{aligned} e_1 &= 0.5 r_2 \\ e_2 &= 0.5r_4 - 0.5r_1 - 1.25r_2 \\ e_3 &= r_1 -e_1 - e_2 \end{aligned} $$
I can see some relation between this solution and my computations. But how can I exactly deduce this from my computations? What is the intuition behind it?
Answer: The first difficulty is that there are many possible solutions. Suppose that the columns (in a 2 x 3 case) were $(1, 0), (2, 0), (0, 1)$ and you have to express $(4, 0)$ as a combination of columns. Then "4 times column 1" is an answer, as is "2 times column 2". In general, linear dependence (which you'll get when you have more columns than dimensions) leads to this sort of multiple correct answer" situation.
Your example is just like this, except that the redundancy isn't quite so obvious.
The second difficulty is more fundamental: When you adjoin the identity to the right of a square matrix $M$ and do row ops on both, each row op corresponds to LEFT multiplication by an elementary matrix. So after one op, you have
$$
E_1 M | E_1 I
$$
After two, you have
$$
E_2 E_1 M | E_2 E_1 I
$$
Notice that at any point, the left matrix is the right matrix times M. If you reduce all the way to the identity on the left, you have
$$
I | E_k \cdots E_2 E_1 I
$$
with $(E_k \cdots E_2 E_1) M = I$, so you've expressed every row of $I$ as the result of a sequence of row-ops on$M$. When $M$ isn't square, you achieve almost the same thing. The key point is that this gets you rows of $I$ as combinations of rows of $M$. That won't help you solve your problem, which involves columns.
Solution: append a $4 \times 4$ identity BELOW $M$, like this:
$$\begin{bmatrix}
1 & 2 & 2 & 6 \\
1 & 0 & 1 & 3 \\
1 & 0 & 1 & 1 \\
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0\\
0 & 0 & 1 & 0\\
0 & 0 & 0 & 1
\end{bmatrix}$$
and then do column ops. The result will be a $3 \times 4$ matrix $A$ at the top, and a $4 \times 4$ matrix $Q$ on the bottom with $MQ = A$. If you've done your column-reduction right, three of $A$'s columns will be the standard basis vectors [$(1,0,0), (0,1,0), (0, 0, 1)$] and $Q$ will show one way to express these as linear combinations ($Q$) of the columns of $M$. The remaining column of $A$ will be all zeros, and  the corresponding row of $Q$ will show a way to express $(0,0,0)$ as a combination of columns of $M$. You can add or subtract this from your expression for $(1,0,0)$ as a combination of columns of $M$ to get a NEW way to express it as a combination of columns, showing that the solution to the problem is not unique.
Comment: Added details on why the approach you took is wrong, as well as why you should expect no unique answer.


Power calculation for disease modeling in iPS cells

Question: I apologize in advance if the question is rather simple, but I have been having a difficult time figuring it out.
I am an experimental scientist interested in modeling human disease with induced pluripotent stem cells. The disease is fairly common, but doesn't have a common genetic basis. It is mainly driven by rare genetic variants of high penetrance but in a small number of individuals.
For (let's say) 5 patients out of 1000 screened affected cases, we are able to strongly associate mutations in one gene with the condition. These mutations are completely absent from  a control population of 5000 individuals.
We have made stem cells from 2 of those individuals to determine whether these mutations result in cellular dysfunction (let's call this phenotype A) when compared to controls. We have several stem cell lines per individual. In this situation, phenotype A is an 'intermediate phenotype'.
The big conceptual question for me is this: Am I modeling the disease or am I only modeling the effect of the disease-associated mutations on cellular function? How can I determine the sample size to test the former claim with, say, 80% power?
Answer: You can already see the Wikipedia article on power calculations, so I won't repeat it here.
Let's take the parameters you probably already know:

You already have the base rate - the rate at which the disease will
occur in a population that doesn't have this particular mutation.
You've got a beta value (you want an 80% chance of not making a type
II error / missing a real effect)

Before you can arrive at your value for n, you still need to choose:

The rate at which you expect the disease to occur in a sample population which has the mutation
The variance that you expect that rate to have - so, you are characterising your sample mean and sample variance, for the population with the mutation, given that your hypothesis is true.

Visualise what you are doing as picking  sufficiently large value for n that the curves describing the mutation-free, low-disease rate population and the mutation-bearing high-disease rate populations don't overlap much (the overlap is where your Type II error would happen - a mutation-effect-mean that happened to fall too far inside the general population's distribution).
If your variance happens to be small (you mention a high penetrance), that helps a lot - your sample size can be surprising small, if the distribution in the "effect" population is really tight.
Does this help?


Weird denominator degrees of freedom in SAS glimmix

Question: I´m trying to learn generalized mixed models in SAS and I have now bumbed into a situation that I cannot figure out by myself. So I was thinking that maybe some of you could help me forward.
I´m running a model where I have normally distributed measurements of traits like tarsus etc in birds from different populations. I have few fixed factors (sampling area, sex and year) and their interactions in the model and random term "sampling site clustered within the sampling area" (2 sampling areas with both 2 sampling sites). I´m using SATTERTH as a method for computing the denominator degrees of freedom.
My problem is that for one particular trait I get really low degrees of freedom always when the sampling site is in the model, and for that particular factor. I noticed that playing around with the methods of computing the degrees of freedom, I can get "better" results, but I cannot understand why in this model, one fixed factor eats up my degrees of freedom.
If anyone can and would like to explain to me why this happens and how I should select the method for computing the DDF´s in "dummies" way, it would make my day. I'm happy to provide you with more information, I was not certain how I should present my problem.
Thank you in advance.
Comment: Are you saying that, in some of your models, you have sampling site as both part of the random term and as a fixed effect? I'm not sure that makes much sense, and might conceivably cause problems..
Comment: The sampling sites are not independent within their research area. Thats why I have clustered sites within the area. (I corrected this to the original question just, i had it wrong there) So im estimating the effect of sampling area as fixed effect and the sampling site within an area as random term.
Answer: The t distribution by Satterwaite is an approximation to the distribution of a t-like statistic when the two variances are unequal and estimated separately. This is the so-called Behren's-Fisher problem.  The distribution under the null hypothesis is not a t distribution but it has been found that it can be well approximated by a t with a fractional number for the degrees of freedom parameter.  There is a special formula for the degrees of freedom in the approximation.  You could look this up but here is a link to Wikipedia:
http://en.wikipedia.org/wiki/Behrens%E2%80%93Fisher_problem.
Comment: Thank you for this Michael! Have you ever encountered a situation where Satterwaite approximation would behave like it does in my case and what could be the reason for this?
Comment: I haven't done much with Satterwaite in linear models with unequal variances.  I think if you look at the formula for degrees of freedom it will probably start making sense.
Answer: This could be an interplay of several factors: variances within the ultimate cluster (site X sampling area, as far as I can tell from your post), and/or concentration of the response within relatively few clusters. Satterthwaite approximations tend to be drawn towards the larger variances. In the worst case scenario of having the largest variance associated with the smallest cluster (e.g., due to an outlier in it), if you have say sites with 10, 15, 25 and 50 observations, and the variances happen to be 50, 10, 14 and 9, then you will end up with 11 degrees of freedom overall (I am making the numbers up, of course, but that's how it may play out, in the end).