How connect nhibernate to local SQLEXPRESS?

Question: I have in project simple connection to database:
public static string GetConnectionString()
        {
            return @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + HttpContext.Current.Request.PhysicalApplicationPath + "Application.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
        }

Now I try to implement NHibernate to project.
hibernate.cfg.xml here:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle</property>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
    <property name="connection.connection_string">Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\1\Desktop\Application+\Application\Application.mdf;Integrated Security=True;User Instance=True</property>
    <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

Test class "Clients" object here:
    public class Clients
    {
        private Guid id;
        private string name;
        private string phone;
        private string fax;
        private string email;
        private string address;
        private string contactPerson;

        public virtual Guid Id
        {
            get { return id; }
            set { id = value; }
        }

        public virtual string Phone
        {
            get { return phone; }
            set { phone = value; }
        }

        public virtual string Fax
        {
            get { return fax; }
            set { fax = value; }
        }

        public virtual string Email
        {
            get { return email; }
            set { email = value; }
        }

        public virtual string Address
        {
            get { return address; }
            set { address = value; }
        }

        public virtual string ContactPerson
        {
            get { return contactPerson; }
            set { contactPerson = value; }
        }

        public virtual string Name
        {
            get { return name; }
            set { name = value; }
        }
    }

Clients.hbm.xml here:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="WrapperObjects" namespace="WrapperObjects">
  <class name="Clients" table="Clients" lazy="false">
    <id name="Id" column="id">
      <generator class="native"></generator>
    </id>
    <property name="Name" column="name" type="System.String"/>
    <property name="Phone" column="phone" type="System.String"/>
    <property name="Fax" column="fax" type="System.String"/>
    <property name="Email" column="email" type="System.String"/>
    <property name="Address" column="address" type="System.String"/>
    <property name="ContactPerson" column="contactPerson" type="System.String"/>
  </class>
</hibernate-mapping>

I used it like this:
public static void Configure()
        {
            sessions = new Configuration().Configure().AddClass(typeof(Clients)).BuildSessionFactory();
        }

        public static void Insert(Clients pb)
        {
            using (ISession session = sessions.OpenSession())
            using (ITransaction tx = session.BeginTransaction())
            {
                session.Save(pb);
                tx.Commit();
            }
        }

On Configure() method appears an error: Keyword not supported.Parameter name: attachdbfilename
How fix??))
Answer: <?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle</property>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
    <property name="connection.connection_string">Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\1\Desktop\Application+\Application\Application.mdf;Integrated Security=True;User Instance=True</property>
    <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

Notice you are using the NHibernate.Driver.MySqlDataDriver driver_class and NHibernate.Dialect.MySQL5Dialect dialect, you need to change it to:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle</property>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\1\Desktop\Application+\Application\Application.mdf;Integrated Security=True;User Instance=True</property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

I assumed you are using MSSQL 2008, change to NHibernate.Dialect.MsSql2005Dialect if you are using 2005
https://community.jboss.org/wiki/DatabasesSupportedByNHibernate?_sscc=t
Answer: have you tried a connection string without User Instance
http://social.msdn.microsoft.com/Forums/en/sqldataaccess/thread/60889070-5c3c-4823-ae9f-1ed6e32b2ce8
example:
Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;

source: http://www.connectionstrings.com/sql-server-2005
To use the User Instance functionality you need to enable it on the SQL Server. This is done by executing the following command: sp_configure 'user instances enabled', '1'.
since the path may be absolute or relative, you can also try:
Data Source=.\SQLEXPRESS;AttachDbFilename=Application.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True

or
Data Source=.\SQLEXPRESS;AttachDbFilename=Application.mdf;Integrated Security=True;Connect Timeout=30

Answer: You are using the MySqlDataDriver as your connection.driver_class in your NH config. Set it to NHibernate.Driver.SqlClientDriver instead.
Likewise, set the dialect to NHibernate.Dialect.MsSql2008Dialect


While nao valida ultimo array php

Question: Alguem sabe porque o button do último registro do while nao executa a action do formulario?
<?php
 while($dados_tabela = $consulta_tabela -> fetchObject()) {
?>

    <?php echo $dados_tabela->id; ?>
    <?php echo $dados_tabela->nome; ?>
    <?php echo $dados_tabela->usuario; ?>
    <?php echo $dados_tabela->senha; ?>
    <?php echo $dados_tabela->email; ?>

            <form name="editar_usuario" action="../php/editar_usuario.php" method="post">
              <input type="hidden" name="id_editar" value="<?php echo $dados_tabela->id; ?>" />
              <button type="submit" class="btn btn-default btn-xs"></button>
            </form>

            <form name="excluir_usuario" action="../php/excluir_usuario.php" method="post">
              <input type="hidden" name="id_excluir" value="<?php echo $dados_tabela->id; ?>" />
              <button type="submit" class="btn btn-default btn-xs"></button>
            </form>

<?php
}
?>

Comment: Tem como colocar a parte do código da query, e a saída de um `print_r( $consulta_tabela );` para avaliarmos? À propósito, não relacionado com a pergunta, mas dá pra dar uma boa enxugada nesse seu HTML depois, reorganizando a tabela de fora. Um bom teste é ver se não tem nenhum outro elemento da página com z-index maior que o botão desejado, coisa que não dá pra analisar só olhando seu código.
Comment: Você não pode colocar o mesmo formulário dentro de um laço, coloque o nome do formulário e a id do form, como uma variável da chave, concatenando com os nomes.
Comment: Ivan, na verdade até "pode", mas é completamente NÃO recomendado por inumeros problemas haha
Comment: Pode só que ele sempre vai sobrescrever a informação.
Comment: @IvanFerrer , poderia me passar como ficaria essa alteração?
Comment: Porque não utiliza `foreach`?
Comment: Vou apresentar uma solução melhor, evitando esse loop de forms... pq isso realmente não é uma boa prática.
Comment: @IvanFerrer obrigado pela solução via javascript porem agora nao funcionou nenhum. eu nao queria passar por $_GET para nao ficar visivel na URL mas vou tentar chamar o $_GET na url de um iframe ou pelo include mas nao vem uma ideia de como implementar
Comment: eu editei, tinha uma variável a mais "form". que na verdade era o nome do form.
Comment: E retire os names excluir_usuario e editar_usuario dos forms, não tem serventia nesse caso, e gera nomes repetidos.
Comment: O problema de fazer isso: quando você envia a requisição post, o documento HTML procura o cabeçalho do , cada form é um array e cada elemento do form é um outro array... se você coloca o mesmo nome, é o mesmo que pegar sempre a mesma chave do array, ele irá procurar o atributo desse array e não irá encontrar porque ficou em outro form de mesma chave. E ele não faz essa distinção e nem essa mesclagem.
Comment: exatamente @IvanFerrer acho que vou colocar nome do form concatenado com o id da linha recuperada na consulta para assim nao ficar o mesmo nome do form em todas as linhas.
Comment: fiz o que disse mas sem sucesso tambem. no caso em cada linha ficaria um form com name diferente. sem sucesso
Answer: Seu problema pode ser resolvido desta maneira, coloque junto a biblioteca do jquery:
    <?php

     $url_editar = '../php/editar_usuario.php';
     $url_excluir = '../php/excluir_usuario.php';

     while ($dados_tabela = $consulta_tabela -> fetchObject()) {
      ?>

        <?php echo $dados_tabela->id; ?>
        <?php echo $dados_tabela->nome; ?>
        <?php echo $dados_tabela->usuario; ?>
        <?php echo $dados_tabela->senha; ?>
        <?php echo $dados_tabela->email; ?>

                <button type="button" id="editar_<?php echo $dados_tabela->id; ?>" class="btn btn-default btn-xs btn-edit" data-id="<?php echo $dados_tabela->id; ?>"></button>

               <button type="button" id="excluir_<?php echo $dados_tabela->id; ?>" class="btn btn-default btn-xs btn-delete" data-id="<?php echo $dados_tabela->id; ?>"></button>

      <?php
    }
    ?>
<form name="editar_usuario" action="<?php echo $url_editar?>" method="post">
 <input type="hidden" id="id_editar" name="id_editar" value="" />
</form>
<form name="excluir_usuario" action="<?php echo $url_excluir?>" method="post">
 <input type="hidden" id="id_excluir" name="id_excluir" value="" />
</form>

Comment: Continua a não funcionar o ultimo button conforme imagem do link http://www.prestoexpress.com.br/erro.jpg
Comment: Ele esta pegando o click pela classe do botao?
Comment: Não exatamente, quando clicar no botão, ele executa uma função que captura os dados contidos nesse botão e envia para o formulário, e depois o submete, fora do loop, isso não é ajax.
Comment: Ajax seria um procedimento de requisição.
Comment: Porque negativou a pergunta, explique o problema.
Comment: Nao entendi @Ivan, nao negativei, alias sou meio novato por aqui ainda aprendendo as regras. esta melhorando o codigo com as alterações que voce citou
Comment: Alguém anda negativando de bobagem por aí
Comment: Já dei UP na sua resposta.
Answer: Penso que seria melhor se você fizesse dessa forma, pois repetir o <form> para cada registro não é uma boa prática.

<?php
 while($dados_tabela = $consulta_tabela -> fetchObject()) {

  ?>

    <?php echo $dados_tabela->id; ?>
    <?php echo $dados_tabela->nome; ?>
    <?php echo $dados_tabela->usuario; ?>
    <?php echo $dados_tabela->senha; ?>
    <?php echo $dados_tabela->email; ?>

            <a href="../php/excluir_usuario.php?id_editar=<?php echo $dados_tabela->id; ?>">Editar

            <a href="../php/excluir_usuario.php?id_excluir=<?php echo $dados_tabela->id; ?>">Excluir

  <?php
}
?>
Comment: Pois é... eu queria evitar o $_GET ... mas acho que seria a única solução de momento
Comment: Entendo... Uma outra alternativa é fazer via JS, não rola?
Comment: Pensei em colocar o $_GET em um iframe sendo assim nao fica visivel na URL ... mas ainda estou pensando em como fazer essa jogada ou ainda em um include . aff
Comment: Algum motivo para não fazer via Ajax?
Comment: Nenhum motivo Ademilson, so que estou pensando em como criar essa função e como chamar ela da outra pagina.
Comment: A melhor maneira seria fazer uma implementação ajax. Com certeza. usando `$.post('request.php', {id:id, acao:'excluir'}, function(e){ var rtn =  $.parseJSON(e);  console.log(s.msg) })` tipo isso ou `$.ajax({...});`
Comment: boa @IvanFerrer nao tinha pensado. pensei em passar por session o que vc acha? na verdade eu queria evitar javascript e $_GET
Comment: @EzequielTavares você pode usar JavaScript e enviar via post com ajax ;)
Ajax resolveria vários problemas como por exemplo o "atualizar" desnecessário da página no caso do "deletar"...

While nao valida ultimo array php


Data preparation (preprocessing and data cleaning) before or after train-test split with scikit learn?

Question: I have been practicing Data Science/Machine Learning, and I am confused about when to complete the following tasks when using train-test split in scikit learn:

EDA
Filling in missing data
Removing data that isn't needed
Working with categorical data
Feature Engineering
Feature Selection

I know that scaling should be done after train-test split. However, I have seen both approaches (train-test split before and after) when working with the above tasks.
I'm confused about which is the correct way for these tasks.
Can someone provide some clarification?
Thank you!
Comment: This is a very broad question and implies that there is a recipe to follow. Instead it might be more interesting to learn about the danger of data leakage: [How to choose the mean and std when using KFold cross validation?](https://stats.stackexchange.com/questions/545853/how-to-choose-the-mean-and-std-when-using-kfold-cross-validation), [Avoiding data leakage in preprocessing](https://stats.stackexchange.com/questions/521188/avoiding-data-leakage-in-preprocessing), [Must we do feature selection in cross validation?](https://stats.stackexchange.com/q/546396/237901)
Answer:
Test set is supposed to be untouched until the final stage: test data insights should not affect our decisions since it simulates the data from the production stage. However, if we split it ourselves, we assume the distributions having no significant differences, so exploring the full data is not technically a mistake.
Filling with a constant should create no leakage. Strategies like filling with mean values result in a leakage (albeit a minor one, if it's a school project, reviewers are known to often turn a blind eye on that).
Depends on the usability criterion. If it's truly, absolutely never going to serve as a model input, there is no difference. Dropping outliers before splitting is somewhat cheating, since that excludes the hard to predict samples from the test, - we should only do this if we expect the real input data to be filtered the same way.
Depends on the encoding strategy. OHE shouldn't result in a leakage, target encoding would make a huge leak if done before splitting.
If we operate within a single observation (like, adding two features' ratio), there's no leak. If it's based on other observations somehow, it's a minor leak. If it considers target too (e.g. SymbolicTransformer()), it's a major leak.
Once again, if we assume the distributions to be roughly the same, stats like mutual information or variance inflation factor should also remain roughly the same. Generally, I'd stick to selection using the train set just to be sure.

TL;DR: when in doubt, don't touch the test set until your best model is ready to be tested.


How to show that $\mathfrak{sl}_n(\mathbb{R})$ and $\mathfrak{sl}_n(\mathbb{C})$ are simple?

Question: We defined a Lie algebra to be simple, if it has no proper Lie ideals and is not $k$ (the ground field). We have the proposition that $\mathfrak{sl}_n(\mathbb{R})$ and $\mathfrak{sl}_n(\mathbb{C})$ are simple $\mathbb{R}$-Lie algebras, and $\mathfrak{sl}_n(\mathbb{C})$ is also simple as a $\mathbb{C}$-Lie algebra. We have shown the proposition for the case $n=2$ using an $\mathfrak{sl}_2$-triple.
How would I show the statement for general $n \in \mathbb{N}$?
I suspect there's a way to use induction, but don't see how that would work. Also, I have no idea how I would generalize and apply the idea with the $\mathfrak{sl}_2$-triple to higher dimensions. I can't even just do the case $n=3$. How do I generalize?
Comment: @darijgrinberg Unfortunately the links says "access forbidden!".
Comment: A link has been provided on a duplicate thread: https://www.math.cuhk.edu.hk/~plyung/simplicity_sln.pdf
Comment: @DietrichBurde Make it http://web.archive.org/web/20210507034553/https://www.math.cuhk.edu.hk/~plyung/simplicity_sln.pdf then.
Comment: @darijgrinberg Indeed, there it is - thank you!
Answer: There is a direct proof that $\mathfrak{sl}(n,K)$ is a simple Lie algebra for any field $K$ of characteristic zero, which just uses Lie brackets of traceless matrices to show that a nontrivial ideal $J$ must be $\mathfrak{sl}(n,K)$ itself, see 6.4 in the book "Naive Lie Theory". This works uniformly for all $n\ge 2$. For a proof using a bit more theory, see Lemma $1.3$ here.
Comment: Thank you very much for the references. I looked up the elementary proof and it is rather straight-forward. I am a bit confused though: We never really make use of bilinearity (over $K$) of the Lie bracket. Does this mean the proof given in "Naive Lie Theory" works for $\mathfrak{sl}_n(\mathbb{C})$ as both $\mathbb{R}$- and $\mathbb{C}$-Lie algebra?
Comment: For this question see "real forms", or "complexification" and "realification" of simple Lie algebras, see $22.214.171.124$ [here](https://www.google.at/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0ahUKEwjRvdG9oJDKAhWKOhQKHZj0AmAQFggjMAE&url=https%3A%2F%2Fwww.itp.uni-hannover.de%2F~giulini%2Fpapers%2FLieRep.pdf&usg=AFQjCNFQZAyKRK6Vw6XDjX05Pz_IoEiPzQ&sig2=mW-279Duz_Ji3pxsxadR9g&bvm=bv.110151844,d.d24). You do not need an extra proof for $\mathbb{sl}(n)$, this follows from general principles.
Comment: I'll have a look at your reference as soon as possible. What exactly do you mean by $\mathbb{sl}(n)$? Thanks a lot!
Comment: @user302234 It means $\mathfrak{sl}_n(K)$, see the last link. Did you had time to look at the reference in the meantime?


Mutual exclusive classes for deciding Softmax Regression vs. k Binary Classifiers

Question: I realize that a similar question is asked here also, but my concern is related to the last section of this article from Stanford
It says the decision will depend on mutual exclusivity of classes and if they are mutually exclusive then prefer softmax else k binary classifiers.
Can anyone provide any rigorous explanation for that statement directly relating the criteria of mutual exclusivity of classes to the performance of the algorithm, because that article only has given just one line explanation :
"This way, for each new musical piece(each class), your algorithm can separately decide whether it falls into each of the four categories."
Comment: softmax produces a probability distribution vector: sum of its elements is 1 (i.e., it may confidently predict only a single category).  This is a poor choice when you want a single example assigned multiple labels.
Comment: @Dave for an MLP type network, if you showed a network trained on digits a picture of a dog, there is no guarantee that it will say that doesn't belong to any of the categories because the decision boundaries are not closed.  It could just as well confidently predict that it is one of the digits because none of the outputs have been discriminatively trained with pictures of a dog.  It would be free to extrapolate away from the digits data in any way that was "convenient".  I think the advantage of the softmax is just efficiency, where the modelling assumptions are correct.
Comment: (Bounty message part 1) I think the core of the question is why to model with softmax at all, instead of going for multi-label ($k$ binary models). That is, why not model the MNIST digits as ten binary classifiers—Is it zero? Is it one? Is it seven?—so that if you show the network a picture of a [boot](https://www.tensorflow.org/datasets/catalog/fashion_mnist), the network can come back and say that the boot does not belong to any of the MNIST digit categories?
Comment: (Bounty message part 2) It's clear why softmax is inappropriate when multiple categories can occur simultaneously and we want a model to be able to give 0.9 probability of a dog being in a photo and also 0.9 probability of a human being in that same photo (people take photos with their dogs all the time), as softmax regression would require the probabilities to sum to one.
Comment: (Bounty message part 3) However, it is not clear why a multi-label approach would be so problematic when the labels are mutually exclusive, and Harrell's comment [here](https://stats.stackexchange.com/questions/108236/softmax-regression-or-k-binary-logistic-regression/147624#147624) makes it sound reasonable.
Answer: One reason to prefer softmax is that it may be more efficient in terms of modelling resources, such as hidden units in a multilayer perceptron network.  This is because it enforces a constraint that all of the probabilities must sum to one "for free" rather than this having to be modelled/learned by the network.  The optimal solution of the cross-entropy loss, for multiple exclusive classes, requires this constraint to be met, so it is better if you can get it for free.  It also means that if you have a hidden unit that encodes "class A is common in this area of the attribute space", it will automatically inhibit the outputs corresponding to the other classes, again without consuming modelling resources.
I learned this while trying to construct some simple networks (with only one input) for illustrating how neural networks learn.  Using softmax outputs I found it was more difficult to construct "pathological" examples for use in teaching.
Comment: @Dave in that case I would have a "not a number" class and still use the softmax activation function (or use some form of novelty detector to pre-screen the images actually presented to the CNN).
Comment: Interesting discussion, as usual. +100
Comment: It makes sense that forcing the probabilities to add up to one instead of letting the model figure it out would ease the job the model has to do. However, I question if we should demand that the probabilities add up to one. Especially in my MNIST example in the bounty message (which I'll concede is not part of the original question), I don't want to show my MNIST CNN a picture of a boot and have it come back with something like `[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]`. I would like all of those to be just about zero. +1 nonetheless.
Comment: I'm not sure that a set of k binary classifiers, given sufficient resources, would necessarily give a different output to the softmax case if the classes are mutually exclusive in the training set.  In both cases the training criterion is optimised by the model(s) outputting the true probability of class membership, so if they differ it is only in the way they fail to be optimal for the problem as stated.  Another approach would be to have a "reject" option if the probabilities of the classes were essentially the same.
Answer: One reason to prefer k binary classifiers is that this can be used for Multi-Label classification.
Here your likelihood function reads like this:
$L=\prod_{i=1}^n (\prod_k (\prod_{j_k}(p_{k,j_k}(x_i)^{\delta_{y_{i,k},j_k}})))
$
where index $i$ runs over the samples, index $k$ runs over the labels, $j_k$ indicates the binary outcomes 0 or 1, $\delta_{a,b}$ indicates the Kronecker delta,$y_{i,k}\in {0,1}$ indicates the multiple hot encoded labels of sample $i$, see https://en.m.wikipedia.org/wiki/Multi-label_classification
For multi class classification there may only be one class assigned and the likelihood is
$L = \prod_{i=1}^n P(Y_i=y_i) = \prod_{i=1}^n \left( \prod_{k=1}^K P(Y_i=k)^{\delta_{k,y_i}} \right)$, compare https://en.m.wikipedia.org/wiki/Multinomial_logistic_regression.
Multilabel classification is (in a sense) a generalization of the multiclass classification.
If you already know that classes are exclusive then the multi-label setting would allow you for too much flexibility (the event takes place either in city A or in city B - but not both). A multi label model might output (0.7,0.8) while a multi-class model would have to trade off, outputting (0.3, 0.7) due to the constraint of class exclusivity and normalization of the output.
PS: in a neural net for multi class classification the last activation function would typically be a softmax (which makes sure that the predicted class probabilities sum up to 1 for each sample). For the binary classification setting, you could simply change that to an (elementwise) sigmoid function.
Comment: I think the point is why we would ever not go with the multi-label model. At least to me, there is an obvious advantage to the multi-label approach. What, if anything, is the drawback?
Comment: I commented in my answer
Comment: Please also note that there is alternatives to softmax, like e.g. entmax, also providing normalized outputs summing to 1. These alternatives tend to focus the probability weight more - it has sparser output structure
Comment: Sure, there are alternatives to softmax, but they all have the same theme of forcing the probabilities to sum to one because the categories are mutually exclusive. At least for the bounty (and I think this was the spirit of the original question, which I concede is not my question), what would be the advantage of forcing the probabilities to sum to one instead of letting them be whatever? $70\%$ chance of `dog` and 80\%$ chance of `human`? Why not? If you get a calibrated model with mutually exclusive outcome categories, this seems like it would be impossible.


Wordpress plugin shortscodes in other plugins?

Question: I'm developing a plugin that creates custom wordpress pages, however I ran into a problem when trying to get shortcodes from other plugins to integrate into my plugin, well more like I couldn't find any info on it.
For example if someone uses my custom page builder and adds a short code [gallery] that is associated with an enabled plugin, I want the shortcode to do it's thing.
Could anyone point me in the right direction for this?
Comment: I think this previous topic would help:

http://stackoverflow.com/questions/9820190/enable-shortcodes-in-a-wordpress-theme
Answer: Try wordpress
http://wordpress.org/plugins/synved-shortcodes/
while this plugin let's you integrate shortcodes on every wordpress page , I suppose that you issue is with wordpress functions.php file where you can have a look at , with this plugin installed !
Comment: Thank you for giving me a helping hand !
Comment: There is a high probability that this answer might attract downvotes because of being a _link-only-answer_. You should add some additional info (explanation, usage, issues, etc). And welcome to SO!
Answer: You can check if a shortcode exist before printing it with the function shortcode_exists() (https://codex.wordpress.org/Function_Reference/shortcode_exists)
Example:
<?php
if ( shortcode_exists( 'gallery' ) ) {
    // The [gallery] short code exists.
}
?>

Then, if it exist and you want to print that shortcode with PHP code you should use do_shortcode() function (https://developer.wordpress.org/reference/functions/do_shortcode/)
Example:
<?php echo do_shortcode('[gallery]); ?>

Answer: Always use in WordPress's in-built

the_content

hook to print your custom page content.
WordPress by default process all shortcodes before outputting any stuff from this hook.
More info can be found here: https://codex.wordpress.org/Function_Reference/the_content


SQL join(INNER JOIN )

Question: This part requires you to write a simple inner join of several tables.
Write a SQL statement that returns a data set with all airports in London. The data set must contain, for each airport, the name of the city, the country, the airport code and its latitude and longi-tude
My answer here:
       SELECT  City.name, Country.name, Airport.code, Airport.latitude,
               Airport.longtitude
       FROM City, Airport, Country
          WHERE Country.id = City.Country
          AND   Airport.city = City.id
          AND   City.name = "London"

Am I right? Do I need to write the keywords like "INNER JOIN" or "ON" on my code?
Comment: can u explain your table structure?
Comment: Sorry. Table  Airport have PRIMARY KEY (id),
     FOREIGN KEY (city) REFERENCES City (id)                              Table City have    PRIMARY KEY (id),
  UNIQUE INDEX (name, country),
   FOREIGN KEY (country) REFERENCES Country (id)                           Table Country have PRIMARY KEY (id),
Answer: This is ok.
SELECT City.name, Country.name, Airport.code, Airport.latitude, Airport.longtitude
FROM City, Airport, Country
WHERE
    Country.id = City.Country
AND Airport.city = City.id
AND City.name = "London"

But can also be write like this
SELECT City.name, Country.name, Airport.code, Airport.latitude, Airport.longtitude
FROM
    City
    inner join Country ON Country.id = City.Country
    inner join Airport ON Airport.city = City.id
WHERE
    City.name = "London"

Answer: Given that the question asks for a 'a simple inner join', then yes, you'll need to use those keywords! INNER JOIN is used to link tables that have matching columns. For example, if one table contains details about a city, another table can refer to it via its ID column, and a query using INNER JOIN can retrieve details from both. If the city details change, they only need to be changed in one table.
In your example, the query would look something like this:
SELECT
    c.name,
    cty.name,
    ap.code,
    ap.latitude,
    ap.longtitude
FROM
    Airport ap
    INNER JOIN City c ON ap.city = c.id
    INNER JOIN Country cty ON c.Country = cty.id
WHERE
    c.name = "London"

Answer:        SELECT  City.name, Country.name, Airport.code, Airport.latitude,
               Airport.longtitude

       from Airport
            inner join city on Airport.city = City.id
            inner join Country ON Country.id = City.Country
       where
            city.name='London'

SQL join(INNER JOIN )


Recording Stereo With U-Phoria UM2

Question: I record my Clavinova CLP-360 with a Behringer UM2 interface. However, I can only record in mono using only one of the inputs on the interface. Would I be able to record in stereo if I connected separate L/R inputs into the two on the interface? My only worry is that since (on the interface) one, I think, is specially made for low-level inputs. Would that affect it, other than volume?
Also, on a less important note, IF all goes well and I record in stereo, could I hear stereo through the live monitor output on the interface?
Thanks!
Answer: You COULD do it if it's the only option. Use a DI box for the mic/Line input and then adjust the input gains to preference.
You will not be able to hear stereo from the direct monitor setting.
Comment: @Galaxy the DI box is for matching the impedance of the XLR input. It may work without it but not as well. http://whirlwindusa.com/support/tech-articles/direct-box-can-be-di-spensible/
Comment: Ok. Could you clarify the function of the DI Box? I use the two interface inputs interchangeably (signal coming from the 1/4" headphone jack output) with no problems. I of course always have the mic +48v switched off (its an option on the back of the interface). Seems to work fine all the time.

Recording Stereo With U-Phoria UM2


What to do when CFA fit for multi-item scale is bad?

Question: I am not sure how to proceed with this CFA im doing in lavaan. I have a sample of 172 participants (I know that's not much for a CFA) and 28 items with 7-point Likert scales that should load on seven factors. I did a CFA with "mlm"-estimators, but the model fit was really bad (χ2(df=329)=739.36; comparative fit index (CFI)= .69; standardized root mean square residual (SRMR)=.10; root mean square error of approximation (RMSEA)=.09; RMSEA 90% confidence interval (CI) = [.08, .10]).
I have tried the following:

bifactor model with one general method factor —> did not converge.
estimators for ordinal data ("WLSMV") —> Model fit: (χ2(df=329)=462; comparative fit index (CFI)= .81; standardized root mean square residual (SRMR)=.09; root mean square error of approximation (RMSEA)=.05; RMSEA 90% confidence interval (CI) = [.04, .06])
reducing the model by items that load low on a factor and add covariances among specific items --> Model fit: χ2(df=210)=295; comparative fit index (CFI)= .86; standardized root mean square residual (SRMR)=.08; root mean square error of approximation (RMSEA)=.07; RMSEA 90% confidence interval (CI) = [.06, .08].

Now my questions:

What should I do with such a model?
What would be statistically correct to do?
Report that it does fit or that it does not fit? And which of those models?

I'd be glad to have a discussion with you about this.
Here is the lavaan output of the CFA of the original model:
    lavaan (0.5-17.703) converged normally after  55 iterations

                                              Used       Total
  Number of observations                           149         172

  Estimator                                         ML      Robust
  Minimum Function Test Statistic              985.603     677.713
  Degrees of freedom                               329         329
  P-value (Chi-square)                           0.000       0.000
  Scaling correction factor                                  1.454
    for the Satorra-Bentler correction

Model test baseline model:

  Minimum Function Test Statistic             2461.549    1736.690
  Degrees of freedom                               378         378
  P-value                                        0.000       0.000

User model versus baseline model:

  Comparative Fit Index (CFI)                    0.685       0.743
  Tucker-Lewis Index (TLI)                       0.638       0.705

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -6460.004   -6460.004
  Loglikelihood unrestricted model (H1)      -5967.202   -5967.202

  Number of free parameters                        105         105
  Akaike (AIC)                               13130.007   13130.007
  Bayesian (BIC)                             13445.421   13445.421
  Sample-size adjusted Bayesian (BIC)        13113.126   13113.126

Root Mean Square Error of Approximation:

  RMSEA                                          0.116       0.084
  90 Percent Confidence Interval          0.107  0.124       0.077  0.092
  P-value RMSEA <= 0.05                          0.000       0.000

Standardized Root Mean Square Residual:

  SRMR                                           0.096       0.096

Parameter estimates:

  Information                                 Expected
  Standard Errors                           Robust.sem

                   Estimate  Std.err  Z-value  P(>|z|)   Std.lv  Std.all
Latent variables:
  IC =~
    PTRI_1r           1.000                               1.093    0.691
    PTRI_7            1.058    0.118    8.938    0.000    1.156    0.828
    PTRI_21           0.681    0.142    4.793    0.000    0.744    0.582
    PTRI_22           0.752    0.140    5.355    0.000    0.821    0.646
  IG =~
    PTRI_10           1.000                               0.913    0.600
    PTRI_11r          0.613    0.152    4.029    0.000    0.559    0.389
    PTRI_19           1.113    0.177    6.308    0.000    1.016    0.737
    PTRI_24           0.842    0.144    5.854    0.000    0.769    0.726
  DM =~
    PTRI_15r          1.000                               0.963    0.673
    PTRI_16           0.892    0.118    7.547    0.000    0.859    0.660
    PTRI_23           0.844    0.145    5.817    0.000    0.813    0.556
    PTRI_26           1.288    0.137    9.400    0.000    1.240    0.887
  IM =~
    PTRI_13           1.000                               0.685    0.609
    PTRI_14           1.401    0.218    6.421    0.000    0.960    0.814
    PTRI_18           0.931    0.204    4.573    0.000    0.638    0.604
    PTRI_20r          1.427    0.259    5.514    0.000    0.978    0.674
  IN =~
    PTRI_2            1.000                               0.839    0.612
    PTRI_6            1.286    0.180    7.160    0.000    1.080    0.744
    PTRI_12           1.031    0.183    5.644    0.000    0.866    0.523
    PTRI_17r          1.011    0.208    4.872    0.000    0.849    0.613
  EN =~
    PTRI_3            1.000                               0.888    0.687
    PTRI_8            1.136    0.146    7.781    0.000    1.008    0.726
    PTRI_25           0.912    0.179    5.088    0.000    0.810    0.620
    PTRI_27r          1.143    0.180    6.362    0.000    1.015    0.669
  RM =~
    PTRI_4r           1.000                               1.114    0.700
    PTRI_9            0.998    0.105    9.493    0.000    1.112    0.786
    PTRI_28           0.528    0.120    4.403    0.000    0.588    0.443
    PTRI_5            0.452    0.149    3.037    0.002    0.504    0.408

Covariances:
  IC ~~
    IG                0.370    0.122    3.030    0.002    0.371    0.371
    DM                0.642    0.157    4.075    0.000    0.610    0.610
    IM                0.510    0.154    3.308    0.001    0.681    0.681
    IN                0.756    0.169    4.483    0.000    0.824    0.824
    EN                0.839    0.169    4.979    0.000    0.865    0.865
    RM                0.644    0.185    3.479    0.001    0.529    0.529
  IG ~~
    DM                0.380    0.103    3.684    0.000    0.433    0.433
    IM                0.313    0.096    3.248    0.001    0.501    0.501
    IN                0.329    0.107    3.073    0.002    0.429    0.429
    EN                0.369    0.100    3.673    0.000    0.455    0.455
    RM                0.289    0.116    2.495    0.013    0.284    0.284
  DM ~~
    IM                0.530    0.120    4.404    0.000    0.804    0.804
    IN                0.590    0.122    4.839    0.000    0.731    0.731
    EN                0.588    0.105    5.619    0.000    0.688    0.688
    RM                0.403    0.129    3.132    0.002    0.376    0.376
  IM ~~
    IN                0.439    0.126    3.476    0.001    0.763    0.763
    EN                0.498    0.121    4.128    0.000    0.818    0.818
    RM                0.552    0.122    4.526    0.000    0.723    0.723
  IN ~~
    EN                0.735    0.167    4.402    0.000    0.987    0.987
    RM                0.608    0.141    4.328    0.000    0.650    0.650
  EN ~~
    RM                0.716    0.157    4.561    0.000    0.724    0.724

Variances:
    PTRI_1r           1.304    0.272                      1.304    0.522
    PTRI_7            0.613    0.153                      0.613    0.314
    PTRI_21           1.083    0.199                      1.083    0.662
    PTRI_22           0.940    0.141                      0.940    0.582
    PTRI_10           1.483    0.257                      1.483    0.640
    PTRI_11r          1.755    0.318                      1.755    0.849
    PTRI_19           0.868    0.195                      0.868    0.457
    PTRI_24           0.530    0.109                      0.530    0.473
    PTRI_15r          1.121    0.220                      1.121    0.547
    PTRI_16           0.955    0.200                      0.955    0.564
    PTRI_23           1.475    0.219                      1.475    0.691
    PTRI_26           0.417    0.120                      0.417    0.213
    PTRI_13           0.797    0.113                      0.797    0.629
    PTRI_14           0.468    0.117                      0.468    0.337
    PTRI_18           0.709    0.134                      0.709    0.635
    PTRI_20r          1.152    0.223                      1.152    0.546
    PTRI_2            1.178    0.251                      1.178    0.626
    PTRI_6            0.942    0.191                      0.942    0.447
    PTRI_12           1.995    0.235                      1.995    0.727
    PTRI_17r          1.199    0.274                      1.199    0.625
    PTRI_3            0.882    0.179                      0.882    0.528
    PTRI_8            0.910    0.131                      0.910    0.472
    PTRI_25           1.048    0.180                      1.048    0.615
    PTRI_27r          1.273    0.238                      1.273    0.553
    PTRI_4r           1.294    0.242                      1.294    0.510
    PTRI_9            0.763    0.212                      0.763    0.382
    PTRI_28           1.419    0.183                      1.419    0.804
    PTRI_5            1.269    0.259                      1.269    0.833
    IC                1.194    0.270                      1.000    1.000
    IG                0.833    0.220                      1.000    1.000
    DM                0.927    0.181                      1.000    1.000
    IM                0.470    0.153                      1.000    1.000
    IN                0.705    0.202                      1.000    1.000
    EN                0.788    0.177                      1.000    1.000
    RM                1.242    0.257                      1.000    1.000

Comment: I have the impression that the data simply do not conform to the model, e.g., you have some extremely high correlations between the factors. Try to look at a standardized solution to get correlations instead of covariances (and at standardized loadings, too). Maybe you want to collapse some factors? Maybe you want to add a method factor for the reverse-coded items if you have some--that often improves fit considerably.
Comment: I have already tried considering the reverse-coded items with a method factor. Improved the fit, but not by much. I would like to collapse a factor or two, but I'm "bound" to stick with the theoretically postulated 7 factor solution. And even if I do collapse, the fit doesn't improve much.
Answer: 1. Go back to Exploratory Factor Analysis
If you're getting very bad CFA fits, then it's often a sign that you have jumped too quickly to CFA. You should go back to exploratory factor analysis to learn about the structure of your test. If you have a large sample (in your case you don't), then you can split your sample to have an exploratory and a confirmatory sample.

Apply exploratory factor analysis procedures to check whether the theorised number of factors seems reasonable. I'd check the scree plot to see what it suggests. I'd then check the rotated factor loading matrix with the theorised number of factors as well as with one or two more and one or two less factors. You can often see signs of under or over extraction of factors by looking at such factor loading matrices.
Use exploratory factor analysis to identify problematic items. In particular, items loading most on a non-theorised factor, items with large cross-loadings, items that don't load highly on any factor.

The benefits of EFA is that it gives a lot of freedom, so you'll learn a lot more about the structure of the test than you will from only looking at CFA modification indices.
Anyway, hopefully from this process you may have identified a few issues and solutions. For example, you might drop a few items; you might update your theoretical model of how many factors there are and so on.
2. Improve the Confirmatory Factor Analysis Fit
There are many points that could be made here:
CFA on scales with many items per scale often perform poorly by traditional standards. This often leads people (and note I think this response is often unfortunate)  to form item parcels or only use three or four items per scale.  The problem is that typically proposed CFA structures fail to capture the small nuances in the data (e.g., small cross loadings, items within a test that correlate a little more than others, minor nuisance factors). These are amplified with many items per scale.
Here are a few responses to the above situation:

Do exploratory SEM that allows for various small cross-loadings and related terms
Examine modification indices and incorporate some of the largest reasonable modifications; e.g., a few within scale correlated residuals; a few cross-loadings. see modificationindices(fit) in lavaan.
Use item parcelling to reduce the number of observed variables

General comments
So in general, if you're CFA model is really bad, return to EFA to learn more about your scale. Alternatively if your EFA is good, and your CFA just looks a little bad due to well known problems of having many items per scale, then standard CFA approaches as mentioned above are appropriate.
Comment: thanks a lot for your advices. I have already returned to EFA, but with your suggestions I figured out that a lot of items don't load on the factor they should. I am tempted to collapse the model to 5 factors instead of 7 theoretical factors, but my Prof wouldn't agree on that, but that's fine. Sadly, the 7 factor model with 4 items each doesn't work out (no matter what is modified). I will report a reduced CFA (with 7 factors + 1 bifactor, 3 items each), that barely doesn't fit (CFI=.89, RMSEA=.067, SRMR=.069), but it's the best I got.
Comment: p.s. Jeromy, I really like your blog. It has helped me a lot so far and will certainly do so in the future :) Thanks!
Answer: I would work on trying to get the bifactor model to converge. Try adjusting the starting values...this may be a fishy approach though, so bear that in mind and interpret with caution. Read up on the dangers of interpreting models that resist convergence if you want to be truly cautious – I admit I haven't done this much yet myself in my study of SEM, so I suggest doing what you need to do to get the model to converge mostly for your benefit. I don't know that it will be any more suitable for publication, but if it clearly isn't because the bifactor model doesn't fit well either, that might be good for you to know.
Otherwise, it seems like you've done about as much as you can with the data you have. AFAIK (I've been looking deeply into this lately for a methodological project of my own, so please correct me if I'm wrong!!), WLSMV estimation in lavaan uses thresholds from polychoric correlations, which is the best way to get good fit indices out of a CFA of ordinal data. Assuming you've specified your model correctly (or at least optimally), that's about all you can do. Removing items with low loadings and freely estimating inter-item covariances is even going a bit far, but you tried that too.
Your model does not fit well by conventional standards, as you're probably aware. Of course you should not say it fits well when it doesn't. This applies to all sets of fit statistics you report here, unfortunately (I assume you were hoping it would fit). Some of your fit statistics are only fairly poor, not outright bad (the RMSEA = .05 is acceptable), but overall, none of it is good news, and you have a responsibility to be honest about that if you're going to publish these results. I hope you can, FWIW.
Either way, you might consider collecting more data if you can; that could help, depending on what you're after. If your objective is a confirmatory hypothesis test, well, you've "peeked" at your data, and will inflate your error rate if you reuse it in an expanded sample, so unless you can just set this dataset aside and replicate a whole, fresh, larger one, you've got a tough scenario to handle.  If you're mostly interested in estimating parameters and narrowing confidence intervals though, I think it might be reasonable to just pool as much data as you can gather, including any you've already used here. If you can get more data, you may get better fit indices, which would make your parameter estimates more reliable. Hopefully that's good enough.
Comment: Big +1 for @Jeromy's alternative too: go back to EFA. Exploratory bifactor analysis is an option too. There's even a couple articles on exploratory SEM (which he also mentions!) out there that I still need to read...again, these aren't quite CFA in the way you might want, but if your objectives suit these methods, your options might not be exhausted yet after all.
Comment: The bifactor model converges when removing one item. But the fit is still really bad and the factors still correlate highly. I think my options are exhausted after all. However, we are collecting more data to have more reliable estimates. Thanks for your reply!


Where can you serve from the sides in table tennis?

Question: Rule 2.6.4 from the ITTF handbook says:

From the start of service until it is struck, the ball shall be above
the level of the playing surface and behind the server's end line, and
it shall not be hidden from the receiver by the server or his or her
doubles partner or by anything they wear or carry.

I have been told that the ball can't be out wide on either side even if it is behind the server's end line. Is that wrong?  Can you serve from as far out wide as you like?
Comment: @graffe It would seem so to me based on a literal interpretation of the rules, but I don't play the game competitively.
Comment: [Related, but not quite a duplicate?](https://sports.stackexchange.com/questions/16219/in-table-tennis-can-you-serve-from-the-side-of-the-table-provided-the-ball-is-b)
Comment: "2.5.14 The end line shall be regarded as extending indefinitely in both directions" would _seem_ to be fairly clear on this but I don't have an actual source to confirm.
Comment: @PhilipKendall would that mean that you can serve from as far out wide as you like?
Answer: The rules are clear, and there is nothing to prohibit serving from out wide.
However from a practical standpoint there is no reason to want to do so.  Serving from such a wide position will mean that the server finds it difficult/impossible to recover to a good position to be ready for their next shot.
In addition, the further the server is from the table, the more difficult it becomes to control the length and height of the serve.
Comment: Thanks! It can be worth it to serve from 6 inches out wide I think.


Android background hides child view text

Question: I have a simple LinearLayout. When I add the android:background to the LinearLayout, the TextView is no longer visible.
What am I not understanding?
<LinearLayout
   android:id="@+id/LinearLayout01"
   android:layout_width="fill_parent"
   android:layout_height="53px"
   android:background="@drawable/glossy_black_top_bar"
   >

       <TextView android:text="This is the Title"
       android:id="@+id/TextView01"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:gravity="center_vertical"
       android:textColor="#FFFFFF">
       </TextView>
</LinearLayout>

Answer: It seems that LinearLayouts with backgrounds expand wierdly. I just used a Framelayout to create a header. Here's the XML if anyone wants I. It takes an ImageView that points to a NinePatched background and stretches it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

     <ImageView android:id="@+id/ImageView01"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:src="@drawable/glossy_black_top_bar"
         android:layout_alignParentTop="true"
         android:scaleType="fitXY">
     </ImageView>

    <LinearLayout
           android:id="@+id/LinearLayout01"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:orientation="horizontal">

             <TextView android:text="MY HEADER TITLE"
             style="@style/title"
               android:id="@+id/TextView01"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:gravity="center"
               android:layout_gravity="center"
               android:shadowColor="#000000"
               android:shadowRadius=".5"
               android:shadowDx="-.5"
               android:shadowDy="-.5"
               android:paddingTop="5dip">
               </TextView>
    </LinearLayout>
</FrameLayout>

<WebView android:id="@+id/WebView01" android:layout_width="fill_parent" android:layout_height="fill_parent"></WebView>

</LinearLayout>


Ridge, lasso and elastic net

Question: How do ridge, LASSO and elasticnet regularization methods compare? What are their respective advantages and disadvantages? Any good technical paper, or lecture notes would be appreciated as well.
Answer: In The Elements of Statistical Learning book, Hastie et al. provide a very insightful and thorough comparison of these shrinkage techniques. The book is available online (pdf). The comparison is done in section 3.4.3, page 69.
The main difference between Lasso and Ridge is the penalty term they use. Ridge uses $L_2$ penalty term which limits the size of the coefficient vector. Lasso uses $L_1$ penalty which imposes sparsity among the coefficients and thus, makes the fitted model more interpretable. Elasticnet is introduced as a compromise between these two techniques, and has a penalty which is a mix of $L_1$ and $L_2$ norms.
Comment: also because the authors are the inventors of these techniques!
Comment: That is a wonderful reference book.
Comment: New link: http://statweb.stanford.edu/~tibs/ElemStatLearn/
Comment: Thank you for giving us a reference of this beautiful book
Comment: I highly recommend section 18.4 as well, pages 661-668. Provides more information on lasso vs. elastic net.
Comment: Link to the book is dead as of 14 Oct 2016
Comment: @Bakaburg They are the *inventors* ie these are not "age-old" techniques??
Comment: AKAIK Tibshirani and/or Hastie are the inventor or at least one of the biggest improver of L1 and L2 regularization techniques for regression, especially of the elastic net. But maybe I am wrong :)
Answer: To summarize, here are some salient differences between Lasso, Ridge and Elastic-net:

Lasso does a sparse selection, while Ridge does not.
When you have highly-correlated variables, Ridge regression shrinks the two coefficients towards one another. Lasso is somewhat indifferent and generally picks one over the other. Depending on the context, one does not know which variable gets picked. Elastic-net is a compromise between the two that attempts to shrink and do a sparse selection simultaneously.
Ridge estimators are indifferent to multiplicative scaling of the data. That is, if both X and Y variables are multiplied by constants, the coefficients of the fit do not change, for a given $\lambda$ parameter. However, for Lasso, the fit is not independent of the scaling. In fact, the $\lambda$ parameter must be scaled up by the multiplier to get the same result. It is more complex for elastic net.
Ridge penalizes the largest $\beta$'s more than it penalizes the smaller ones (as they are squared in the penalty term). Lasso penalizes them more uniformly. This may or may not be important. In a forecasting problem with a powerful predictor, the predictor's effectiveness is shrunk by the Ridge as compared to the Lasso.
Comment: @ balaks for the second point that you made, what does it mean of 'one does not know which variable gets picked'? Did you mean LASSO is indifferent, so it kind of randomly picks one so we don't really know which one is the best?
Comment: total non-expert here, but I think the idea is that X1 and X2 may be significantly indifferent explainers of Y, but the tiny unimportant edge of one over the other leads lasso to select it a floor the other, where Ridge would preserve them both. As such, lasso results may be harder to reproduce or cross validate. This MIGHT be consistent with why we call lasso an unstable selector. (Would love someone else to confirm)
Answer: I highly recommended you to have a look at An introduction to statistical learning book (Tibshirani et. al, 2013).
The reason for this is that Elements of statistical learning book is intended for individuals with advanced
training in the mathematical sciences. In the foreword to ISL, the authors write:

An Introduction to Statistical
  Learning arose from the perceived need for a broader and less technical
  treatment of these topics. [...]
An Introduction to Statistical Learning is appropriate for advanced undergraduates or master's students in statistics or related quantitative fields or for individuals in other disciplines who wish to use statistical learning tools to analyze their data.
Comment: It's fine to quote a book, but please mark it as a quote and not as your own text. Otherwise it's plagiarism. I edited it for you now.
Comment: Can you elaborate on why you found this reference to be useful?
Answer: The above answers are very clear and informative. I would like to add one minor point from the statistic perspective. Take the ridge regression as an example. It is an extension of the ordinal least square regression to solve the multicollinearity problems when there are many correlated features. If the linear regression is
Y=Xb+e

The normal equation solution for the multiple linear regression
b=inv(X.T*X)*X.T*Y

The normal equation solution for the ridge regression is
b=inv(X.T*X+k*I)*X.T*Y.

It is a biased estimator for b and we can always find a penalty term k which will make the mean square error of Ridge regression smaller than that of OLS regression.
For LASSO and Elastic-Net, we could not find such a analytic solution.

Ridge, lasso and elastic net


Importing non-unique terms with Feeds Importer

Question: I'm trying to import a large chunk of data to our site using Feeds Importer. However, I've come to a small problem when trying to map a piece of our data to a collection of taxonomy terms.
The problem is as follows:
We have a vocabulary called Categories with two levels. Every parent term has a list of child terms.
In some of our terms, both the parent and the child have the same name, e.g.:
parent; child
Cozinhas; Cozinhas
This is absolutely necessary as we need both the main category and the sub category to be listed and presented in this fashion.
With Feeds Importer we simply import all the main (parent) categories once and the every sub (child) categories related to it (e.g.: "Casas de Banho" -> "Banheiras"). However, in this case, it simply maps the term to the parent and lists it twice. We are using Hierarchical Select to save the terms, so we use Tamper to explode the terms we've imported and send it to the correct field.
I've tried importing the alias of the sub-category term ("Cozinhas-0") and the unique ID to map it correctly but it simply doesn't work that way, it seems it has to be the term name.
Is there any way to map this correctly?
tl;dr:
We need to import several values, with Feeds Importer, into a single Hierarchical Select field and we need them to be unique, in order to map same-name taxonomy terms to their correct ID. Is there a way to do this?
Answer: Obviously, there is a way to map by term ID on the mapping settings of the Feeds Importer.

Problem solved!
Comment: How would you achieve this on the new Feeds 3? I have a terms already on Drupal and looking to import and I currently do not have TermIDs.


which is best popular open source logging software/program in c++ program area?

Question: which is best popular open source log software/program in c++ program area?
I know log4cpp is one of logging programs, but it had memory leaking issue, So I want know which is popular and best one in production area?
Comment: Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam.
Answer: Starting from version 1.54.0, Boost has included boost.log.


How do you play loud notes on the piano without slapping the keys?

Question: How do you play loud notes on the piano without generating a harsh, slapping, or percussive sound?
I read about pressing down from the surface of the keys rather than from above. And my piano teacher recommends releasing tension after hitting the bottom of a key. What else should I take note of? Thank you.
Answer: I highly recommend reading What Every Pianist Needs to Know About the Body by Thomas Mark. The answer to this question has a lot to do with the action of the piano itself, but it has more to do with the way you move your muscles to play.
The answer to your question is explained in detail in Chapter 7, entitled "Mapping The Piano". To paraphrase the first part - The very important thing that the pianist needs to know is that it is not the pressure applied to the keys that determines the volume of the sound, but the speed with which they are depressed. This may be surprising to some pianists, but it is the truth.
If you press a key on the piano down very slowly, you will notice that just before the key reaches the keybed, there is a slight "bump". The "bump" is sometimes called the "point of sound", because just after you reach this point, the hammer is thrown toward the string. Depending on how fast the hammer is traveling, the volume or quality of the sound produced will change. You cannot change the mass of the hammer just by playing, and nothing you do after the key reaches the point of sound will have any effect on the sound, because the hammer has already been thrown at the string.
Slight changes in the velocity of key descent will produce large changes in volume and quality of sound. This is not a linear function, but an exponential one. Every piano is different, but every individual instrument will have a point at which the quality of the sound decreases at a faster rate than the volume increases. Playing on a higher quality instrument will allow you to create a higher quality sound with better volume.
Keeping all this information in mind, find a piano that is well maintained, in tune, and of high quality (Steinways have an apparent point of sound, so if you can find one of those, great) and develop an acute tactile awareness of the way you are pressing down the piano keys. Your fingers do not just play; they are not just muscles and bones, they also have nerves and receive information. Develop a fine sense of how hard you are pressing down - it shouldn't feel like pressing down, it should feel like simply moving your fingers like you would move an hinge back and forth. Lift you hands up and let your hands dangle from your wrists every time you sit down to play to relieve any tension whatsoever, and then let your fingers rest on the keys and play, not changing the way your hands are from when they are dangling from the wrist. This will save you from pain and risk of injury later on, and will vastly improve the quality of your playing with just a couple of minutes' practice - imagine how much the quality will improve over years of playing.
Find a couple pianos of varying quality and use your tactile awareness and your ears to determine where that point is where you begin giving up quality and not getting that much more volume. With your tactile awareness, you will be able to play around this point in clever ways, getting different types of fortissimo that match the innuendos you will want from the music.
Comment: Even if the hammer weren't thrown over the last little distance of travel, the instrument would still respond to velocity.
Comment: Precisely: the mass of the hammer would still be unchangeable.
Comment: Thanks this answered my question, "is velocity on a midi keyboard really the same way a piano loudness is made"? And apparently it really is just the speed. This is an interesting contrast to a guitar with which the distance you pull the string from its resting point affects the loudness and the timbre seems to be affected by various other things like plectrum type and picking depth and angle of striking/releasing it.
Comment: Now I understand why "velocity" is the name of that MIDI parameter.
Answer: The way I understand it, this is more of an issue on upright pianos than grands. It has to do with the construction of the action, the system of levers and hammers that transfer the energy of striking the key into the energy of the hammer striking the note.
If you own an upright piano at home, I highly recommend dismantling the front panel (ask yer parents, if necessary), and removing a key or two to see how it works (put it back when you're done playing). The key has a screw at the back called a capstan, and on the bottom of the key, there's a groove where it sits on a pin. When you press the key down, the pin stays put and the capstan goes up. The capstan connects to the rest of the action (the pieces of which all have clever, less memorable names).
Ignoring the middle part of the action which I am not qualified to explain. The big difference between an upright and a grand is the direction of travel of the hammers. On a grand, the hammers strike upward and gravity can pull them away to allow the strings to vibrate freely.
Not so on an upright. The hammers move horizontally. So there's little assistance from gravity to get the stupid thing back out of the way. There's usually a spring system to catch the backswing of the hammer, but it's a piece that can stop functioning correctly on unkempt uprights. That means if you're not careful, you can double-strike the string.
One of the dangers of practicing too much on an out-of-repair piano is that you teach your fingers not to trust the catchback system. And you try to control the hammers with your fingers, pressing and holding (with pressure) where finesse is required.
You should be pressing the keys so as to launch the hammer against the string and follow through with the movement until the key hits the bottom (there should be a pad, but call it "to the wood"). One firm strike and then your finger can just stay there until releasing, when the dampers will reengage.
The catchback system and the action (height adjustment of each capstan) are the pieces that need to work correctly. And if they do, then your fingers need to work with them, rather than against them. The capstan heights affect the "play" between the key and the rest of the action. On an out-of-repair piano there can be quite a bit of play between the touch of the key and the point where it engages the action. Even worse, the play may vary from key to key, so you have to alter your attack of each note to try to get a consistent volume. This contributes to much of the slappy sound of the old western saloon piano meme, as there can be a extra percussive noise if there's both play at the capstan and worn-out pads at the bottom of the action where the capstan strikes. So much for the piano mechanisms.
As to how this knowledge affects playing, the act of pressing a key should be more of a lunge rather than a slap. Imagine you're poking your stupid brother in the shoulder, telling him he's wrong about something. Not hard enough to hurt, but hard enough that he knows he's getting poked in the shoulder. :)
The part your teacher mentioned about releasing the tension is also very true. After the hammer is launched toward the string, it has a moment of free movement. The whole hammer assembly disconnects from the part that gives it force and at this moment (just before it strikes the string), you cannot affect it's velocity anymore. The hammer needs this moment of freefall in order to engage the catchback system at all. If you're pushing the keys like a bad piano might train you, the hammer doesn't experience this freefall moment, and you can continue to apply pressure right up to the string. This is a problem I had myself. (My Russian piano teacher would say: "Joshua, why do you pet the cat?" "Why do you tickle the keys?" Years later, I figured out what she meant.) In effect, your fingers try to hold the key with force, to replicate the catchback system. As programmers say: don't re=write standard library functions.
The difference is more about speed than force, I think. Not in the sense of the physics, but more poetically. Think about pressing the key in one swift movement. Remember that about halfway through, the hammer launches off into freefall. So you only need to apply pressure at the very beginning. One swift stroke.

If you can manage to practice on a grand regularly, it will help to retrain your fingers. You simply cannot control the hammers in the same way. The extra unnecessary pressure will give no haptic feedback, and this may help to loosen the habit.
Answer: This is an interesting question and I'm not aware of much if any actual research on it. Most pianists seem to claim that you can play a note with exactly the same loudness but with a different quality. I myself have a difficult time believing this as I cannot see any physical reason for it; the only thing you can control before the note is the speed at which the hammer will hit the string. After the note has been produced you have no control at all. Now, some claim you can control other things like the acceleration of the hammer when it hits the string (by utilizing the elasticity of the arm of the hammer or something; the thing gets disconnected from the key before the hit so it's not obvious you actually can do it). You can also probably have some control over the noises the mechanism or your fingers hitting the key has. To see whether or not these are possible, audible, or have the expected effect would require some careful experiments.
Now, obviously pianists do produce different qualities. What I believe causes these qualities is context. A single chord can be played with different qualities by varying the relative loudness (and even timing) of its notes. For example, if you emphasize the top note of the chord, it will sound brighter; emphasize the bass and it may sound fuller. Often when you play an accent if the only thing you do is make the note louder, it will sound harsh. You also have to ever so slightly vary the timing. You get a different effect by playing it a bit late or a bit early.
Another thing experience tells us is that when you play with relaxed hands you produce a better sound. My explanation to this is that when you're relaxed you have more control. For example if your hands are tense when you start playing a chord, chances are you'll play every note of it more or less equally loudly, which makes the chord sound dull. I don't think releasing tension after you've played a chord has any effect at all. However, releasing tension before you start playing the next thing allows you to do it in a more controlled manner. Tenseness easily causes all kinds of unwanted unevenness or uniformity in loudness and timing which gets perceived as poor tone quality.
So, to answer your question, I don't believe there's such a thing as a beautiful note. The quality always depends on the context. I think the key here is that you have to listen carefully to what you're playing now, "pre-listen" (imagine) what the next thing should sound like and have your hands ready for whatever they have to do.
Comment: I was influenced by Josef Lhevinne's [chapter](http://www.nytimes.com/1982/02/28/arts/of-piano-tone-and-umbrella-tips.html?pagewanted=1) on "The Secret of a Beautiful Tone," but it seems like tone itself is still a debated concept.
Comment: While other answers are informative, this is the only answer that directly adresses the question.
Answer: As a typist from the old school (true mechanical typewriters, not computer keyboards), I know that in order to type efficiently it is important to apply more power with your fingers early, when you just start pressing the key. At that time most of muscle energy will be converted to the velocity of the hammer (the hammer of the typewriter, in my case).
If you stop putting in power when the key is about half of the way, the typewriter key with rest in its final depressed position very silently, all sound will be from the hammer that is already accelerated enough before.
I do not have much experience on a piano, but the mechanism seems somewhat similar (the key, the system of levers and finally the accelerating hammer), so may make sense to try the experience of typists.
Answer: To play any notes on the piano keyboard without creating a slapping sound on the keys, be sure to place the fingers on the keys prior to pressing them down. To facitlitate pressing the keys, drop your wrist and snap it back up, while at the same time transferring the weight from the snap into your fingers and into the keys. A long, sharp snap will produce louder tones, whereas a slower, smoother "snap" will produce quieter tones. To minimize the thumping sound of the bottom of the keys hitting the keybed, use the weight transfer at the beginning of pressing the key, but do not follow the key with the full weight all the way to the bottom of the key.  The loudness or softness of the tone of a given note on a given piano is created by the speed/force with which the hammer strikes the strings. Since the mass of each hammer is constant, the force with which the hammer strikes the string is a function of the speed with which it strikes the string. So the only variable available to you is the speed to which you accelerate the hammer, and the speed of the hammer is the result of how much force you apply to each key's lever system.
Beyond the degree of "loudness", and some physics of the strings in terms of the clang tone (the initial strike of the hammer on the string) and resulting vibrations, other commenters here have correctly identified the necessity of context -- the balance and connection of preceeding notes, simultaneous/concommitant notes, and subsequent notes -- to affect the perception of any single note.
The most important instrument in any musical performance is . . . "the human ear". . .
Answer: Transmit your weight to the keyboard.
There is no research on it (i guess) because from the theoretical point of view there is no mystery. The difficulty of doing it is controlling all the chain of muscle, in particular there is no need to lift the shoulders, which is an instinctive movement.
Comment: I would disagree: making it your goal to play with more *weight* will not alone affect the sound and will only cause unnecessary tension.
Comment: physically we use our weight anyway, the whole thing is hence about how you transmit it...

if we were in space with no attach, you do see that we can't play piano. Then we'll need a force that binds us to the piano (let's say electric so that it produces sound anyway). Most of the part is transmitted from our butt to the floor, but part from our fingers to the keyboard. It's kind of a reversoir of force downward.


complex numbers/trig

Question: express $(-1 +j)$ in the form $re^{j\theta}$ where $r$ is positive and $-\pi<\theta<\pi$
The answer is $ \sqrt{2} e^{j \cdot 2.3562}$
My query is, that on the way to getting the answer I have $\cos\theta = -1/\sqrt{2}$ and $\sin\theta = 1/\sqrt{2}$.
thus $\cos^{-1} = 2.3562$  but when I do $\sin^{-1}(1/\sqrt{2})$ I do not get $2.3562$.  I suspect that this has something to do with radians and trig, two of my weak points.  I have set my calculator to radians.
Comment: Why all the down votes ? Anyone care to explain? I think this is a valid question and the OP is showing his progress and where is he having troubles...
Comment: what do mean :$ -pie $
Comment: @Cardinal, he means $-\pi$.
Comment: Calculators must use functions in order to display a single answer. You are running into the issue that the inverse cosine function has its range over $ \ 0 \ \le \ \theta \ \le \ \pi \ $ , but the inverse sine function has the range $ \ -\frac{\pi}{2} \ \le \ \theta \ \le \ +\frac{\pi}{2} \ $ .  When working with a calculator, one must ask the questions, "What quadrant must the angle be in?" and "What angle _in that quadrant_ has those sine and cosine values?".  A positive sine and _negative_ cosine means your angle is in the _second_ quadrant, so the angle must be $ \ \frac{3 \pi}{4} \ $ .
Answer: HINT: with $a=-1,b=1$ you will get $r=\sqrt{1^1+1^1}$ and $\tan(\phi)=\frac{1}{-1}$

complex numbers/trig


Como comparar vetores em C

Question: Olá, gostaria de entender o porquê de meu código não funcionar. Eu estou tentando desenvolver uma aplicação de forca e não consigo fazer com que a letra digitada seja comparada com a letra que está no vetor, o que eu estou fazendo de errado?
Segue o código:
#include<stdio.h>
#include<locale.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>
int main (){
    int i,len_palavra,exec=1,back;
    char lacuna[20]="_";
    char letra[20];
    char palavra[4]="arroz";

    setlocale(LC_ALL,"PORTUGUESE");
    len_palavra = strlen(palavra);
    for(i=1;i<=len_palavra;i++)
    lacuna[i]='_';

    while (exec == 1){
        system("cls");
    printf("\t\t%s\n",lacuna);
    printf("\nDigite uma letra: ");
    gets(letra);

    for(i=0;i<len_palavra;i++){
        if (letra[0] == palavra[i])
            lacuna[i] == letra[0];
    }
}
    return 0;
}

Comment: Podemos começar por aqui: char palavra[4]="arroz"; você está tentando colcoar 5 valores em um vetor com tamanho 4
Answer: Tem alguns problemas no seu código:

char palavra[4]="arroz"; O espaço reservado não joga com o tamanho guardado
for(i=1;i<=len_palavra;i++) Este for está com <= em vez de < apenas
if (letra[0] == palavra[i]) lacuna[i] == letra[0]; Dentro do if está a comparar com == em vez de atribuir o valor.

Para alem disso está a ler uma letra com gets como se fosse uma string e depois nas comparações usa apenas o primeiro caretere. Simplifique e use apenas um char.
Também não tem o critério de fim que deveria ser quando ambas as strings são iguais.
Acertando tudo isso ficaria assim:
int main ()
{
    int i,len_palavra;
    char lacuna[20]="_";
    char letra; //apenas char
    char palavra[]="arroz"; //sem tamanho especificado

    setlocale(LC_ALL,"PORTUGUESE");

    len_palavra = strlen(palavra);
    for(i=1; i<len_palavra; i++) //apenas com <
        lacuna[i]='_';

    while (strcmp(palavra,lacuna) != 0) //strcmp para saber quando termina
    {
        system("cls");
        printf("\t\t%s\n",lacuna);
        printf("\nDigite uma letra: ");
        scanf("%c",&letra); //scanf com %c em vez de gets

        for(i=0; i<len_palavra; i++)
        {
            if (letra == palavra[i])
                lacuna[i] = letra; //atribuição em vez de comparação
        }
    }

    printf("\t\t%s\n",lacuna); //adicionei este printf para ver o estado final do jogo
    return 0;
}

Veja o exemplo no Ideone
Note que utilizei a função strcmp para comparar as palavras, que retorna 0 quando são iguais.

Como comparar vetores em C


ubuntu python anaconda2: cannot import matplotlib after activate tensorflow

Question: Just as this question, I use Ubuntu and Anaconda for python 2.7 to install tensorflow and then activate the environment by source activate tensorflow which is exactly the same as shown in official website. After activation, use python command to enter python environment, now I can import tensorflow as tf but I cannot import matplotlib.
Without activating tensorflow, the import matplotlib works but in that case I cannot import tensorflow. So is it a conflict? Can someone tell me how to solve it? Is there any way to keep tensorflow always activated so that I don't need to activate it everytime (my previous ubuntu do have this feature but I forgot how did I make it)?
Answer: Try installing matplotlib using anaconda directly with conda install matplotlib from your tensorflow environment. One of the ideas of using anaconda is to keep environment self contained with the ability to avoid dependency conflicts (i.e. I don't see a point in activating the tensorflow for every new shell if you don't intend to use anaconda). You could either avoid the use of anaconda entirely and install tensorflow locally or export source activate tensorflow to your ~/.bashrc
Comment: Thanks mate, I installed matplotlib under tensorflow environment and it works. I'm currently only using cpu version of tensorflow so that I installed it through anaconda following its introduction. I'll switch to gpu version some days later to use CUDA. It's actually not takes too much time since I didn't close my terminal frequently. Anyway, thanks for your help, that's pretty nice.


Parameters in the Hamilton-Jacobi Equation

Question: I'm reading through Gelfand and Fomin's 'Calculus of Variations', and they've just derived the Hamilton-Jacobi Equation:
$$\frac{\partial S}{\partial x} + H \left(x, y_1, \ldots, y_n , \frac{\partial S}{\partial y_1},\ldots,\frac{\partial S}{\partial y_n}\right)=0$$
where $S=S(x, y_1, \ldots, y_n)$. They then go on to say that the complete integral of this equation depends on $n$ parameters:
$$S = S(x,y_1, \ldots, y_n, \alpha_1,\ldots,\alpha_n )$$
However, $S$ depends on $n+1$ independent variables $(x, y_1, \ldots, y_n)$, and the Hamilton-Jacobi equation includes partial derivatives with respect to all of them, so shouldn't the complete integral have $n+1$ parameters?
Answer: Notice that the Hamilton–Jacobi (HJ) eq. does not depend on the un-differentiated function $S$. Hence, if $S$ is a solution to the HJ eq., then adding any constant $\alpha_{n+1}$ would trivially be a new solution $S+\alpha_{n+1}$. Traditionally, one does not bother to include this trivial integration constant $\alpha_{n+1}$ in the tally of integration constants $\alpha_{1}, \ldots ,\alpha_{n}$.
References:

H. Goldstein, Classical Mechanics, Section 10.1.
Comment: Brilliant, thanks!


Programmatically stretch window across available vertical space in winforms

Question: How can I make a Winforms window stretch from the top of the screen to the bottom but not over the Taskbar?
I'm looking for an end result similar to the snap feature in Win 7, but would like it in XP and Vista too.
Answer: Look at System.Windows.Forms.Screen it contains all the information you need to do this, primarily the GetWorkingArea function.
Comment: Thanks Doggett - it's easy when you know how ;)


ASP.NET hangs when inserting numbers using texbox control

Question: I am using asp.net 4.5, C# and SQL Express, with five text boxes. The values passed are numbers between 0 and 99.  When the inserting the numbers using ExecuteNonQuery, the system hangs for 30 seconds or more.
During VS debugging, I verified the data is actually written to the database, however, ExecuteNonQuery never completes.
I have tried several methods including converting(TryParse and Convert) with the same results. I also created a simple test page with just five textboxes, but shows the same problem.  This issue fails with hard coding as well as stored procedure. Using the SQLDatasource control works, but prefer to code using C#.  The fields are only used for numbers and will be calculated during reporting.
Note: I'm assuming the value needs converted from a string to a INT.
Table structure:
<code>          [StatID] [int] IDENTITY(1,1) NOT NULL,
      [Made2PT] [int] NULL, [Missed2PT] [int] NULL,
</code>
Stored procedure:
<code>@Made2Pt Int, @Missed2pt Int
          AS
          BEGIN
      INSERT INTO tblStatsV2(Made2Pt,Missed2pt)
      VALUES (@Made2Pt,@Missed2pt)
</code>
C# code behind sample, Partial Test page with two text boxes:
<code>sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("@Made2Pt", txtMade2PT.Text == "" ? 0 :
                                          Convert.ToInt32(txtMade2PT.Text));
sqlCmd.Parameters.AddWithValue("@Missed2pt",txtMade2PT.Text == "" ? 0 :
                                          Convert.ToInt32(txtMissed2PT.Text));`
</code>
Partial sample code behind from other page:
<code> cmd.CommandType = CommandType.StoredProcedure;
 if (int.TryParse(txt2ptMade.Text, out made2PT))
 {
          cmd.Parameters.Add("@Made2Pt", SqlDbType.Int).Value = made2PT;
 }
</code>
I would expect the entry to return in less that a second as my other pages have quick response.
Comment: There is nothing wrong with this code.... but you are right, this should give an almost instant result. Therefor the issue must lie somewhere else.
Comment: What you describe sounds suspiciously like a deadlock. Are you sure you aren't calling `ExecuteNonQueryAsync`?
Answer: What I didn't do was test my issue on different browsers(Edge, Chrome, Opera...).. I did fix the stored procedure by adding local variables, but this did not eliminate the issue.  I discovered that issue only fails with Microsoft Edge. After scanning Microsoft's support, one fix was to remove a KB patch.. Each browser processes the data differently, so you can expect different results on performance issues. Hope this helps..


Prove that $(x-1,y-1)$ is a prime ideal in $\mathbb F_2[x,y]$

Question: So I need to show that $\mathbb F_2[x,y]/(x-1,y-1)$ is an integral domain.
If I define a homomorphism $\varphi:\mathbb F_2[x,y]\to\mathbb F_2[x,y]/(x-1,y-1)$ the kernel of the homomorphism is $(x-1,y-1)$. So what's next ? I am clueless.
Comment: If you want to go with that approach, you will want to define a homomorphism from $\Bbb F[x,y]$ to something you know if an integral domain, with kernel $(x-1,y-1)$. The image of that homomorphism will be isomorphic to your quotient.
Answer: Hint:
Consider the ring homomorphism
\begin{align}
\mathbf F_2[x,y]&\longrightarrow \mathbf F_2 ,\\
p(x,y)&\longmapsto p(1,1),
\end{align}
check it is surjective and determine its kernel.
Comment: Its kernel is $(x-1,y-1)$ and it is surjective by the first isomorphism theorem.Am I correct @Bernard.
Comment: The implication is that the ideal is not only prime, it is maximal.
Comment: @Smita: That's right.
Comment: @Bernard: how did you determine that it will be surjective to $F_2$.Suppose I have the ideal as $(x^2,y^2)$ what will be corresponding map and how will you guess it?
Comment: A constant polynomial maps onto what, in your opinion? I don't understand your second question. Could you give more explanations?
Comment: Suppose instead of $(x-1,y-1)$ I have $(x^2,y^2)$ will that be prime and if it is then how will you prove it similar to the proof given by you to my original question.@Bernard
Comment: It is not a prime ideal: in the quotient, $x$ and $y$ are nilpotent.


Why does this SQL result in Index Scan instead of an Index Seek?

Question: Can someone please help me tune this SQL query?
SELECT  a.BuildingID, a.ApplicantID, a.ACH, a.Address, a.Age, a.AgentID, a.AmenityFee, a.ApartmentID, a.Applied, a.AptStatus, a.BikeLocation, a.BikeRent, a.Children,
        a.CurrentResidence, a.Email, a.Employer, a.FamilyStatus, a.HCMembers, a.HCPayment, a.Income, a.Industry, a.Name, a.OccupancyTimeframe, a.OnSiteID,
        a.Other, a.ParkingFee, a.Pets, a.PetFee, a.Phone, a.Source, a.StorageLocation, a.StorageRent, a.TenantSigned, a.WasherDryer, a.WasherRent, a.WorkLocation,
        a.WorkPhone, a.CreationDate, a.CreatedBy, a.LastUpdated, a.UpdatedBy
FROM    dbo.NPapplicants AS a INNER JOIN
        dbo.NPapartments AS apt ON a.BuildingID = apt.BuildingID AND a.ApartmentID = apt.ApartmentID
WHERE   (apt.Offline = 0)
AND     (apt.MA = 'M')

.
Here's what the Execution Plan looks like:
.

What I don't understand is why I'm getting a Index Scan for NPapplicants.  I have an Index that covers BuildingID and ApartmentID.  Shouldn't that be used?
Comment: How many rows are there in the table NPapplicants?
Comment: image shows 7775, from the latest statistics update
Answer: It is because it is expecting close to 10K records to return from the matches.  To go back to the data to retrieve other columns using 10K keys is equivalent to something like the performance of just scanning 100K records (at the very least) and filtering using hash match.
As for access to the other table, the Query Optimizer has decided that your index is useful (probably against Offline or MA) so it is seeking on that index to get the join keys.
These two are then HASH matched for intersections to produce the final output.
Comment: Thanks for the response.  So are you saying there's not much I can do.  The query is about as fine-tuned as it's going to get with that much data to return?
Comment: For that amount of columns from the applicant table - yes, that's as good as it gets.  Unless the filter on `apartments(Offline,MA)` is really really selective (like 1% or less) and `count(apartments) < count(applicant)` such that it can produce only a few keys on which to INDEX SEEK on applicant.
Answer: A seek in a B-Tree index is several times as expensive as a table scan (per record).
Additionally, another seek in the clustered index should be made to retrieve the values of other columns.
If a large portion of records is expected to match, then it is cheaper to scan the clustered index.
To make sure that the optimizer had chosen the best method, you may run this:
SET STATISTICS IO ON
SET STATSTICS TIME ON

SELECT  a.BuildingID, a.ApplicantID, a.ACH, a.Address, a.Age, a.AgentID, a.AmenityFee, a.ApartmentID, a.Applied, a.AptStatus, a.BikeLocation, a.BikeRent, a.Children,
        a.CurrentResidence, a.Email, a.Employer, a.FamilyStatus, a.HCMembers, a.HCPayment, a.Income, a.Industry, a.Name, a.OccupancyTimeframe, a.OnSiteID,
        a.Other, a.ParkingFee, a.Pets, a.PetFee, a.Phone, a.Source, a.StorageLocation, a.StorageRent, a.TenantSigned, a.WasherDryer, a.WasherRent, a.WorkLocation,
        a.WorkPhone, a.CreationDate, a.CreatedBy, a.LastUpdated, a.UpdatedBy
FROM    dbo.NPapplicants AS a INNER JOIN
        dbo.NPapartments AS apt ON a.BuildingID = apt.BuildingID AND a.ApartmentID = apt.ApartmentID
WHERE   (apt.Offline = 0)
AND     (apt.MA = 'M')

SELECT  a.BuildingID, a.ApplicantID, a.ACH, a.Address, a.Age, a.AgentID, a.AmenityFee, a.ApartmentID, a.Applied, a.AptStatus, a.BikeLocation, a.BikeRent, a.Children,
        a.CurrentResidence, a.Email, a.Employer, a.FamilyStatus, a.HCMembers, a.HCPayment, a.Income, a.Industry, a.Name, a.OccupancyTimeframe, a.OnSiteID,
        a.Other, a.ParkingFee, a.Pets, a.PetFee, a.Phone, a.Source, a.StorageLocation, a.StorageRent, a.TenantSigned, a.WasherDryer, a.WasherRent, a.WorkLocation,
        a.WorkPhone, a.CreationDate, a.CreatedBy, a.LastUpdated, a.UpdatedBy
FROM    dbo.NPapplicants WITH (INDEX (index_name)) AS a
INNER JOIN
        dbo.NPapartments AS apt ON a.BuildingID = apt.BuildingID AND a.ApartmentID = apt.ApartmentID
WHERE   (apt.Offline = 0)
AND     (apt.MA = 'M')

Replace index_name with the actual name of your index and compare the execution times and the numbers of I/O operations (as seen in the messages tab)
Comment: Interesting.  Without the Index:  CPU time = 93 ms,  elapsed time = 679 ms.   ///   With the Index:  CPU time = 172 ms,  elapsed time = 666 ms.
Comment: @Axeva: as you can see, the mama optimizer didn't raise no fool. On non-selective fields, an index seek is more expensive, especially with a non-covering index.


Comparing to methods / models with human evaluators

Question: I have 2 methods / models. I want to compare them using expert human raters so the amount of samples/tests must be small.
I want to figure out which is the better method.
What is a good way of doing this?
Compare directly 1:1? Or just let them rate everything in random order and then see which method wins more often? How do I then determine statistical significance?
Answer: Do a group Test of Difference but Repeated Measure design (ANOVA, Friedman, etc) and in your following post-hoc analysis (if previous test was significant), it's a many-to-one where all are paired to the "expert".


List vs Dictionary Length Difference?

Question: New to python, but having a bit of trouble with transforming a large list into a dictionary.
<code>flat_list = [item for sublist in zipped_list_total for item in sublist]
print(flat_list)
print(len(flat_list)) #result is 9673

ticker_dictionary = dict([(d[0], d[1:]) for d in flat_list])
print(len(ticker_dictionary)) #result is 6396
</code>
To give you some background, zipped_list_total is a list that appends 3 different zipped lists together into one large zipped list. Flat_list is pretty much just drilling down the zipped list by one level. For example.. len(zipped_list_total) is 3, len(flat_list) is 9673
If we look at flat_list, the data is formatted like such:
 [(a,b,c),(d,e,f).....]
Basically I am trying to make a dictionary that says {a:(b,c), d:(e,f)...}
When I run the code above, it looks like the list correctly transforms into a dictionary up until a certain point, but then stops. Is there a reason why the conversion would stop (does it have something to do with memory?)
Thank you in advance for any help you can provide.
Comment: You likely have duplicate keys.  A dictionary can only store each key once.
Comment: ohhhh you're a smart man - I knew that was a rule, but I didn't think to check it in this scenario. You were right - thank you sir
Comment: I'll make this an answer so you can accept it and close off this issue.
Answer: You likely have duplicate keys. A dictionary can only store each key once.

List vs Dictionary Length Difference?


CV problem in LIBSVM

Question: I am using LIBSVM for regression problem. Based on the codes provides in their FAQ, the grid search is like this:
bestcv = 0;
for log2c = -1:3,
  for log2g = -4:1,
    cmd = ['-v 5 -c ', num2str(2^log2c), ' -g ', num2str(2^log2g)];
    cv = svmtrain(heart_scale_label, heart_scale_inst, cmd);
    if (cv >= bestcv),
      bestcv = cv; bestc = 2^log2c; bestg = 2^log2g;
    end
    fprintf('%g %g %g (best c=%g, g=%g, rate=%g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
  end
end

with the codes above I always got the worst results, then I changed to the following and everthing works well.
bestcv = inf;...

if (cv <= bestcv)...

In my sense cv is a score, more is better, and should be less than 1(100%). But in my case cv becomes like error, less is better, and some are bigger than 1. It's so weird, maybe I did something wrong? or can I keep my codes and results like mine?
Answer: Problem solved! I checked svmtrain.c, in case of regression problem, cv is error(MSE), lower the better. And in case of classification problem, cv is accuracy, higher the better. Therefore I did everything right.

CV problem in LIBSVM