Convolutional neural network - Using absolute of tanh on convolution output

Question: I've watched an online lecture regarding CNN (https://www.youtube.com/watch?v=wORlSgx0hZY) that confused me a bit. At roughly 8:35 in the lecture it was stated that it is important to use the absolute value of the tanh function on the output from the convolutional layer. I've never heard that before and I can't quite understand it just based on the lecture. Can anyone expand on that?
The lecture connects this to how "the polarity of features is often irrelevant to recognize objects" and "the rectification eliminates cancellations between neighboring filter outputs when combined with average pooling".
I've attached an excerpt of the slide used in the lecture below:
Answer: When you are trying to recognize objects, edges, etc., the algorithms generally look for deviation from nearby or summed/averaged elements.  The deviation could be negative or positive, but in most cases it is a "recognition" regardless of the polarity.  The algorithms impart polarity due to the mathematics, but the interpretation doesn't care if it is a deviation up or down.
However, some filters and algorithms do carry information in the polarity.  If you combine one where polarity matters with one where polarity does not, then you want to be sure you are adding a "recognition" properly, so the filter is augmented appropriately and not inappropriately pushed more negative or more positive.
Comment: Is this why rectified linear units have become popular?
Comment: I wouldn't say that, but algorithms that do this are based on older ones that don't. You would usually be responsible for rectifying or interpreting.  Given that this (and machine learning in general) is becoming very popular and accessible, packages that make sense by interpreting for you are winning.  It's a good thing overall, but even better with people like you trying to understand! Just be sure to know what you use and how it works.


Dúvida com customização de rotas asp.net mvc

Question: Estou estudando sobre rotas, tenho uma lista e quero mostra o nome do produto na url. Da forma que está mostra apenas o nome da Categoria.
Agradeço
 public class Produto
    {
        public int ProdutoId { get; set; }
        public string Nome { get; set; }
        public string Descricao { get; set; }
        public string Categoria { get; set; }
        [DisplayFormat(DataFormatString = "{0:c}")]
        public decimal Preco { get; set; }
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
        public DateTime Data { get; set; }

        public List<Produto> TodosProdutos()
        {
            var produtos = new List<Produto>
            {
                new Produto
                {
                    ProdutoId = 110,
                    Categoria = "Informatica",
                    Nome = "Notebook Acer",
                    Descricao = "E5-571-54MC com Intel Core i5, 4GB de RAM, Windows 8.1",
                    Preco = 1690.00M,
                    Data = new DateTime(2015,7,15)
                },
                new Produto
                {
                    ProdutoId = 120,
                    Categoria = "Informatica",
                    Nome = "Notebook Positivo Premium",
                    Descricao = "TV S6050 LCD 14'' Processador Intel Core i3, Windows 8, HD 500GB",
                    Preco = 1290.00M,
                    Data = new DateTime(2015,7,1)
                },
                new Produto
                {
                    ProdutoId = 130,
                    Categoria = "Informatica",
                    Nome = "iPad Mini 3",
                    Descricao = "16 GB Wi Fi Dourado MGYE2BR/A Apple",
                    Preco = 1990.00M,
                    Data = new DateTime(2015,7,10)
                },
                new Produto
                {
                    ProdutoId = 210,
                    Categoria = "Eletrodomesticos",
                    Nome = "Ar Condicionado Consul",
                    Descricao = "Portátil 12.000 Btus Frio C1A12AB, 220 V, Branco",
                    Preco = 990.00M,
                    Data = new DateTime(2015,7,11)
                },
                new Produto
                {
                    ProdutoId = 220,
                    Categoria = "Eletrodomesticos",
                    Nome = "Micro-Ondas LG",
                    Descricao = "30 L, EasyClean MH7093R Prata, com Grill, Branco",
                    Preco = 430.00M,
                    Data = new DateTime(2015,7,6)
                },
                new Produto
                {
                    ProdutoId = 230,
                    Categoria = "Eletrodomesticos",
                    Nome = "Refrigerador Electrolux",
                    Descricao = "DF42 382 Litros 2 Portas Frost Free, 220 V , Branco",
                    Preco = 1250.00M,
                    Data = new DateTime(2015,7,7)
                },
                new Produto
                {
                    ProdutoId = 310,
                    Categoria = "Telefonia",
                    Nome = "Samsung Galasy S6",
                    Descricao = "SM-G920I Single Chip, Branco, Processador quad-core",
                    Preco = 2120.00M,
                    Data = new DateTime(2015,7,3)
                },
                new Produto
                {
                    ProdutoId = 320,
                    Categoria = "Telefonia",
                    Nome = "Motorola Moto G",
                    Descricao = "Preto, TV Digital, Dual Chip, Processador Quad Core 1.2GHz, Tela 5",
                    Preco = 870.00M,
                    Data = new DateTime(2015,7,16)
                },
                new Produto
                {
                    ProdutoId = 410,
                    Categoria = "Esporte",
                    Nome = "Bicicleta Colli Bike ",
                    Descricao = "Aro 26 18 Marchas Suspensão Dianteira CBX 750 Preta + Garrafa Térmica",
                    Preco = 380.00M,
                    Data = new DateTime(2015,7,9)
                },
                new Produto
                {
                    ProdutoId = 420,
                    Categoria = "Esporte",
                    Nome = "Tênis Feminino Fila",
                    Descricao = "Kenya Racer, 2.0 W Vermelho/Limão, 38, Palminha durável",
                    Preco = 125.00M,
                    Data = new DateTime(2015,7,10)
                },
                new Produto
                {
                    ProdutoId = 430,
                    Categoria = "Esporte",
                    Nome = "Tênis Diadora",
                    Descricao = "Ghost III Azul e Verde Masculino, número 44",
                    Preco = 65.00M,
                    Data = new DateTime(2015,7,11)
                },
                new Produto
                {
                    ProdutoId = 510,
                    Categoria = "Beleza",
                    Nome = "Barbeador Philips",
                    Descricao = "Aquatouch AT751 Recarregável, 110 V",
                    Preco = 219.00M,
                    Data = new DateTime(2015,7,1)
                },
                new Produto
                {
                    ProdutoId = 520,
                    Categoria = "Beleza",
                    Nome = "Secador Candence",
                    Descricao = "Secador de Cabelo - SEC400 - 1400w, Cabo, 220 V",
                    Preco = 205.00M,
                    Data = new DateTime(2015,7,3)
                },
            };
            return produtos;
        }
    }

tenho no RouteConfig:
  public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                  "Produtos",
                  "Produtos/",
                  new { Controller = "Produto", Action = "Index" }
                );

            routes.MapRoute(
                "Detalhes",
                "Produtos/{produtoid}",
                new { Controller = "Produto", Action = "Detalhes" },
                new { Produtoid = @"\d+" }
                );

            routes.MapRoute(
                 "Categorias",
                 "Produtos/{categoria}",
                 new { controller = "Produto", action = "Categorias" }
             );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Produto", action = "Index", id = UrlParameter.Optional }
            );

        }

Tenho o Controller:
    public class ProdutoController : Controller
    {

        private readonly List<Produto> todosProdutos;

        public ProdutoController()
        {
            todosProdutos = new Produto().TodosProdutos().OrderBy(x => x.Preco).ToList();
        }

        // GET: Produto
        public ActionResult Index()
        {
            ViewBag.Produtos = "Todos os Produtos";
            return View(todosProdutos);

        }

        public ActionResult Detalhes(int produtoId)
        {
            return View(todosProdutos.FirstOrDefault(x => x.ProdutoId == produtoId));
        }

        public ActionResult Categorias(string categoria)
        {
            var _categoria = todosProdutos.Where(x => x.Categoria == categoria).ToList();
            ViewBag.Categoria = categoria;
            return View(_categoria);
        }

    }

Comment: em qual url q vc quer mostrar o nome do produto?
Comment: qual o problema?
Comment: Quero mostra o nome do produto na URL neste exemplo só mostra o nome da categoria
Answer: No seu controller você precisará criar uma action que receba o nome da categoria e do produto como parâmetros. Ex.
    public ActionResult Exibir(string categoria, string produto)
    {
        var modelProduto = todosProdutos.FirstOrDefault(x => x.Categoria == categoria && x.Nome == produto); //Sugestão, crie um campo para exibir o nome do produto formatado para url:
        return View(modelProduto );
    }

No arquivo RouteConfig.cs adicione a nova configuração. Ex.
routes.MapRoute(
    "Exibir",
    "Produto/{categoria}/{produto}",
    new { Controller = "Produto", Action = "Exibir" }
    );

Sugestão: Crie um campo específico no seu modelo para guardar o nome do produto e da categoria de forma "amigável" para URLs, removendo espaços, acentos e caracteres especiais. Ex. Se o nome do produto "Produto em promoção", o campo UrlAmigavel deve trazer "produto-em-promocao".


"reduce" function in python not work on "namedtuple"?

Question: I have a log file that is formatted in the following way:
datetimestring \t username \t transactionName \r\n

I am attempting to run some stats over this dataset.  I have the following code:
import time
import collections
file = open('Log.txt', 'r')

TransactionData = collections.namedtuple('TransactionData', ['transactionDate', 'user', 'transactionName'])
transactions = list()

for line in file:
    fields = line.split('\t')

    transactionDate = time.strptime(fields[0], '%Y-%m-%d %H:%M:%S')
    user = fields[1]
    transactionName = fields[2]

    transdata = TransactionData(transactionDate, user, transactionName)
    transactions.append(transdata)

file.close()

minDate = reduce(lambda x,y: min(x.transactionDate, y.transactionDate), transactions)
print minDate

I did not want to define a class for such a simple dataset, so I used a name tuple.  When I attempt to run, I get this error:
Traceback (most recent call last):
  File "inquiriesStat.py", line 20, in <module>
    minDate = reduce(lambda x,y: min(x.transactionDate, y.transactionDate), transactions)
  File "inquiriesStat.py", line 20, in <lambda>
    minDate = reduce(lambda x,y: min(x.transactionDate, y.transactionDate), transactions)
AttributeError: 'time.struct_time' object has no attribute 'transactionDate'

It appears that the lambda function is operating on the 'transactionDate' property directly instead of passing in the full tuple.  If I change the lambda to:
lambda x,y: min(x, y)

It works as I would expect.  Any ideas why this would be the case?
Comment: I believe in a world without `reduce`...
Answer: Simply use:
minDate = min(t.transactionDate for t in transactions)

Below is an explanation of why your code isn't working.
Let's say transactions = [t1, t2, t3] where t1...t3 are three named tuples.
By the definition of reduce, your code:
reduce(lambda x,y: min(x.transactionDate, y.transactionDate), transactions)

is equivalent to
min(min(t1.transactionDate, t2.transactionDate).transactionDate, t3.transactionDate)

Clearly, the inner min() returns time.struct_time instead of a named tuple, so when reduce tries to apply .transactionDate to it, that fails.
There are ways to fix this, and to make use of reduce for this problem. However, there seems to be little point given that a direct application of min does the job and to my eye is a lot clearer than anything involving reduce.
Comment: or `key=operator.attrgetter('transactionDate')`. Don't use a `lambda` when there is a built-in that does the same thing.
Comment: reduce doesn't work because the result of the first call (a time.struct_time) to reduce is passed in as one of the arguments to the next call.
Comment: @agf: why, is there a significant difference in efficiency or something that actually makes `operator.attrgetter` preferable?
Comment: contrast with `reduce((lambda x,y: x if x.transactionDate < y.transactionDate else y), transactions)` which would work ;-)
Comment: @agf: true, I just don't use that effect often enough for its syntax to really stick in my head, and I find it's usually not worth the effort to look it up every time when I could just do the same thing with a lambda function while incurring only a few percent performance penalty. (A test I just ran shows a 4% difference)
Comment: @Duncan You're right, you'd have to seed it with a `struct_time` to start with, like `transactions[0].transactionDate` or something.
Comment: @DavidZaslavsky Yes. A call to a function defined in C is much faster than a function defined in Python, and there is one less level of indirection. Plus, why re-implement a built-in? You're not going to do it better / faster than what's already in Python, and you can very easily do it worse, so it's good practice to get used to using the tools provided to you.
Comment: Incompatible return types between function calls to reduce was indeed the problem.  I realize that there are easier built in ways to implement what I have described, but I wanted to see how "map" "reduce" and "lambda" work in python.  Getting back to my lisp roots :)  Thanks everyone.


Can I use drupal_get_form and drupal_render within a custom Drupal 7 input filter?

Question: As the title says:  I've got a custom input filter in Drupal 7 which replaces a token with a custom drupal form. Without showing the complete code, which might just confuse things, The main essence is the following:
<code>function _my_filter($text, $filter = NULL, $format = NULL, $langcode = NULL, $cache = NULL, $cache_id = NULL) {
  $rendered_text = $text;
  preg_match_all(MY_CUSTOM_REGEX, $text, $matches);
  if (!empty($matches[0])) {
    foreach ($matches[0] as $match) {
      $custom_form = drupal_get_form('my_custom_form');
      $replacement = drupal_render($custom_form);
      $rendered_text = str_replace($match, $replacement, $rendered_text);
    }
  }
  return $rendered_text;
}
</code>
For some reason when the node is being saved this times out.  I've narrowed it down to being something in my drupal_get_form (but this form renders fine without any problems outside of an input filter).
Can I use drupal_get_form and drupal_render within an input filter like this?
Answer: I believe you can do this, but not by default. You'll need to disable caching. This is because the filtered data is cached, so your form will only work the first time. To disable caching, you need to set cache to FALSE in your hook_filter_info() definition.
If it's timing out, then it may be a problem in your form definition itself - does the for work in non-filter context (ie embedded directly into a page)?
Comment: I kept thinking I had this solved...but I still don't.  It absolutely appears cache related.  Putting cache => false into my _info definition didn't fix it, but that may be due to multiple layers of caching happening on the server.  You seem to be right that it shows the form the first time...then after that, every time, it times out.  So, while your fix didn't 'solve' this, I think it's the correct answer and the key to the puzzle here.


Textbook suggestion-Vector Analysis

Question: I took a course in vector analysis this year. It was a two fold course. The first part covered linear algebra and basic euclidean geometry. The second took to more advanced areas such as differential geometry, and the integration theorems. We used vector analysis by Schaum(author: Murray Speigel). I was wondering if there are more books on the subject? Please make sure you state the things covered in the textbooks you mention.
Comment: What is your background in single-variable calculus, or in mathematical analysis? Mainly, I'd like to know if you've studied those subjects in a way that emphasized proofs and theory.
Comment: @ user204305 : Yes, I have. I have done advanced mathematical analysis, which is a course we take in my university. The course took a deviation to an introduction in functional analysis. You see the problem I have is that I understand the concepts behind vector analysis, but I cannot seem to apply it when presented with a real situation(in particular I am working on water etching). I want to improve my problem solving, although the textbook mentioned has many solved problems, it does not offer insight. Or maybe I was blind for it.
Comment: You could try Chapter 7 of Arnold's *Mathematical Methods of Classical Mechanics* for an intuitive explanation of differential forms. At a lower level, you could try Volume 2 of *Calculus* by Apostol. For a fuller theoretical treatment, you can look at *Advanced Calculus* by Loomis, or *Mathematical Analysis II* by Zorich.
Answer: Schaum's Outline Vector Analysis by Murray Spiegel is useful for those who would devote themselves to advanced topics, where the vector analysis is just the beginning. Schaum's Outline Vector Analysis by Murray Spiegel is, I believe, not only covers the topic vector analysis, but also other interesting topics like Gauss' and Coulomb's Law, which can be explained by vector analysis. I suppose you are an engineering student, so you don't have to learn the intricacies of vector analysis. I would recommend the book Calculus with Analytic Geometry by Thurman S. Peterson (ISBN 97185-5804-9). It has a chapter that is devoted to vector analysis and its succeeding chapters covers other topics which is the logical consequence of learning vector analysis (example: divergence, curl, line and surface integrals).
It's a good book. Happy looking! Cheers!:-)
The book looks like this:enter image description here
Note: That's not me. I'm uploading better picture for you.
Answer: I highly recommend "Vector Calculus" by Michael Corral, which you can either download for free from here: https://www.mecmath.net/ or get a printed b/w copy from lulu here: https://www.lulu.com/de/de/shop/michael-corral/vector-calculus/paperback/product-7wd428.html?page=1&pageSize=4.
Comment: As it's currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).

Textbook suggestion-Vector Analysis


Why $E[X_iX_j] = P(X_i=1, X_j=1)$?

Question: This is a probability problem.
At a party, n people put their hats and they handed in their own hats into a box.
After enjoying party, they picked up one of them.
\begin{align}
X_iX_j&=\left\{
\begin{array}{ccc}
1 & \mbox{if the ith and jth party goers both select their own hats.}\\
0 & otherwise.
\end{array} \right.
\end{align}
\begin{align}
E[X_iX_j]&=P\{X_i=1, X_j=1\}\\
&=P(X_i=1)P(X_j=1|X_i=1)\\
&=\frac1n \frac1{n-1}
\end{align}
In this process, I don't understand where and how $E[X_iX_j]=P\{X_i=1, X_j=1\}$ come into existence. Please give me some hints or explanation? thank you!
Comment: I think confusion may arise because $X_i, X_j$ are not explicitly defined. Writing $P\{X_i=1,X_j=1\}$ is just a convenient way of saying $P\{\text{both $i,j$ pick their own hats}\}$. You could also write this as $P\{X_i=2,X_j=1/2\}$, for instance, and in that case you define $X_i, X_j$ in a slightly different way, but both refers to the same event.
Comment: Sorry for causing confusion. I should have added $E(X_i)=/frac1n$ for $i=1,2,...,n$
Answer: Since $X_i,X_j$ take values in $\{0,1\}$, the product $X_iX_j$ is equal to $1$ if $X_i=X_j=1$, and 0 if at least one of the two is $0$.
So $$\begin{align}\mathbb{E}[ X_iX_j ] &= 1\cdot \mathbb{P}\{X_i=1\text{ and }X_j=1\}+ 0\cdot \mathbb{P}\{X_i=0\text{ or }X_j=0\} \\&= \mathbb{P}\{X_i=1\text{ and }X_j=1\}\end{align}$$
by definition of the expectation as $\mathbb{E}[Z]=\sum_{a} a \mathbb{P}\{Z=a\}$ (for $Z$ being a discrete random variable).
Comment: The above, of course, relies on the (implicit in your question) definition of $X_i$ being the indicator event of "party goer $i$ chooses her own hat.". That is, $$X_i = \begin{cases} 1 & \text{ if  party goer } i \text{ chooses her own hat}\\0 &\text{ otherwise.}\end{cases}$$
Comment: Thank you very much. I'm impressed nice answer. Thank you.
Comment: You're welcome!

Why $E[X_iX_j] = P(X_i=1, X_j=1)$?


How to DROP multiple columns with a single ALTER TABLE statement in SQL Server?

Question: I would like to write a single SQL command to drop multiple columns from a single table in one ALTER TABLE statement.
From MSDN's ALTER TABLE documentation...

DROP { [CONSTRAINT] constraint_name | COLUMN column_name }

Specifies that constraint_name or column_name is removed from the table. DROP COLUMN is not allowed if the compatibility level is 65 or earlier. Multiple columns and constraints can be listed.

It says that mutliple columns can be listed in the the statement but the syntax doesn't show an optional comma or anything that would even hint at the syntax.
How should I write my SQL to drop multiple columns in one statement (if possible)?
Answer: For SQL Server:
ALTER TABLE TableName
    DROP COLUMN Column1, Column2;

The syntax is
DROP { [ CONSTRAINT ] constraint_name | COLUMN column } [ ,...n ]

For MySQL:
ALTER TABLE TableName
    DROP COLUMN Column1,
    DROP COLUMN Column2;

or like this1:
ALTER TABLE TableName
    DROP Column1,
    DROP Column2;

1 The word COLUMN is optional and can be omitted, except for RENAME COLUMN (to distinguish a column-renaming operation from the RENAME table-renaming operation). More info here.
Comment: @Gweebz - I assume that the error that you had was related to column usage. Column could be used in a constraint, index or another calculated column.
Comment: Precisely; the second column I had was used in an Index. I dropped that Index and my DROP statement worked perfectly after that.
Comment: @jeicam - That would have happened probably because, 1 of the columns you are trying to drop might be a primary key.
Comment: You can also add if exists statement if needed `DROP COLUMN IF EXISTS Column1`
Answer: Summarizing
Oracle:
ALTER TABLE table_name DROP (column_name1, column_name2);

MS SQL Server:
ALTER TABLE table_name DROP COLUMN column_name1, column_name2

MySQL:
ALTER TABLE table_name DROP column_name1, DROP column_name2;

PostgreSQL
ALTER TABLE table_name DROP COLUMN column_name1, DROP COLUMN column_name2;

Be aware
For some DBMS, such as MS SQL:

DROP COLUMN does not physically remove the data, and for fixed length types (int, numeric, float, datetime, uniqueidentifier etc) the space is consumed even for records added after the columns were dropped. To get rid of the wasted space do ALTER TABLE ... REBUILD. (source)
Comment: For PostgreSQL you can even omit `COLUMN` keyword as in MySql.
Comment: You can also use the same format for MySQL as for MS SQL and Postgre SQL: ALTER TABLE table_name DROP COLUMN column_name1, column_name2;
Answer: create table test (a int, b int , c int, d int);
alter table test drop column b, d;

Be aware that DROP COLUMN does not physically remove the data, and for fixed length types (int, numeric, float, datetime, uniqueidentifier etc) the space is consumed even for records added after the columns were dropped. To get rid of the wasted space do ALTER TABLE ... REBUILD.
Comment: +1 for the note about table sizes and requiring a REBUILD. Can you provide a link to documentation as a reference?
Comment: I talked to my DBA about doing a REBUILD and he said that if the table had a clustered Index (which mine did), I could just run `ALTER INDEX PK_IndexName ON TableName REBUILD` and it would reclaim the space. This is somewhat described here: http://msdn.microsoft.com/en-us/library/ms189858.aspx under the section "Rebuilding an Index".
Comment: Right there in the ALTER TABLE: http://msdn.microsoft.com/en-us/library/ms190273.aspx
Comment: Anyone can shed some light on WHY would this be implemented like so? If I dropped column I expect indexes, data and everything built on that column to be gone. Leaving space wasted without as much as warning seems like bad practice, or am I missing something?
Answer: This may be late, but sharing it for the new users visiting this question.
To drop multiple columns actual syntax is
alter table tablename drop column col1, drop column col2 , drop column col3 ....

So for every column you need to specify "drop column" in Mysql 5.0.45.
Comment: @TomBikiNurse The question has an MSDN reference hence it was assumed that the SQL in question is related to MS SQL Server and not MySQL
Comment: @Graeme the syntax is correct, i have tested it and it works, if i use:  ALTER TABLE Test DROP COLUMN c1, c2; Mysql throws an error. ...near c2
Comment: This is incorrect syntax.  Use:
ALTER TABLE Test DROP COLUMN c1, c2;
Comment: @SuryaPratap The question does mention 'my SQL' in the last paragraph.
Comment: @Eternal21 the reference you mention is ```How should I write my SQL to drop multiple columns in one statement (if possible)?``` the context of the sentence suggests that the "my" referred to the author and "SQL" referred the language.
Comment: This syntax is better especially if you want to make use of the newer idempotent syntax for dropping columns:

`ALTER TABLE dbo.[TableName]
        DROP COLUMN IF EXISTS [Column1],
        COLUMN IF EXISTS [Column2]`

See Jeff Rush's post: https://thedatayouneed.com/drop-exists-columns/
Answer: The Syntax as specified by Microsoft for the dropping a column part of an ALTER statement is this
 DROP
 {
     [ CONSTRAINT ]
     {
          constraint_name
          [ WITH
           ( <drop_clustered_constraint_option> [ ,...n ] )
          ]
      } [ ,...n ]
      | COLUMN
      {
          column_name
      } [ ,...n ]
 } [ ,...n ]

Notice that the [,...n] appears after both the column name and at the end of the whole drop clause. What this means is that there are two ways to delete multiple columns. You can either do this:
ALTER TABLE TableName
    DROP COLUMN Column1, Column2, Column3

or this
ALTER TABLE TableName
    DROP
        COLUMN Column1,
        COLUMN Column2,
        COLUMN Column3

This second syntax is useful if you want to combine the drop of a column with dropping a constraint:
ALTER TBALE TableName
    DROP
        CONSTRAINT DF_TableName_Column1,
        COLUMN Column1;

When dropping columns SQL Sever does not reclaim the space taken up by the columns dropped. For data types that are stored inline in the rows (int for example) it may even take up space on the new rows added after the alter statement. To get around this you need to create a clustered index on the table or rebuild the clustered index if it already has one. Rebuilding the index can be done with a REBUILD command after modifying the table. But be warned this can be slow on very big tables. For example:
ALTER TABLE Test
    REBUILD;

Answer: For MySQL (ver 5.6), you cannot do multiple column drop with one single drop-statement but rather multiple drop-statements:
mysql> alter table test2 drop column (c1,c2,c3);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(c1,c2,c3)' at line 1
mysql> alter table test2 drop column c1,c2,c3;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'c2,c3' at line 1
mysql> alter table test2 drop column c1, drop column c2, drop c3;
Query OK, 0 rows affected (0.64 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>

BTW, drop <col_name> is shorthanded for drop column <col_name> as you can see from drop c3 above.
Answer: If it is just single column to delete the below syntax works
ALTER TABLE tablename DROP COLUMN column1;
For deleting multiple columns, using the DROP COLUMN doesnot work, the below syntax works
ALTER TABLE tablename DROP (column1, column2, column3......);
Answer: Generic:
ALTER TABLE table_name
DROP COLUMN column1,column2,column3;

E.g:
ALTER TABLE Student
DROP COLUMN Name, Number, City;

Answer: alter table tablename drop (column1, column2, column3......);

Comment: This is incorrect syntax. Use: ALTER TABLE Test DROP COLUMN c1, c2;
Answer: for postgis is
alter table table01 drop columns col1, drop col2
Comment: tried with sql, but it does not work. Got this in log:

12:58:04 ALTER TABLE ORDERS DROP COLUMNS user_name, user_contact_number, user_address Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user_name, user_contact_number, user_address' at line 2 0.0060 sec
Answer: this query will alter the multiple column test it.
create table test(a int,B int,C int);

alter table test drop(a,B);

Comment: This is incorrect syntax. Use: ALTER TABLE Test DROP COLUMN c1, c2;
Answer: ALTER table table_name Drop column column1, Drop column column2,Drop column column3;

for MySQL DB.
Or you can add some column while altering in the same line:
ALTER table table_name Drop column column1, ADD column column2 AFTER column7;


What is the importance of the multiplicity of an eigenvalue of a matrix A?

Question:
Here is the question, given that $A$ is an $m \times m$ matrix, is the statements in problem (3) and (4) true or false? I just can't figure out why the multiplicity of eigenvalues matters here.
Thanks in advance.
Comment: Welcome to math.SE. Please include all the necessary information in your question; don't make people go to different sites to see pictures so they know what you are talking about.
Comment: Which is why you should **type out the information**. In any case, the use of images instead of text is strongly discouraged, for many reasons (it messes up some displays, it is not accessible-friendly, it is not searchable, etc).
Comment: @ArturoMagidin sorry about that, but it seems that I do not have enough reputation to show pictures within this site, it automatically uses the imugr
Comment: https://en.wikipedia.org/wiki/Krylov_subspace
Answer: Well, this is only a start!  We could think more about how to rigorously show this ...
For now, I've done a few empirical experiments.  If $A$ has eigenvalue of multiplicity $m$, then $A$ is proportional to the identity matrix, and if the eigenvalue is positive, the sequence converges to a vector parallel to the vector you start with.  If the eigenvalue is negative, the sequence will not converge (the sign will flip with each iteration).
Similarly, if any of the eigenvalues are negative in the multiple eigenvalue case, we can see the same behavior.
If there are all positive eigenvalues, looks (only after a few experiments) to converge.
Comment: So, the matrix $\left(\begin{array}{cc}1&1\\0&1\end{array}\right)$, which has eigenvalue $1$ repeated twice, is "proportional to the identity matrix"? How?
Comment: You are right!  Missed that.
Answer: In the repeated eigenvalue case, you might want to consider looking at Jordan normal form. For the $m$ repeated eigenvalues case, we can write the entire matrix as just one Jordan block, or as $J=\lambda I + N$ for a nilpotent matrix $N$ with ones on the superdiagonal.
If we raise this to the $k$th power and apply it to a random vector $v\in \mathbf{R}^m$ and normalize to get $v_k := J^kv/\|J^k v\|$, this is the same as iterating the method above $k$ times (assuming we never get to the division by zero part). So, to figure out what happens we need to see if $J^k/\|J^k v\|$ converges. This does converge, but it depends on $N$. If $N$ is the zero matrix, we'll just get back the original vector. From now on we will assume $N$ is nonzero as well as $\lambda$.
If it is not the zero matrix, for large powers a few select entries will dominate. The reason why this happens can be seen from the binomial theorem:
$$(\lambda I+N)^k = \sum_i \binom{k}{i}\lambda^{k-i} N^{i}.$$
In general you can't use this, but $\lambda I$ commutes with everything so it is fine here. Many of these terms vanish since $N$ is nilpotent, and for sufficiently large $k$ the number of terms becomes constant. The largest term as $k\to \infty$ will always be the one associated to the largest value of $i$, which we can see by dividing out by $\lambda^k$. This is because $\binom{k}{i}$ will grow on the order of $k^i$ for fixed $i$. To find this term, we look for the largest nonzero power of $N$. The nonzero entries in this matrix will indicate the dominant values in $J^k$.
Because we normalize the vector, we can scale the matrix by anything and get the same result at the end. Thus, for large $k$ we can treat $J^k$ as $N^i$ where $i$ is the largest nonzero power of $N$ because these are precisely the dominant entries. Thus, we get $N^i v/\|N^i v\|$ as our result in the limit.
For example, take the matrix $\begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}$ that you gave. The matrix $N$ will be $\begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}$, which has $N^2=0$. As a result, we will converge to $Nv/\|Nv\|$ which is either $\vec{0}$ or $(\pm1,0)$.
One point that is worth making is that while this does converge, it is quite slow. Look at the following SAGE code:
<code>m=matrix(RR,2,2,[[1,1],[0,1]])

print m
M=m^10000
print M

v=vector((-1,-23))

print M*v/((M*v).norm())

m2=matrix(RR,2,2,[[2,1],[0,1]])

print m2
M2=m2^10000
print M2

print M2*v/((M2*v).norm())
</code>
The first gives us (-0.999999995000043, -0.0000999995647192882), while the second gives (-1.00000000000000, -4.80352388465618e-3011). Big difference!
Comment: Thank you! just one question, if it says a matrix of m x m with only one eigenvalue with multiplicity m, does that mean this matrix can only be in the form of a big Jordan block? If yes, is there any simple proof of that?
Comment: Under an appropriate change of basis, yes it must have that form. Consider $A-\lambda I$, where $\lambda$ is your eigenvalue. Then $(A-\lambda I)^m=0$ by Cayley-Hamilton. Hence, $N=A-\lambda I$ is nilpotent - under a suitable basis, we can write $N$ as 1's and 0's on the superdiagonal. But $\lambda I$ is the same in any basis, so adding it back we get the desired form. There's a more general proof here: https://en.wikipedia.org/wiki/Jordan_normal_form


How to get Expectation and Variance of Geometric Distributions

Question: A random variable N follows a geometric distribution with the "Success Rate" = $\alpha$, so that $P [N=k] = \alpha (1-\alpha)^{k-1},$ for $k$ = 1,2,...
Random variables $(Y_1 , Y_2...)$ are independent replications of a random variable $(Y)$. Also assume that these replications are independent from $N$. The distribution of $Y$ is shown below:
$P[Y=3] = \frac{1}{4} $ and $P[Y=-1]=\frac{3}{4}$.
Consider a random variable $Z$ defined as the sum of first $(N+1)$ variables, that is
$$Z = Y_1 + Y_2 + ... + Y_N + Y_{N+1}$$
A. What is the expectation of $Z$?
I dont understand how to apply the formula for expectation since what I know is $E[Z] = \int^\infty_{-\infty} xf_x(x)dx  $. How do I manipulate the information given to use this formula?
B. What is the variance of $Z$?
$var(Z) = E[Z^2] - E[Z]^2$ What am I not understanding?
Comment: $Z$ is not a continuous random variable, but discrete. To compute $E[Z]$ condition on $N$, i.e. $E[Z]=E[E[Z|N]]$.
Answer: Condition on $N$ to have better knowledge on $Y_i$, $i=1,\dots,N$. Nevertheless, you can easily observe that $E[Y_i]=0$ for all $i$ so $E[Z]$ will eventually be zero as well. But you can do it as follows:
\begin{align*}
E[Z] &= E[E[Z|N]]= E[E[Y_1+\dots+Y_n+Y_{n+1}|N=n]]
\end{align*}
On the other hand, each $Y$ is Bernoulli taking values in $\{-1,3\}$. So
$$E[Y_i] = 3\frac{1}{4}-1\frac{3}{4} = 0.$$
Hence
$$E[Y_1+\cdots Y_n+Y_{n+1}|N=n] = 0*(n+1)=0.$$
Hence
$$E[Z]=0.$$
Since $E[Z]=0$ the variance is just $E[Z^2]$ and again using the same reasoning you get
\begin{align*}
E[Z^2] &= E[E[Z^2|N]]= E[E[(Y_1+\dots+Y_n+Y_{n+1})^2|N=n]]
\end{align*}
Now since all $Y_i$ are independent $E[Y_iY_j]=E[Y_i]E[Y_j]=0$ then
$$E[(Y_1+\cdots Y_{n+1})^2|N=n] = E[Y_1^2+\cdots Y_{n+1}^2|N=n]=(n+1)E[Y_i^2]=(n+1)(3^2\frac{1}{4}+(-1)^2\frac{3}{4})=3(n+1).$$
So altogether
$$E[Z] = 3E[N+1] = 3E[N] + 3 = \frac{3}{\alpha}+3$$
where I used that the expected value of a geometric distribution with parameter $\alpha$ is $1/\alpha$.
Comment: Ok I am closely studying this. Only thing I am trying to figure out is where did the variable $k$ go? And to get the variance I would just repeat the steps except find $E[Z^2]$ and then subtract the two together, right?


Print lower triangular packed matrix in Fortran 77

Question: I have a matrix of real*8 numbers saved in an array as a packed lower triangular matrix:
|1  *   *   *   *   *|
|2  7   *   *   *   *|
|3  8  12   *   *   *|
|4  9  13  16   *   *| => [1,2,3,4,5,6,7,8,9...21]
|5 10  14  17  19   *|
|6 11  15  18  20  21|

I want to be able to print it in the following format:
 [row|col]   1  2   3   4   5
     1       1  *   *   *   *
     2       2  7   *   *   *
     3       3  8  12   *   *
     4       4  9  13  16   *
     5       5  10 14  17  19
     6       6  11 15  18  20

 [row|col]   6
     1       *
     2       *
     3       *
     4       *
     5       *
     6       6

The problem I have is that I don't know how to loop into the matrix elements without the need to creating extra arrays to save the elements by columns and then print them. this is what I have tried so far
      Implicit Real*8 (A-H,O-Z)

      INTEGER      ARRAY(21)

      10 Format(5X,'[Row|Col]',5(8X,I6))
      Icol=6
      Num1=1
C     Test array
      DO  K=1,21
      Array(K)=K*1.0d0
      ENDO

C     Print the elements row-by-row.
44    Num2=Icol-Num1
      Num=Num2
      If ((Num2).gt.5) Num=5
      Write(*,10) (I,I=Num1,Num1+Num)
      INum1=INum1+Num
      if (Inum1.ne.Icol) goto 44
      STOP
      END

Comment: Is the 6th column supposed to be separated from the first 5?
Comment: Yes, I want to print 5 columns at the time so they can fit without a problem in my output.
Comment: Please use [tag:fortran] for all Fortran questions to get more attention. Also use some indentetion in yur code to make it readable and consider using some less pre-historic version of Fortran in year 2017. Not the code yu show has syntax errors like `ENDO`. You should show the **real code** [mcve].
Comment: Start by developing a formula to calculate the index in the array of the value to print at a given coordinate in the matrix.
Comment: I doubt you actually need fortran 77, more likely you are just using fixed format input. The answer (which looks fine to me) is *not* fortran 77.
Answer: The key is to identify the formula designating the non-zero elements of the lower triangular matrix. If i and j are running indices for rows and columns respectively, then (j < i) elements will be in the lower triangular part. Here is the code:
PROGRAM print_low_tri_matrix
IMPLICIT NONE
INTEGER :: i,j,n,m,p
REAL ,ALLOCATABLE, DIMENSION(:,:) :: a
REAL, ALLOCATABLE, DIMENSION(:) :: r

n = 6
p = n*(n+1)/2   ! Number of non-zero elements in a lower triangular matrix of size n by n

ALLOCATE(a(n,n),r(p))

DO i = 1, p
        r(i) = i*1.0    ! Array containing the non-zero elements
END DO

m = 1          ! Index tracking the non-zero elements array r
DO j = 1,n
        DO i = 1,n
                IF(j .LE. i) THEN       ! Non-zero indices of the matrix
                        a(i,j) = r(m)
                        m = m + 1
                ELSE
                        a(i,j) = 0.
                END IF
        END DO
END DO

!       Printing the full matrix a - uncomment for checking
!         DO i = 1,n
!                         WRITE(*,*) (a(i,j),j=1,n)
!         END DO

!       Printing the matrix a as needed
DO i = 1,n
        DO j = 1,n
                IF(j .LE. i) THEN
                        WRITE(*,'(F12.4)',ADVANCE="NO") a(i,j)
                ELSE
                        WRITE(*,'(A12)',ADVANCE="NO") '*'
                END IF

                IF (j .EQ. n ) WRITE(*,*)
        END DO
END DO

END PROGRAM print_low_tri_matrix

And the output will be:
1.0000           *           *           *           *           *
2.0000      7.0000           *           *           *           *
3.0000      8.0000     12.0000           *           *           *
4.0000      9.0000     13.0000     16.0000           *           *
5.0000     10.0000     14.0000     17.0000     19.0000           *
6.0000     11.0000     15.0000     18.0000     20.0000     21.0000

Of course, you can change the matrix into an integer array if you wanted.
P.S :- To make this work in f77, you can change the format specifiers as  WRITE(*,'(F12.4)',ADVANCE="NO") a(i,j) to WRITE(*,'(F12.4,$)') a(i,j). The allocations of the arrays should be removed and defined directly.
Comment: One needs to do a lot more than change the `write` statement and dynamic allocation to make this (needlessly) F77-compatible.  And note that `$` editing isn't F77 anyway.
Comment: The OP has asked for fortran 77, which I doubt they actually need. But it might be worth noting that your code is not F77 compliant.
Comment: @Ross, Yes, you are right. I forgot to make it f77 standard. But I hope the OP can modify this appropriately. I will add a note in the answer.


cookies not being deleted

Question: I have a basic login system. The basic login / logout functions are as follows:
function login() {
    global $page;

    if ($_COOKIE['adminUser'] == adminUser && $_COOKIE['adminPass'] == adminPass):
        $_SESSION['adminLogin'] = true;
        redirect($_SERVER['REQUEST_URI']);
    elseif ($_POST['adminUser'] == adminUser && $_POST['adminPass'] == adminPass):
        setcookie('adminUser', $_POST['adminUser'], time() + 60 * 60 * 24 * 7);
        setcookie('adminPass', $_POST['adminPass'], time() + 60 * 60 * 24 * 7);
        $_SESSION['adminLogin'] = true;
        redirect($_SERVER['REQUEST_URI']);
    else:
        $page->content->table = new template('admin/login.tpl');
        // it shows the login form
    endif;
}

    function logout() {
        $_SESSION['adminLogin'] = false;
        setcookie('adminUser', false, time() - 60*100000);
        setcookie('adminPass', false, time() - 60*100000);
        redirect(pathApp);
    }

redirect($x) is header("Location: $x"); die;.
No other COOKIES are being set anywhere in the entire script.
The problem is that the logout function is not working. I tried to debug this via Firebug, to see what headers are being sent and all seems ok to me. Here is Firebug's log for logout:
Response Headers

HTTP/1.1 200 OK
Date: Fri, 15 Apr 2011 18:48:57 GMT
Server: Apache
X-Powered-By: PHP/5.2.13
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: adminUser=deleted; expires=Thu, 15-Apr-2010 18:48:56 GMT
adminPass=deleted; expires=Thu, 15-Apr-2010 18:48:56 GMT
Content-Length: 1041
Connection: close
Content-Type: text/html

Request Headers

GET /freeads/admin/logout HTTP/1.1
Host: clienti.bsorin.ro
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:18.104.22.168) Gecko/20110303 Firefox/3.6.15
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://clienti.bsorin.ro/freeads/admin
Cookie: adminUser=q; adminPass=q; PHPSESSID=22faf6e20467b88d97dc7838572cbd47

The script is live at http://clienti.bsorin.ro/freeads/admin. Username and password are both set to 'q'.
Thanks!
Comment: Don't use relative time values for deleting cookies. It assumes the client's clock is accurate, which is not always the case. For deleting cookies, always use a fixed "ancient" date, like Jan 1/1970 00:00:01. And please tell me you're not storing usernames/passwords in that cookie... please please please tell me you're not.
Comment: @Marc: at this point I am storing username / password in the COOKIE. Don't worry though, it definitely is not final. I thought `time() - 60` is actually sending the server time (- 60). I tried it like `setcookie('adminUser', false, 1)` but still no luck.
Answer: It seems the system was flawed to start with because I didn't set up the cookies properly. I didn't use the path parameter. The cookies were being set at /path/login and were being deleted at path/logout.
The correct way would have been to change both setcookie() command pairs (login & logout) to:
setcookie('adminUser', $_POST['adminUser'], time() + 60 * 60 * 24 * 7, '/');
setcookie('adminPass', $_POST['adminPass'], time() + 60 * 60 * 24 * 7, '/');

setcookie('adminUser', false, time() - 60*100000, '/');
setcookie('adminPass', false, time() - 60*100000, '/');

Notice the fourth parameter, path, being set to /. Took me a while but I figured it out :).
Answer: I noticed that you are using a sub-domain. setCookie has a fifth parameter that will specify the domain. It is tricky with sub-domains to delete cookies. This worked for me
setCookie("clockInTime", $param, date('U')+86502,'/', '.mywebsite.com')

The last param will pick up any and all sub-domains of mywebsite using the '.' before the domain.
Answer:
check you're not sending any headers before using setcookie.
change your conditionals to use curlybraces (I beg you)
make sure you're setting the cookies/deleting them on the same domain (and path) try using setcookie($name, $val, $time, '/');

I can see the following error when logout is called.

  DEBUGGING:
  [class_dispatcher.php : 26] [scalar
  [integer / float / string / boolean]]
  page->content is not of class
  'template'

This is most likely the cause - as it's being outputted BEFORE setcookie is called.
Comment: I must have been saving the file at the time. Also, why point number 2? (about the curly braces). Thanks!
Comment: The most prominent PHP coding standards all recommend curly braces: http://pear.php.net/manual/en/standards.control.php
Do you really not see why?
Answer: You can change cookie's expiry time using setcookie().
Important: Expiry time of cookie must be update before any data is sent to the browser because browser identifies a cookie and stores it based on headers sent from the server to the browser, so you must use setcookie() before headers for updating cookie expiry time
Answer: The issue in my case, is that when I made the request to the backend using the fetch api, I forgot to set the credientials parameter to 'include'. {credentials: 'include'}

cookies not being deleted


Changing UIStatusBarStyle to LightContent (white) not working in Swift

Question: I am having a lot of trouble trying to change the status bar color to white in Swift. I have checked all the questions related to this here and non of the solutions seem to work properly. Right now I'm using the key in info.plist: "View controller-based status bar appearance" set to NO. In my AppDelegate.Swift I have:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)
    return true
}

The bar is white now but I have an error in the console:

Error: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.*

Has anyone managed to figure out how to do this cleanly? Any tips would be really appreciated!
Answer: If you want a light content style across your entire app, you don't need code. You've already changed "View controller-based status bar appearance" to NO, so now all you need to do is select your project in the project navigator pane, then choose the General tab and look for the Status Bar Style dropdown – it's in the Deployment Info section, just underneath Device Orientation.
As you can see in the screenshot below, just change that to be Light and you're done.
Comment: This works, I have removed the code from the AppDelegate.swift however I'm still getting those errors in the console.
Comment: I'm glad it works; please mark the answer as correct so others can find it easily! If the error is still there, a) it's possible there's something else in your code that's causing it (not your status bar), or b) it's an Apple problem. Apple does have a tendency to leave strange error messages in, which can be quite confusing.
Comment: I don't have any other code yet. If I don't have the key in the plist then the bar stays black. If the key is in the plist it works but I'm getting that error message...seems strange
Answer: This question has a deprecated answer.
'setStatusBarStyle(_:animated:)' was deprecated in iOS 9.0: Use -[UIViewController preferredStatusBarStyle]
Use like this:
override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}


Sinon spy with a Promise not being called

Question: The test (below) for this piece of code is failing:
module.exports = function(User, jwt) {
  'use strict';

  return function(req, res) {
    User.create(req.body)
    .then(function(id) {
      var token = jwt.sign({id: id});
      res.json({token: token});
    });
  };
};

Here is the test:
'use strict';
var chai = require('chai');
var sinon = require('sinon');
require('sinon-as-promised');

chai.should();
chai.use(require('sinon-chai'));

describe('routes/signup', function() {

  var User;
  var request;
  var response;
  var jwt;
  var signup;

  beforeEach(function() {
    User = {create: sinon.stub()};
    request = {body: 'body'};
    response = {json: sinon.spy()};
    jwt = {sign: sinon.stub().withArgs({id:'id'}).returns('token')};
    signup = require('../../../routes/signup')(User, jwt);
  });

  it('returns token when resolving', function() {
    User.create.resolves('id');
    signup(request, response);
    return response.json.should.have.been.calledWith({token: 'token'});
  });
});

If I interrogate the response.json method it appears to have never been called. response.args is an empty array.
I'm guessing I'm missing something fundamental with testing promises. Help!
Answer: Remember promises are async, so you need to wait until the promise resolves and then call then method to do your assertions. fr0609's answer will give you a false positive because it will return before the then block is ever called.
Try this:
it('returns token when resolving', function(done) {

  User.create.resolves('id');

  signup(request, response)
    .then(function() {
      response.json.should.have.been.calledWith({token: 'token'});
      done();
    })
    .catch(done);
});

Comment: also consider checking out [chai-as-promised](https://github.com/domenic/chai-as-promised/) :)


How does boosting work?

Question: What is the easiest way to understand boosting?
Why doesn't it boost very weak classifiers "to infinity" (perfection)?
Answer: In plain English: If your classifier misclassifies some data, train another copy of it mainly on this misclassified part with hope that it will discover something subtle. And then, as usual, iterate. On the way there are some voting schemes that allow to combine all those classifiers' predictions in sensible way.
Because sometimes it is impossible (the noise is just hiding some of the information, or it is not even present in the data); on the other hand, boosting too much may lead to overfitting.
Answer: Boosting employs shrinkage through the learning rate parameter, which, coupled with k-fold cross validation, "out-of-bag" (OOB) predictions or independent test set, determine the number of trees one should keep in the ensemble.
We want a model that learns slowly, hence there is a trade-off in terms of the complexity of each individual model and the number of models to include. The guidance I have seen suggests you should set the learning rate as low as is feasibly possible (given compute time and storage space requirements), whilst the complexity of each tree should be selected on basis of whether interactions are allowed, and to what degree, the more complex the tree, the more complex the interactions that can be represented.
The learning rate is chosen in the range $[0,1]$. Smaller values ($<0.01$) preferred. This is a weighting applied to each tree to down weight the contribution of each model to the fitted values.
k-fold CV (or OOB predictions or independent test set) is used to decide when the boosted model has started to overfit. Essentially it is this that stops us boosting to the perfect model, but it is better to learn slowly so we have a large ensemble of models contributing to the fitted model.

How does boosting work?


Interchange the order of integral and derivative

Question: I am just wondering when we can interchange the order of the integral and derivative. And the following is the formal version of my question.
$$\partial_x \int f(x,y)dy = \int \partial_x f(x,y) dy$$
I already know the case if the integral is on a bounded set, then f is $C^1$ can definitely induce the above equation. I am curious if the integral is not just on a bounded interval, and what should be the constraint to have this equation? Like can $\partial_x f(x,y) \in L^1$ induce the equation?
Comment: This holds if there exists a dominating function $g$, i.e. $|\partial_x f(x,y)|\le g(y)\in L^1$.
Answer: The most general theorem is in the context of Lebesgue integration:

Let $X \subseteq \mathbf R$ be an open subset, $(\Omega,\mu)$ a measure space and $f:X\times \Omega\longrightarrow\mathbf R$ a map with the following properties:

For each $x\in X$, the function $\;t\longmapsto f(x,t)$ is Lebesgue-integrable,
The function $x\longmapsto f(x,t)$ is differentiable for almost all $t\in\Omega$,
There exists a Lebesgue-integrable function $\varphi:\Omega\longrightarrow\mathbf R $ such that for  each $x\in X$ and almost all $t\in \Omega$,
  $$\smash[t]{\left|\frac{\partial f(x,t)}{\partial t}\right|}\le \varphi(t).$$
  Then the function $F:x\longmapsto \displaystyle\int_{\Omega} f(x,t)\,\mathrm d\mu(t)$ is differentiable on $X$, and its derivative is
  $$F'(x)=\int_\Omega\frac{\partial f(x, t)}{\partial x}\,\mathrm d\mu(t).$$
Answer: What you're seeking might be a special case of the Leibniz Integral Rule, which tells you that
$$\frac{d}{dx}\int_{a(x)}^{b(x)}f(x,y)dy=f(x,b(x))b'(x)-f(x,a(x))a'(x)+\int_{a(x)}^{b(x)}\frac{\partial}{\partial x}f(x,y)dy.$$
In the case that $a(x),b(x)$ are constant with respect to $x$, then of course $a'(x)=0$, $b'(x)=0$, and we're left with the last term, and we conclude that the integral and derivative signs may be exchanged.


Why doesn't the signature of a method contain the return type?

Question: Let's say you have an overloaded method. Would the signature contain the return type? If not, why?
Comment: Give a sample method?
Comment: possible duplicate of [Why is the return type of method not included in the method-signature?](http://stackoverflow.com/questions/13314316/why-is-the-return-type-of-method-not-included-in-the-method-signature)
Answer: The signature doesn't contain a return type. Why? I will give some examples: let's say you have two methods:
int someMethod(int x) {...}

double someMethod(double x) {...}

If you tried to call that method as
System.out.println(someMethod(10));

the parameter types will be evaluated to call the correct method. Now let's say you have:
int someMethod(int x) {...}

double someMethod(int x) {...}

when you call it as someMethod(10), Java won't know what method to call. This is why what matters is the list of parameters and not the return type.
Comment: This Java behaviour isn't very flexible, see my example from Swift language in the neighbouring topic http://stackoverflow.com/a/28079432/407986
Answer: From Oracle Definition

Definition: Two of the components of a method declaration comprise the
  method signature—the method's name and the parameter types.

Then Method signature contains method name and parameter list only not the return type.
public             String         myMethod(String myInput)

^access modifier   ^return type   {^method name    ^parameter list}

inside { } part is the method signature.
Comment: Yes. My question is why doesn't the method signature contain the return type? Isn't that an integral part of the method?
Comment: @priya No. method signature doesn't contains return type
Comment: @priya it is the design of Java.
Answer: In the concept of method overloading return type  is doens'nt matter at all. Method name must  be same. That's it.
Both the methods may or not have a return type or any one method may void.


How to specify the period during which the remaining-time-label is updated in Inno Setup?

Question: I wanted to show remaining time during an installation like in the following question and used the code from there, posted by TLama: How to show percent done, elapsed time and estimated time progress?
The code is working for me, so thanks for this.
But if you install bigger files, the period in which the "remaining-time-label" is updated, is too fast.
So I wanted to ask, how to change the update period of the "remaining-time-label", so that it updates only every second or every half second.
Thanks in advance
Answer: Use GetTickCount to remember the last update time. On the next calls to CurInstallProgressChanged calculate difference to CurTick and update the labels only if the difference is large enough (1000 = 1 second)
var
  LastUpdate: DWORD;

procedure CurInstallProgressChanged(CurProgress, MaxProgress: Integer);
var
  CurTick: DWORD;
begin
  CurTick := GetTickCount;
  if (CurTick - LastUpdate) >= 1000 then
  begin
    LastUpdate := CurTick;
    // Update labels
  end;
end;

Comment: Thank you very much, that works for me. Didn't expect it to be that easy, feeling really silly now...


C: Call close() in if condition

Question: Generally,
I read lot of code which always used following snippet to check if close fd successfully
// code A
int result = close(some_fd);
if ( result == -1)
  perror("close error");

I'd like to simplify above code
//code B
if ( close(some_fd) == -1 )
  perror("close error");

Above snippet can be executed and if has error,
then "close error" also can be display normally.
AFAIK, if (conditions) which conditions will be r-value,
so that should mean ( close(some_fd) == -1 ) just temporary
Dose close(some_fd) really execute normally when I call it in if condition?
Comment: What do you mean with "just temporary"?
Comment: Both are correct and are executed normally, you can use the first option if you need to use the return value from close() later, but it's only zero or -1, so the second one is more practical.
Comment: Yes, why wouldn't it?
Comment: Hi @klutt: yes,I mean  with "just temporary"
Comment: I'm sorry, but I really don't understand what you mean.
Comment: I've modified my article, my question is "Code A" equivalent to "Code B"?
Comment: Hi @AlbertoPires: Ok, I got it. Thanks very much. Could write your message to answer?
Answer: You can safely invoke close inside the if.
In fact, you're a right when you say that the r-value is temporary, as it represents a value which is stored into a temporary memory address, just used to be assigned to a l-value.
However, in your case, what it's stored "temporarly" is the whole condition value, which means the return value of close(fd) fuction comparared to -1. Therefore, the close will be executed as expected, and its effects is not temporary.
Answer: Both are correct and are executed normally, you can use the first option if you need to use the return value from close() later, but it's only zero or -1, so in this case the second one is more practical.

C: Call close() in if condition


Python Pandas print Dataframe.describe() in default format in JupyterNotebook

Question: Output format without print function
If I run a JupyterNotebook cell with
dataframe.describe()

a pretty fromatted table will be printed like that:
VSCode JupyterNotebook dataframe.describe() solo cell printing format
Output format with print function
If I run a cell with more than just one line code dataframe.describe() would not print anythink. Therefore I need to call
print(dataframe.describe()).

This leads to a totally different formatting though:
VSCode JupyterNotebook printing dataframe.describe() with print function
Is there a way to print dataframe.describe() in the first format?
Answer: There are multiple things to say here:

Jupyter Notebooks can only print out one object at a time when simply calling it by name (e.g. dataframe). If you want, you can use one cell per command to get the right format.

If you use the function print, it will print anything as text because print is using the function to_string for any object it gets. This is python logic - in contrast, option 1) is Jupyter-specific...

If you don't want to use a seperate cell and still get the right formatting, there are several options, one might be this:
from IPython.display import display
display(dataframe)

Answer: I assume you are using the same jupyter notebook files in both environments.
If that is the case, the problem you are facing is related to the execution order of the steps defined in the notebook itself, as the output of the code cell itself will be the one of the execution of the last line of the cell.
Let me illustrate you with an example.
Having the defined the following a dataframe in pandas:
data = {'id':[1,2,3,4],'nome':['Paolo','Pietro','Giovanni','Maria'],'spesa':[23.4,34.5,99.2,50.1]}

The output of the following cell would be different between this two cases:
# Outputs the dataframe itself
dataframe1 = pd.DataFrame(data)
dataframe1.describe()
dataframe1

# Outputs the describe() function return value
dataframe1 = pd.DataFrame(data)
dataframe1
dataframe.describe()

Both cells execute the same two lines on the dataframe without changing its internal state, however, only the last line will be written to the cell output.


can its possible to make for loop for array of objects, removing duplicate and add the values which consists of same user

Question: I have a array of objects, inside every object user and value(value
      consist of array). This has to minimize to remove duplicate users and
      add data to array of values.
      ex---------

      [ { user: 'VAY9090', value: [ 'KL65' ] },
      { user: 'VAY9090', value: [ 'KL6I' ] },
      { user: 'VAY9092', value: [ 'KLMF' ] },
      { user: 'VAY9092', value: [ 'KLMQ' ] },
      { user: 'VAY9090', value: [ 'KLMR' ] },
      { user: 'BTD9891', value: [ 'KLMS' ] },
      { user: 'VAY9090', value: [ 'KLVZ' ] },
      { user: 'VAY9033', value: [ 'KMYJ' ] },
      { user: 'BTD9891', value: [ 'KMYK' ] } ]

      convert to

      [

     { user: 'VAY9090', value: [ 'KL65','KL6I','KLMR','KLVZ' ] },
     { user: 'VAY9092', value: [ 'KLMQ','KLMQ' ]},
     { user: 'BTD9891', value: [ 'KLMS','KMYK'] },
     { user: 'VAY9033', value: [ 'KMYJ' ] }
     ]

Comment: I'm voting to close this question as off-topic because i cant see any research effort, not even a try to solve this.
Comment: @raghunandan have you tried searching on Google and Stack Overflow for the answer to your question? If so, please tell us what you have found and why it didn't help you solve your problem.
Comment: many for loop helped me from stack over flow, but my scenario is different so could solve that problem, so took help from posting the data..!! and new to this kind of for loop and all..!!
Answer: You could try something like this:

var data = [
  { user: 'VAY9090', value: [ 'KL65' ] },
  { user: 'VAY9090', value: [ 'KL6I' ] },
  { user: 'VAY9092', value: [ 'KLMF' ] },
  { user: 'VAY9092', value: [ 'KLMQ' ] },
  { user: 'VAY9090', value: [ 'KLMR' ] },
  { user: 'BTD9891', value: [ 'KLMS' ] },
  { user: 'VAY9090', value: [ 'KLVZ' ] },
  { user: 'VAY9033', value: [ 'KMYJ' ] },
  { user: 'BTD9891', value: [ 'KMYK' ] }
];

var convertedData = convert(data);

console.log(convertedData);

function convert(data) {
  var result = [];
  var obj = {};

  data.forEach(function(item) {
    obj[item.user] = obj[item.user] || {
      user: item.user,
      value: []
    };

    obj[item.user].value = obj[item.user].value.concat(item.value);
  });

  for(var i in obj) {
    result.push(obj[i]);
  }

  return result;
}
Comment: Thanks buddy..!! Its working fine


I m trying to compute the series $\sum_{n=1}^{\infty}\frac{1}{ne^{n}}$ Thanks for the help!

Question: I m trying to compute the series $\displaystyle \sum_{n=1}^{\infty}\frac{1}{ne^{n}}$
Thanks for the help!
Comment: We know $\ln (1-x)=-\displaystyle\sum_{n=1}^\infty \dfrac{x^n}{n}$. Now put $x=\dfrac{1}{e}$ (why can you do that?). So the answer is $1-\ln(e-1)$.
Answer: Can you sum the geometric series $\displaystyle \sum_{n=1}^{\infty}\frac{1}{e^{an}}$?  Integrate both sides with respect to $a$, then set $a$ to $1$.
Comment: Actually, you want to integrate, because $n$ is in the denominator.
Comment: @RobertIsrael:  Right you are.  Thanks.
Comment: Would it not be better to leave this answer as a comment? Because the OP may get a wrong message that posting a question with no context (although downvoted) is answered anyway.


Spring Boot Application failed to start because of missing bean

Question: How I "solved" it:
The initial problem was that I forgot to change the package name in the main class that launches the application:
@EnableJpaRepositories(basePackages = {"com.sda.VictorLiviu.ecommerce.jparepository"})

After that I just instanced itemMapper as a normal class in ItemService like this:
ItemMapper itemMapper = new ItemMapper();

and than used its toEntity method as:
itemMapper.toEntity();

. . . . . . . . . . . .
My Spring Boot app says it doesn't have a Bean class which it clearly has. I will post the Pom, service and repository. I want to point out that I have exactly the same class and repository for UserService and OrderService and they don't give any error, the only difference is the @Transactional and I removed it and got the same error.Any suggestions are welcomed!
The Error:
Description:

Field repository in com.sda.VictorLiviu.ecommerce.service.ItemService required a bean of type 'com.sda.VictorLiviu.ecommerce.JpaRepository.ItemRepository' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type 'com.sda.VictorLiviu.ecommerce.JpaRepository.ItemRepository' in your configuration.

POM XML
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/>
    </parent>
    <groupId>com.sda.VictorLiviu</groupId>
    <artifactId>e-commerce</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>e-commerce</name>
    <description>E-commerce website Final Project sda</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>

        <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

ItemService class
    package com.sda.VictorLiviu.ecommerce.service;

import com.sda.VictorLiviu.ecommerce.DtoMapper.ItemMapper;
import com.sda.VictorLiviu.ecommerce.JpaRepository.ItemRepository;
import com.sda.VictorLiviu.ecommerce.exceptions.ItemNotFoundException;
import com.sda.VictorLiviu.ecommerce.model.Item;
import com.sda.VictorLiviu.ecommerce.dto.ItemDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Transactional
@Service
public class ItemService {

    @Autowired
    ItemRepository repository;

    @Autowired
    ItemMapper itemMapper;

    public void add(ItemDto dto) {
        repository.save(itemMapper.toEntity(dto));
    }

    public Item delete(Long id) {
        repository.deleteById(id);
        return null;
    }

    public List<Item> getItems() {
        return repository.findAll();
    }

    public Item getItemById(Long id) {
        Optional<Item> optionalItem = repository.findById(id);
        return optionalItem.orElseThrow( () -> new ItemNotFoundException("Couldn't find the specific item!"));
    }
}

Repository
package com.sda.VictorLiviu.ecommerce.JpaRepository;

import com.sda.VictorLiviu.ecommerce.model.Item;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ItemRepository extends JpaRepository<Item, Long> {
}

Item Class
package com.sda.VictorLiviu.ecommerce.model;

import javax.persistence.*;

@Entity
@Table(name="item")
public class Item {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "item_seq_gen")
    @SequenceGenerator(name = "item_seq_gen", sequenceName = "item_seq", allocationSize = 1)
    @Column(name = "id")
    private Long id;

    @Column(name = "price")
    private double price;

    @Column(name = "name")
    private String name;

    @Column(name = "category")
    private String category;

    @Column(name = "quantity")
    private int quantity;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }
}

ItemDto Class
package com.sda.VictorLiviu.ecommerce.dto;

public class ItemDto {

    private Long id;
    private double price;
    private String name;
    private String category;
    private int quantity;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }
}

Application.properties
logging.level.org.springframework=info

jwt.signing.key.secret=mySecret
jwt.get.token.uri=/authenticate
jwt.refresh.token.uri=/refresh
jwt.http.request.header=Authorization
jwt.token.expiration.in.seconds=604800

spring.jpa..show-sql=true
spring.h2.console.enabled=true

!!!!!!
Image with my packages
Comment: Show the bean class too
Comment: Beans should have `@component` annotation
Comment: @Repository is not required .
Comment: @ThorbjørnRavnAndersen I have an ItemDto and an Item class. ItemDto is a simple class with getters, setters and default constructor while Item has needed annotations such as Id, GeneratedValue, in order to create the table when I run the app. Which one is the bean?
Comment: I think the problem might be in the package where you hold your repository

Check your packages because currently it is 'package com.sda.VictorLiviu.ecommerce.JpaRepository'
Comment: @S.Tushinov I have different packages in ecommerce for different classes such as repository package, dto package, model package, controller package. What would be the problem? I checked that spring asked in the error log exactly for the path I had for those repositories
Comment: @VictorV what is the package in which you keep your 'ItemRepository ' class ? Or in other words do you really have a package called **JpaRepository**
Comment: @S.Tushinov at the bottom of my post I have added an imgur link with my packages. I will re-edit the whole post after I find the sollution because it is a bit messy now.
Comment: can you try using constructor injection instead of field injection? I'm curious if that will change anything. Also, I would recommend going away from using capital letters in package names.
Comment: You could also try deleting the @Repository annotation from `ItemRepository` as it shouldn't be necessary.
Comment: Please post the full `pom.xml`, `application.properties`. Also put `@Table` annotation in the `Item` class and try it.
Comment: Updated pom.xml (posted full) and also posted application.properties and inserted Table annotanion in Item class, still doesn't work. I will talk to someone I know in around 7 hours and I post the sollution if we find any.
Answer: You need to turn on jpa repositories processing.
To do this, annotate your application with @EnableJpaRepositories
Comment: Thank you! I made a new packages some time ago and forgot to modify it in that annotation. Now the error is about my itemDtoMapper, but I will figure it out in a few hours when I meet someone and I will update the post
Comment: @Antonniossss that solves a part of it, the problem is that the app won't start because of a missing bean. Now its another bean that it says its missing. After I fix it I will post the solution and declare it solved. I think its because I went from CRUD Repository to JPA Repository and messed up the project a bit. I will refactor it with my trainer and post solution
Comment: Seems like a different problem.


Trial solution for in-homogenous differential equation with complex numbers

Question: I am trying to solve following:
Now I have to find trial solutions for the particular solutions, however, I struggle here:
The solutions are given in the right order
I have tried to define the homogenous solution first and get to the solution: $y_h=c_0cos(2x)+c_1sin(2x)+c_3xcos(2x)+c_4sin(2x)$. And then I tried to determine the trial solutions taking the multiplicity of solutions into account by comparing. However, I don't get the solution provided above. Especially for the third one.
Comment: This makes no sense. $$q^4+4q^2+16=(q^2+4)^2-4q^2=(q^2+2q+4)(q^2-2q+4)$$ has roots $\pm1\pm\sqrt{3}$ (all sign combinations). Contrary for the given roots in their multiplicity, the characteristic polynomial is $$(q^2+4)^2=q^4+8q^2+16,$$ giving a different middle coefficient.
Answer: $$y^{4} + 4y'' + 16y = b(x)$$
Since the complementary solution is:
$$y_h=c_0\cos(2x)+c_1\sin(2x)+c_3x\cos(2x)+c_4\sin(2x)$$
And given that:
$$b(x)=x\sin 2x$$
We have to first choose a particular solution of the form:
$$y_p=(Ax+B)\sin 2x+ (Cx+D)\cos 2x$$
But since $\sin 2x $ is already part of the homogeneous solution we multiply the solution by x. Then we have $Bx \sin 2x $ and this is also part of the homogeneous solution so we have to multiply our guess by $x^2$. Hence we have:
$$y_p=x^2(Ax+B)\sin 2x+ x^2(Cx+D)\cos 2x$$
For your second question. The guess should be $y_p=at^2+bt+c$. No need to multpily by $t^2$ the guess. It's maybe just a mistake. Since we have:
$$(r^2+1)(r-1)^2=0$$
The differential equation is:
$$y^{(4)}-2y'''+2y''-2y'+y=0$$
The inhomogeneous equation is:
$$y^{(4)}-2y'''+2y''-2y'+y=2t^2+1$$
Here is the solution provided by Wolfram WA solution
So that the particular solution is:
$$y_p=2t^2+8t+9$$
And the homogeneous solution is:
$$y_h=c_0e^x+c_1xe^x+c_3\cos(x)+c_4\sin(x)$$
It's a polynomial of degree two not four as written in your book.
Comment: Hey, thank you for your answer. The first part is very clear to me now. And actually your answer for the second problem does match my own solution. I don't know how they get to $t^2$. And thank you for the Wolfram link. I didn't know it existed. Btw, I stumbled upon another set of question. I tried to solve them. Do you mind to take a look in the answer section?
Comment: @randomname, you're welcome. The $t^2$ is just a typo. Yes you can post them .
Comment: thank you so much :) I have just posted them. Let's find out what' wrong with my solution.
Answer: $$y_t+4y_{t-2}+16y_{t-4}=b_t$$
You are given the solution $z=\pm 2i$ with multiplicity two.
The module of z is $|z|=\sqrt {2^2+0^2}=2$. We can deduce the angle since we have $\dfrac {z}{|z|}=i\implies \phi = \dfrac {\pi} 2$. Therefore the solution to the homogeneous difference equation is:
$$y_h=\color{red}{2^t }\left(c_1 \cos(\frac {\pi}2t)+c_2 \sin(\frac {\pi}2t)+c_3 t\cos(\frac {\pi}2t)+c_4 t\sin(\frac {\pi}2t) \right)$$
You can deduce why you have to multiply by $t^2$ in the third option and why you don't have to multiply for the first and second option. Do you get it ?
Comment: Wow, thank you. In this case now everything is quite clear! But then the solutions of my reasoning to the original problems of this thread would be wrong.
Comment: YW.  Your solution wasn't correct thats why. @randomname Your reasoning for the first problem the differential equation is correct. It's the solution in the second problem the difference equation that is wrong.
Comment: Ah okay. So it does make a difference whether it is a solution of a difference or differential equation. I will try to remember that I have to redefine the angle and radius when it comes to a difference equation. Thanks a lot.
Comment: You're welcome. Good luck for your exam @randomname


MSEP error derivation

Question: I have random variable $X$ and set of observations $\mathcal{D}$. Let $\widehat{X}$ be an estimator for $E[X|\mathcal{D}]$ and predictor for $X$. Mean square error of prediction MSEP is defined as
$$
msep_{X|\mathcal{D}} = E[(\widehat{X} - X)^2|\mathcal{D}]
$$
In the book it says also
$$
msep_{X|\mathcal{D}} (\widehat{X}) = Var(X|\mathcal{D}) + (\widehat{X} - E[X|\mathcal{D}])^2
$$
and I do not know how to get this.
I thought it would go through with variance formula, where I set
$$
msep_{X|\mathcal{D}} = E[(\widehat{X} - X)^2|\mathcal{D}] = Var(\widehat{X} - X|\mathcal{D}) + E[(\widehat{X} - X)|\mathcal{D}]^2
$$
but I could not proceed.
Any help would be great.
Answer: I assume you mean that $E\left[ {\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X}} \right]=E\left[ X|D \right]$.
So first, note that if $E\left[ XY|D \right]<\infty $ and $X,Y$ are both measurable with respect to $D$, then $E\left[ XY|D \right]=YE\left[ X|D \right]$.  Now, by definition:
     $MS{{E}_{{{P}_{X|D}}}}\left( {\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X}} \right)=E\left[ {{\left( X-\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X} \right)}^{2}}|D \right]=E\left[ {{X}^{2}}|D \right]-2\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X}E\left[ X|D \right]+E\left[ {{{\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X}}}^{2}}|D \right]$.
Also by definition (of the conditional variance), we get
     $E\left[ {{X}^{2}}|D \right]=\operatorname{Var}\left( X|D \right)-{{E}^{2}}\left[ X|D \right]$.
Putting it together, using the fact that $E\left[ {\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X}} \right]=E\left[ X|D \right]$ implies $E\left[ \overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X}|D \right]=\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X}$:
     $MS{{E}_{{{P}_{X|D}}}}\left( {\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X}} \right)=\operatorname{Var}\left( X|D \right)+{{\left( \overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X}-E\left[ X|D \right] \right)}^{2}}$.
(Since ${{\left( \overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X}-E\left[ X|D \right] \right)}^{2}}={{E}^{2}}\left[ X|D \right]+{{\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X}}^{2}}-2\overset{\lower0.5em\hbox{$\smash{\scriptscriptstyle\frown}$}}{X}E\left[ X|D \right]$).
Comment: There is no assumption on unbiasedness - therefore I do not know if $E[\widehat{X}] = E[X|\mathcal{D}]$. But thanks anyway for this

MSEP error derivation


24 Port Switch versus 4 x 8 Port Switch

Question: While prices for switches in the end-customer sector are decreasing, I found that 24 port switches are much more expensive than multiple 8 port switches with the same speed.
Are there any disadvantages by using four 8 port switches and connecting them instead of a single 24 port switch, except of a slightly higher latency?
edit: (Hopefully obviously,) I am not going to configure a server centre. I just work for a non-profit organization (in my freetime, so I am not professional), and they need to connect a bunch of computers in the same room to another room with an active directory server.
Comment: Not to forget: 4x8 Ports do not sum up to 24 Ports since you need to dedicate more ports as uplink.
Answer: Doesn't sound like professional networking... however:
A 24 port switch offers (about) the given speed between any two ports simultaneously. If switches are connected (at normal speed) then the bandwidth between all ports on the first switch and all ports on the second is limited to that of a single connection.
Depends on the traffic. In the best case there is no difference, in the worst case bandwidth drops to 1/7th. And if you cascade four switches this can get really evil.
Comment: Thanks for the answer. Indeed, we just need a fast connection to a server (for copying images and user profiles) and some slow connections to the clients. While the clients do not really communicate between each other, four small switches might be the apposite answer for my, admittely, very squishy question.
Comment: +1. All depends on how you connect them. 10g uplink? forget it. Traffic between two computers may overload the uplinks to the 4th (main) switch. For office cabling LIKELY good enough. Backbone? Forget it.
Answer: How about reliability? Disrupting a single link would leave 3/4 of your users in the dark, unless you are using 8-port switches which would implement STP so you could create a ring topology for switch interconnects:
<code>sw1 ---- sw2
 |        |
 |        |
sw3 ---- sw4
</code>
But then again, your main argument of cost-efficiency is moot as STP-capable managed switches are expensive even in their 8-port variants.
Also, the available bandwidth would be less than what you could expect from an integrated 24-port switch where the backplane is usually rated as non-blocking, allowing full-duplex wire-speed transfers for all ports simultaneously. If all you connect to is a single server (using a single link), this would not matter much performance-wise though.

24 Port Switch versus 4 x 8 Port Switch


how to prevent a "div" tagged to the first dropdown menu from hiding itself once I select an option on second dropdown menu on the same page

Question: I'll try to explain as best as I could on the issue I am facing.
Basically there are 3 dropdown menus dropDownGroup1, dropDownGroup2, and dropDownGroup3 on the same page, where once a user selects an option from for example, dropdownGroup1 a div that is tagged to the selected option will show.
The problem I'm facing currently is that every time I select an option from the other 2 dropdown menu afterwards , the div that appeared when I selected on dropdownGroup1 hides itself. how do I prevent that from happening. I tried grouping them but the jquery doesn't seem to work.

$(document).ready(function() {
  $("[class^='dropDownValue']").click(function() {
    var inputValue = $(this).attr("value");
    var parents = $(this).parents(".dropDownGroup");
    var targetBox = parents.find("." + inputValue);
    parents.find('.dropdownOptions').not(targetBox).addClass('d-none');
    parents.find(targetBox).removeClass('d-none');
  });
});

    Lorem Ipsum
    <select class="custom-select dropDownValue1">
      <option>Select</option>
      <option value="Option1" id="01">Option1</option>
      <option value="Option2" id="02">Option2</option>
      <option value="Option3" id="03">Option3</option>
      <option value="Option4" id="04">Option4</option>
    </select>

Option1

Option2

Option3

Option4

    Lorem Ipsum
    <select class="custom-select dropDownValue2">
      <option>Select</option>
      <option value="Option5" id="05">Option5</option>
      <option value="Option6" id="06">Option6</option>
      <option value="Option7" id="07">Option7</option>
      <option value="Option8" id="08">Option8</option>
    </select>

Option5

Option6

Option7

Option8

    Lorem Ipsum
    <select class="custom-select dropDownValue3">
      <option>Select</option>
      <option value="Option9" id="09">Option5</option>
      <option value="Option10" id="10">Option6</option>
      <option value="Option11" id="11">Option7</option>
      <option value="Option12" id="12">Option8</option>
    </select>

Option9

Option10

Option11

Option12

Comment: "*hides itself*" - does it?  Or is it your code that's hiding it?  And you need to add an exclusion (like you do for other exclusions already)?
Answer: You can use closest div from your select-box and then use .siblings to hide/show only div where value matches.
Demo Code :

$(document).ready(function() {
  $("select.custom-select").change(function() {
    var inputValue = $(this).val(); //get value
    console.log(inputValue)
    var parents = $(this).closest(".form-group");
    var targetBox = parents.siblings("." + inputValue);
    parents.siblings('.dropdownOptions').not(targetBox).addClass('d-none'); //hide other siblings...
    targetBox.removeClass('d-none'); //show
  });
});
.d-none {
  display: none
}

    Lorem Ipsum
    <select class="custom-select dropDownValue1">
      <option>Select</option>
      <option value="Option1" id="01">Option1</option>
      <option value="Option2" id="02">Option2</option>
      <option value="Option3" id="03">Option3</option>
      <option value="Option4" id="04">Option4</option>
    </select>

Option1

Option2

Option3

Option4

    Lorem Ipsum
    <select class="custom-select dropDownValue2">
      <option>Select</option>
      <option value="Option5" id="05">Option5</option>
      <option value="Option6" id="06">Option6</option>
      <option value="Option7" id="07">Option7</option>
      <option value="Option8" id="08">Option8</option>
    </select>

Option5

Option6

Option7

Option8

    Lorem Ipsum
    <select class="custom-select dropDownValue3">
      <option>Select</option>
      <option value="Option9" id="09">Option9</option>
      <option value="Option10" id="10">Option10</option>
      <option value="Option11" id="11">Option11</option>
      <option value="Option12" id="12">Option12</option>
    </select>

Option9

Option10

Option11

Option12


Batch Normalization decreasing model accuracy

Question: I'm a little confused. I have seen that Batch normalization leads to faster convergence and increased accuracy.
But the opposite is happening in my case. By normalizing, my accuracy actually decreased.
Is there something that I am missing?
Following is the code that I'm using
<code>model = Sequential()
model.add(Bidirectional(LSTM(64 ,return_sequences=True),input_shape=(X_train.shape[1],X_train.shape[2])))

model.add(Conv1D(filters=16, kernel_size=3, padding='same'))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling1D(pool_size=2))

model.add(Conv1D(filters=32, kernel_size=3, padding='same'))
    model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling1D(pool_size=2))

model.add(Conv1D(filters=64, kernel_size=3, padding='same'))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling1D(pool_size=2))

model.add(Dropout(0.3))
model.add(Flatten())

model.add(Dense(150))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(Dropout(0.4))

model.add(Dense(10))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(Dropout(0.4))

model.add(Dense(dummy_y.shape[1],activation = 'softmax'))

model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['categorical_accuracy'])
model.summary()
</code>
Is it the right place for batch normalization or I've done something wrong ?
Answer: Try putting your Batch Normalization layer AFTER activation. Because what it's doing right now is effectively killing off half of your gradient on each layer - you normalize to 0 mean, which means only half of your ReLUs are firing, and you get vanishing gradient.
Comment: You can get away with it if you have residual connections.
Comment: BatchNorm has a $\gamma$ and $\beta$ term that actually do not necessarily make this true.
Comment: Thanks, lugi. It did work and it is converging faster . I wonder why at so many places its used before the activation function.


Flask + Flask-Security + Babel not working

Question: I have setup with Flask + Babel + Flask Security.
Created all translation like this:

root

main.py
translations

ru

LC_MESSAGES

messages.mo
messages.po

In main.py there is part to setup language which executes:
@babel.localeselector
def get_locale():
    user = getattr(g, 'user', None)
    if user is not None:
        print("User locale {}".format(user.locale))
        return user.locale
    # I put here constant to test
    return 'ru'

But http://localhost/login stayed untranslated. Can you please advice where else to dig? No errors in logs even with Debug = True
Comment: I found that translation applies for templates in *templates/* but not for *templates/security/*
Answer: I have found that Flask-Security doesn't work with Babel out of box!
This Pull Request fixes it partially from WTF processing perspective.
To be able to translate Jinja2 templates as well following need to be amended in core.py
def render_template(self, *args, **kwargs):
    # Provide i18n support even if flask-babel is not installed
    # or enabled.
    kwargs['gettext'] = gettext
    kwargs['ngettext'] = ngettext
    kwargs['_'] = _
    return render_template(*args, **kwargs)

Answer: FWIW, with me simply changing my imports to
from flask_babelex import Babel, gettext, lazy_gettext

made it all work fine with Flask-Security.
Answer: You should tell to your app that your use a particular locale. I did that as follows:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_security import Security, SQLAlchemyUserDatastore
from .models import User, Role,
from flask_babel import Babel

app = Flask(__name__)
db = SQLAlchemy(app)

user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore)

babel = Babel(app, 'ru')


I am working on this code of Google maps on codepen

Question: It works perfect on codepen but when I download it to my computer, it doesnt work. I am trying to figure this out for hours, what could be the reason that it works on codepen but not on my computer browser?
I know I am doing something very stupid that I am not realizing. All the other google map code that I have work just fine

  <link rel='stylesheet prefetch' href='https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css'>

    Start (A):

    <input id="start" onchange="calcRoute();" />

    End (B):
    <select id="end" onchange="">

      <option value="sydney, AU">Sydney</option>
      <option value="melbourne, AU">Melbourne</option>
      <option value="-33.751873,150.698227">Penrith</option>

    </select>
    <input type="button" onclick="calcRoute();" />
    Distance:

Comment: https://codepen.io/falak786/pen/MEWyzB
Comment: You can update your post instead of adding comments. Others might important info if you don't.
Comment: What errors do you get on your computer?
Comment: I just noticed that it wasn't working on the mozilla browser only. And it was working on chrome but only partially. Does maps Api v3 has to do anything with it?
Answer: I hope this works, only copy & paste, cheers.

         Start (A):
         End (B):
         <select id="end" onchange="calcRoute();">
            <option value="47.2970596,11.51218330000006">Absam</option>
            <option value="47.52602899999999,11.706817199999932">Achenkirch</option>
            <option value="47.31316,10.998730000000023">Affenhausen </option>
            <option value="47.3990938,11.943168199999946">Alpbach</option>
            <option value="47.2624249,11.462091200000032">Ampass</option>
            <option value="47.20705,10.761870000000044">Arzl im Pitztal
            </option>
            <option value="47.26660109999999,11.895328199999994">Aschau im Zillertal
            </option>
            <option value="47.3112528,11.198198899999966">Auland bei Seelfeld
            </option>
            <option value="47.19569,11.302649999999971">Axamer Lizum</option>
            <option value="47.2303585,11.279548999999975">Axams</option>
            <option value="47.5108796,12.118506600000046">Bad Haring
            </option>
            <option value="47.2970596,11.51218330000006">Bad Tölz über Garmisch</option>
            <option value="47.30548899999999,10.962690000000066">Barwies</option>
            <option value="47.3001526,11.563272299999994">Baumkirchen</option>
            <option value="47.40969,10.748219899999981">Berwang</option>
            <option value="47.15991,9.808210000000031">Bludenz</option>
            <option value="46.7340955,11.288801499999977">Bozen</option>
            <option value="47.50075,9.742309999999975">Bregenz</option>
            <option value="47.1525,15.046010000000024">Breitenbach</option>
            <option value="47.0094541,11.509094199999936">Brenner
            </option>
         </select>
         <button type="button" onclick="calcRoute();">Calculate</button>
         Distance:


Does training with a more difficult task improve model performance on easier tasks?

Question: Say I have a time series deep learning model where I am trying to predict whether an event will end tomorrow and I am using binary classification to do this. If I change the target (or add another one) and predict the duration to the end of the event, which I think is a harder task, or if I use multiclass classification to predict whether the event will end tomorrow, in 2 days or in 3 or more days, will this improve the predictions for the next day's (tomorrow's) events?
Answer: It may well do so, but there is no guarantee. You can construct counterexamples where these approaches will not work, and examples where it will work, and this very probably holds for any such scheme you are thinking about. Whether this works "often enough" in a specific domain is an empirical question.