Matrix with four unknows and three rows (a particular case)

Question: $$\left(\begin{array}{ccc|c}
2&2&1&4.5 \\
4&6&3&12\\
6&9&7&m
\end{array}\right)$$
When I try to solve this, obviously always end up with this $m=x$ term. When you do this wth Gauss, you actually can reach to $y=(459-m)/90$ and $z=(2m-36)/5$, and once you plug $y$ and $z$ in the first equation you get $x=0.75$. Now, when you try to sustitute on the other equations to get $y$ and $z$, always end up with expression like $270=270$ I know it means the system is consistent but  I can´t catch $y$ and $z$.
I also tried to do with cramer and this is what I get:
$\det (M)= 10,  \det(M_{11})= 0.75, \det(M_{12})= 51-2x,  \det(M_{13})=4x-72$
so $x=\det(M_{11})/\det(M)= 0.75, y=(51-2m)/10, z= (2m-46)/2$
What I am missing? This is when I stuck.
Thank´s for all kind of help.
Comment: No, all the "x´s" terms are positive. G. elimination is about get a a matrix with one´s in the diagonal right and zeros in the rest right? I already tried and is worst because you all in terms of "m"
Answer: Your solution is spot on with Gauss.
Yes, you always get $x = 0.75$ as fixed.
$y$ and $z$ have a "free" variable that you can set to "any' value you like. For example, choose $m = 0$ and $y = \dfrac{459}{90}$ and $z = -\dfrac{36}{5}$.
Now, when you sub those values in, of course each side should equate.
If you had shown this using Gaussian Elimination, you would have ended up with:
$$\left[\begin{array}{ccc|c}
      1&   0&   0&  0.75\\
      0&   1&  0&  5.1 - 0.2m\\
      0&  0& 1&  0.4m-7.2
    \end{array}\right]$$
It is best to leave the solution showing that you have 'free' variables.
Comment: oh! in the D. LAY book says that!. Thank´s. It is a homework from school and some of my friends reach to m=12.5.....may be they do what youre saying. thank you
Comment: You can certainly choose $m = 12.5$, but recall, you would write the solution in general form showing that you have a 'free' variable that can be anything at all! I showed the simplified GE form. Regards
Comment: Thank´s a lot ! it was trivial . And thank U very much indeed for the simplified form.
Comment: Is when the mark turns green right? sorry i´m new in this but I think this is it.
Comment: Nice to be able to verify good work!


Why is this event not happening at the correct time, using schedule?

Question: in my program I wanted to make it so that this a specific code gets triggered at a specific time during the day.
class MainGUI:
    def __init__(self):
        global allTerms
        global itemFinder
        with open("allTermsOut", "rb") as infile:
            allTerms = pickle.load(infile)
        with open("itemFinderOut", "rb") as infile:
            itemFinder = pickle.load(infile)

        self.t_entry = None
        self.d_entry = None
        self.curr_frame = None

        #GUI Start

        schedule.run_pending()
        time.sleep(1)
        self.root = tk.Tk()
        self.term_entry = tk.StringVar()
        self.defn_entry = tk.StringVar()

        self.root.geometry("750x750")
        self.root.title("Rymn")

        # starting screen
        #prompt
        self.prompt = tk.Label(self.root, text = "What would you like to do?", font = ('Arial', 18))
        self.prompt.pack(padx = 10, pady = 10)

        self.frame = tk.Frame(self.root)
        # review button
        practiceButton = tk.Button(self.frame, text = f"Practice terms", font = ('Arial, 20'), command=self.startPractice)
        practiceButton.grid(row = 0, column=0)
        #add button
        addItems = tk.Button(self.frame, text = "Add Items", font = ('Arial', 20), command= self.addItem)
        addItems.grid(row= 0, column= 1, padx = 10)
        #delete button
        deleteItems = tk.Button(self.frame, text = "Delete Items", font = ('Arial', 20), command = self.deleteItems)
        deleteItems.grid(row=0,column=2)
        self.frame.pack()

        # Menu stuff
        self.frames2 = [None, None, None] # creating separate frames
        self.frames = [self.addItem, self.deleteItems, self.startPractice] # storing function for separate frames
        #menu bar
        menubar = tk.Menu(self.root)
        self.root.config(menu=menubar)
        #filemenu stuff
        filemenu = tk.Menu(menubar, tearoff = 0)
        #filemenu.add_command(label = "Home", command = lambda: self.showFrame('home'))
        filemenu.add_command(label = "Reviews Terms", command=lambda: self.showFrame('review'))
        filemenu.add_command(label = "Add Terms", command= lambda: self.showFrame('add'))
        filemenu.add_command(label = "Delete Terms", command= lambda: self.showFrame('delete'))
        menubar.add_cascade(label="Go To", menu = filemenu, underline = 0)

        self.root.mainloop()

I have a method called midnightPrinter which is just a test method:
def midnightPrinter(self):
    print("tis midnight")

Outside of my MainGUI method I have
try:
    schedule.every().day.at("07:55").do(MainGUI.midnightPrinter)
    MainGUI()
finally:
    with open("allTermsOut", "wb") as outfile:
        print("allTerms ", allTerms)
        pickle.dump(allTerms, outfile)
    with open("itemFinderOut", "wb") as outfile:
        print("itemFinders ",itemFinder)
        pickle.dump(itemFinder, outfile)

To run my code and MainGUI method.
The event is not triggered (nothing is printed in my console), at 7:55 AM.
I believe the issue is where I'm placing my code for the schedule:
schedule.every().day.at("07:55").do(MainGUI.midnightPrinter) but I'm just not sure where to put it?
Thanks
Comment: So you want help with a function by showing us your GUI and not the function that is not working ?
Comment: @Thingamabobs I'm sorry I should've been more specific the only schedule code I have in here is the one line in my try function.
```schedule.every().day.at("07:55").do(MainGUI.midnightPrinter)```
Comment: You have to *repeatedly* call `schedule.run_pending()` in order for any scheduled events to be processed - you're currently doing that exactly once per run of your program.  In the context of Tkinter, you CANNOT use the `while True:` loop you see in the module documentation (that would simply lock up the GUI), you will need to call `run_pending()` from a function that constantly reschedules itself via Tkinter's `.after()` method (perhaps every 100 or 500 milliseconds).
Comment: @jasonharper Would I not just be able to put it in my MainGUI class, since that has ```self.root.mainloop()``` which loops the main function?
I added these 2 lines to my mainGUI but still doesn't work
```schedule.every().day.at("15:15").do(MainGUI.midnightPrinter)
        self.root.after(500, schedule.run_pending)```
Comment: The mainloop doesn't loop any code of yours, unless you schedule it with `.after()` or have it in an event binding of some sort.  And `self.root.after(500, schedule.run_pending)` only calls the function once, half a second later - you need a function that reschedules itself, and *also* calls `run_pending()`.
Answer: There are few issues in your code:

it is not recommended (actually should not) call .mainloop() inside class constructor function __init__()
according to document of schedule module, schedule.run_pending() should be called repeatedly.  For a tkinter application, either use .after() or thread.
you need to pass the class function to schedule.do() using an instance of MainGUI class, not the class itself

Below is an example based on provided code:
import tkinter as tk
import schedule

class MainGUI:
    def __init__(self):
        self.root = tk.Tk()
        self.root.geometry("750x750")
        self.root.title("Rymn")

        # starting screen
        #prompt
        self.prompt = tk.Label(self.root, text = "What would you like to do?", font = ('Arial', 18))
        self.prompt.pack(padx = 10, pady = 10)

        self.frame = tk.Frame(self.root)
        # review button
        practiceButton = tk.Button(self.frame, text = f"Practice terms", font = ('Arial, 20'), command=self.startPractice)
        practiceButton.grid(row = 0, column=0)
        #add button
        addItems = tk.Button(self.frame, text = "Add Items", font = ('Arial', 20), command= self.addItem)
        addItems.grid(row= 0, column= 1, padx = 10)
        #delete button
        deleteItems = tk.Button(self.frame, text = "Delete Items", font = ('Arial', 20), command = self.deleteItems)
        deleteItems.grid(row=0,column=2)
        self.frame.pack()

        # Menu stuff
        self.frames2 = [None, None, None] # creating separate frames
        self.frames = [self.addItem, self.deleteItems, self.startPractice] # storing function for separate frames
        #menu bar
        menubar = tk.Menu(self.root)
        self.root.config(menu=menubar)
        #filemenu stuff
        filemenu = tk.Menu(menubar, tearoff = 0)
        #filemenu.add_command(label = "Home", command = lambda: self.showFrame('home'))
        filemenu.add_command(label = "Reviews Terms", command=lambda: self.showFrame('review'))
        filemenu.add_command(label = "Add Terms", command= lambda: self.showFrame('add'))
        filemenu.add_command(label = "Delete Terms", command= lambda: self.showFrame('delete'))
        menubar.add_cascade(label="Go To", menu = filemenu, underline = 0)

        #self.root.mainloop()  # should not call mainloop() here

    # dummy class functions
    def startPractice(self): print("practice")
    def addItem(self): print("add item")
    def deleteItems(self): print("delete items")
    def showFrame(self, frame): print("show", frame)

    def midnightPrinter(self):
        print("this midnight")

# function to call schedule.run_pending() repeatedly using .after()
def schedule_loop():
    schedule.run_pending()
    app.root.after(1000, schedule_loop)

app = MainGUI() # create an instance of MainGUI
schedule.every().day.at("07:55").do(app.midnightPrinter) # use instance instead
schedule_loop()  # start the schedule loop
app.root.mainloop() # start the tkinter mainloop

Comment: Thank you very much, this is my first time using tkinter so I'm very appreciative of all the suggestions!


Application of Plancherel/Parseval

Question: Assuming $u,v\in L^1\cap L^2$, then how do you show that $$\int uv=\int \hat{u}\hat{v}$$
I tried using Plancherel, but didnt give any nice result.
Any ideas/hints?
Thanks
Answer: Hint:
$$uv = \frac{1}{4} ((u+v)^2-(u-v)^2).$$
Apply Plancherel's theorem (twice) and conclude.
Note: In your question, it should read $\int \hat{u} \bar{\hat{v}}$ instead of $\int \hat{u} \hat{v}$.
Comment: @nerd You are welcome. If you find the answer helpful, you can upvote/accept it by clicking on the up arrow/tick next to it.
Answer: Plancherel's Theorem gives
$$
               \int u\overline{v}dx = \int \hat{u}\overline{\hat{v}}ds.
$$
So that gives you
$$
                   \int uv dx = \hat{u}\overline{\hat{\overline{v}}}ds.
$$
And,
$$
          \overline{\hat{\overline{v}}}(s)=\overline{\frac{1}{\sqrt{2\pi}}\int e^{-isx}\overline{v(x)}dx}  =\frac{1}{\sqrt{2\pi}}\int e^{isx}v(x)dx,
$$
which is the inverse Fourier transform, and that means your equality does not hold in general.

Application of Plancherel/Parseval


Achar o item mais vendido juntamente com determinado item

Question: Para explicar, prefiro um exemplo:
Quero descobrir qual item é mais o mais vendido juntamente com o salgado de frango.
Para isso, tentei a seguinte abordagem e falhei miseravelmente por falta de conhecimento técnico:
-Buscar todos cupons (vendas) que contenham o código do salgado de frango [OK]
-Pegar todos itens desses cupons [OK]
-Somar a quantidade individual de cada item que é vendido. O valor mais alto é o resultado.
Tentei usar SQL somente.
A estrutura relevante das tabelas é a seguinte:
Tabela produto
codbarra | descricao
Tabela venda
idvenda | dtvenda
Tabela vdaitem
idvdaitem | vdaitem | codbarra | qtde | dtvenda
Comment: Não tenho a certeza de que a estrutura de tabelas esteja correcta. Parece estar a faltar uma coluna na tabela vdaitem para ligar à tabela venda
Comment: @JeffersonLucas: Sua abordagem está correta e é possível ser implementada de forma modular em T-SQL, através do uso de CTE (common table expression).
Comment: Alguma resposta ajudou a resolver o problema e pode sanar dúvidas similares de outros usuários? Caso positivo não esqueça de marcar a resposta como aceita. Pra fazer isso é só clicar no ✓ do lado esquerdo da mesma (abaixo do indicador de up e down votes).
Answer: Vamos fazer por partes.

Encontrar todas as vendas que contenham o código do salgado de
frango

SELECT v.idvenda,
       v.dtvenda
  FROM venda v
 INNER JOIN vdaitem vi
    ON vi.idenda = v.idvenda
 INNER JOIN produto p
    ON p.codbarra = vi.codbarra
 WHERE p.codbarra = 'CODIGO_BARRA_SALGADO_FRANGO'  -- Aqui substitui pelo valor correto

Usando a query anterior vamos seleccionar os restantes produtos para cada uma das vendas:

;WITH VendasContendoSalgadoFrango AS
(
    SELECT v.idvenda,
           v.dtvenda
      FROM venda v
     INNER JOIN vdaitem vi_frango
        ON vi_frango.idvenda = v.idvenda
     INNER JOIN produto p_frango
        ON p_frango.codbarra = vi.codbarra
     WHERE p_frango.codbarra = 'CODIGO_BARRA_SALGADO_FRANGO'
), RestantesProdutos AS
(
    SELECT vFrango.idvenda,
           vFrango.dtvenda,
           vi.codbarra,
           p.descricao,
           vi.qtde
      FROM VendasContendoSalgadoFrango vFrango
      --Ligar outra vez às tabelas vdaitem e produto, desta vez para obter os restantes produtos to cupon que contem o código do salgado de frango
     INNER JOIN vdaitem vi
        ON vi.idvenda = vFrango.idvenda
     INNER JOIN produto p
        ON p.codbarra = vi.codbarra
       AND p.codbarra <> 'CODIGO_BARRA_SALGADO_FRANGO' -- Nao queremos os detalhes do salgado de frango uma segunda vez
)
SELECT TOP 10 codbarra,
       descricao,
       COUNT(DISTINCT idvenda),
       SUM(qtde)
  FROM RestantesProdutos
 GROUP BY codbarra, descricao
 ORDER BY 4 DESC

Isto irá listar o TOP 10 de vendas, em termos de número de artigos vendidos. Pode comparar isto com o número total de vendas (cupons) para excluir os valores discrepantes (pequeno numero de vendas contendo elevado numero de artigos VS elevado numero de vendas contendo um pequeno numero de artigos)
Comment: só colocaria o top 10 e o group by na segunda query para evitar de selecionar todos os itens na tabela temporaria e depois filtrar. em uma base com muitas vendas isso será um problema de desempenho.
Answer: Fiz algo semelhante a poucos dias, a fim de facilitar a vida do usuário mostrando em primeiro lugar, os itens mais vendidos ao cliente selecionado, em seguida os itens mais vendidos de forma geral. Acredito ser bem próximo da sua necessidade.
Para isso usei o union e coloquei uma coluna para ordenar, para sua situação a query ficaria assim:
with rankVendas as (
select
    codbarra,
    descricao,
    null as qtdVendida,
    0 as ordem
from produto p
where p.codbarra='CodBarraSalgadoFrango'

union

Select top 10
    codbarra,
    descricao,
    sum(vi.qtde) as qtdVendida,
1 as ordem
from produto p
left outer join vdaitem vi on vi.codbarra = p.codbarra
where p.codbarra != 'CodBarraSalgadoFrango'
group by codbarra, descricao, ordem)

Select
    codbarra,
    descricao
from rankVendas
order by ordem, qtdVendida desc;

Answer: Você pode utilizar a função agregada SUM agrupando pelo produto apenas nos itens que tenham nota junto com a descrição "salgado de frango":
SELECT TOP(1) p.descricao,
              SUM(vi.qtde) AS quantidade_total
  FROM venda v
       INNER JOIN vdaitem vi ON vi.idvenda = v.idvenda
       INNER JOIN produto p ON p.codbarra = vi.codbarra
 WHERE p.descricao <> 'salgado de frango'
   AND EXISTS(SELECT 1
                FROM vdaitem vi2
                     INNER JOIN produto p2 ON p2.codbarra = vi.codbarra
               WHERE vi2.idvenda = v.idvenda
                 AND p2.descricao = 'salgado de frango')
 GROUP BY p.descricao
 ORDER BY 2 DESC

Explicação da query:

Utilizamos o JOIN para realizar a junção das tabelas venda, vdaitem e produto. (Note que na sua descrição não existe coluna de vínculo entre a vdaitem e a venda, portanto eu levei em consideração que exista e que se chame idvenda);
Realizamos a restrição no WHERE para impedir que o produto com a descrição "salgado de frango" seja considerada;
Restringimos utilizando o EXISTS as vendas que possuem o item algum item com a descrição "salgado de frango" garantindo assim que estamos pegando todos os registros que não são "salgado de frango" mas possuem vínculo de itens junto ao mesmo;
Agrupamos utilizando a cláusula GROUP BY pela coluna descricao da tabela produto;
Utilizamos a função agregada SUM na quantidade dos itens resultantes;
Ordenamos de forma decrescente (DESC) utilizando ORDER BY pela coluna de ordem 2, que neste caso é a somatória;
Restringimos mais ainda o resultado utilizando a expressão TOP com a quantidade de registros desejados.

TOP
Limita as linhas retornadas em um conjunto de resultados de consulta a um número ou percentual de linhas no SQL Server 2014. Quando TOP é usado junto com a cláusula ORDER BY, o conjunto de resultados é limitado ao primeiro número N de linhas ordenadas; caso contrário, ele retorna o primeiro número N de linhas em uma ordem indefinida. Use esta cláusula para especificar o número de linhas retornado de uma instrução SELECT ou afetado por uma instrução INSERT, UPDATE, MERGE ou DELETE.

SUM
Retorna a soma de todos os valores ou somente os valores DISTINCT na expressão. SUM pode ser usado exclusivamente com colunas numéricas. Valores nulos são ignorados.

EXISTS
Especifica uma subconsulta a ser testada quanto à existência de linhas.

GROUP BY
Agrupa um conjunto de linhas selecionadas em um conjunto de linhas de resumo pelos valores de uma ou mais colunas ou expressões no SQL Server. Uma linha é retornada para cada grupo. As funções de agregação na lista de  da cláusula SELECT fornecem informações sobre cada grupo em vez de linhas individuais.

ORDER BY
Classifica os dados retornados por uma consulta no SQL Server.
Comment: https://pt.stackoverflow.com/questions/129467/query-mix-de-produtos-oracle
Comment: Problema recorrente , software como SAS fazem isto melhor mas muitas vezes a solução tem de vir de SQL mesmo.
Comment: @Motta praticamente a mesma coisa, dei até um upvote lá. Não sabia que o número da coluna no order funcionava no Oracle também
Answer:
Quero descobrir qual item é mais o mais vendido juntamente com o salgado de frango.

A solução proposta nesta resposta segue a lógica definida pelo autor, utilizando CTE (common table expressions) para implementá-la. Considera ainda que existe coluna idvenda na tabela vdaitem, de modo a permitir o relacionamento entre a venda e os itens vendidos.
Eis sugestão para obter o que é solicitado:
-- código #1
declare @CodFrango int;
set @CodFrango= informe o codigo de barra do salgado de frango;

with
VendasComFrango as (
SELECT distinct idvenda
  from vdaitem
  where codbarra = @codFrango
),
VendasPorProduto as (
SELECT VI.codbarra, sum(VI.qtde) as SomaQtde
  from vdaitem as VI
       inner join VendasComFrango as VCF on VCF.idvenda = VI.idvenda
  where VI.codbarra <> @codFrango
  group by VI.codbarra
)
SELECT top (1) VPP.codbarra,
       (SELECT descricao from produto as P where P.codbarra = VPP.codbarra) as Produto,
       somaQtde
  from VendasPorProduto as VPP
  order by VPP.SomaQtde desc;

O código é enxuto, utilizando o mínimo de recursos (memória, principalmente). Por exemplo, a tabela de produtos somente é associada ao final, para obter a descrição do produto.
A variável @CodFrango deve ser declarada da mesma forma que a coluna codbarra da tabela produto.


Need help wiith a Drupal Migration

Question: I have a task to do a Drupal migration and was given a database backup and a backup of all the web files. It was a Drupal 7 site but I have no further information as to what modules and themes were used. I need to get it up and running on Windows IIS6 enviroment with FastCGI and ISAPI Rewrite running with a MySQL 5 backend. This is a staging environment.
I have
1. rebuilt the database in MYSQL from the sql dump
2. unpackaged the web files into the webroot
3. configured settings.php to point to the DB
and all I got was WSOD so I added
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

to the beginning of index.php to get a better handle on errors
I got "Fatal error: Call to undefined function: user_access() in menu.inc"
so I checked the system table but
system.module
node.module
user.module
filter.module
block.module

All check out- with status="1" and correct filepaths in data- e.g. module/system/system.module etc.
I have then tried truncating the cache (went directly in to the DB) and tried
TRUNCATE TABLE cache;
TRUNCATE TABLE cache_block;
TRUNCATE TABLE cache_bootstrap;
TRUNCATE TABLE cache_field;
TRUNCATE TABLE cache_filter;
TRUNCATE TABLE cache_form;
TRUNCATE TABLE cache_image;
TRUNCATE TABLE cache_menu;
TRUNCATE TABLE cache_page;
TRUNCATE TABLE cache_path;
TRUNCATE TABLE cache_token;
TRUNCATE TABLE cache_update;

this caused a slew of PHP Warnings that eventually righted itself as cache started rebuilding.
Am now in state where the page only shows multiple instances of one warning.
Warning: array_merge(): Argument #2 is not an array in theme_get_setting()
(line 1461 of C:\Sites\public_html\includes\theme.inc).

But now having finding any info on how to proceed from here. Apologies as this my first time doing a Drupal migration.Do have a copy of all the original backps so I can start agin from scratch as necessary.
Answer: I would suggest you to use drush and try rebuilding registry using Registry rebuild because there might be modules file path issues (conflicts) while migrating.
After you put all files in place and database imported. try this,

Download Registry rebuild module.
now run drush rr on your drupal installation directory. [ if it is multi-site then your working directory should be inside sites/example.com/ ]

Need help wiith a Drupal Migration


OpenGL texturing

Question: Sorry for the plea for help, but I am frustrated.
I don't know why, but I've never seemed to be able to get texturing to work in OpenGL. I would really appreciate a minimal example, so long as it only uses /gl.h /glu.h and standard C++ libraries. Any other insight would be appreciated.
Sorry for simply asking for you to write up a whole program for me, but I could really use it, since EVERY internet example I have seen uses glut. I can't compile it for some reason, and it is very annoying.
Thanks.
Comment: Then your problem is your inability to compile glut, not the need for someone to hand-code you an example that doesn't use it.
Comment: What OS? Creating a window is platform specific.
Comment: Windows, sorry not to clarify
Comment: I cannot use GLUT tutorials because I don't want to rely on GLUT in my programs.
Comment: Well, texturing is finally working. Thanks for your input.
Answer: You NEED some library or interface to create an OpenGL context (and a window to display it).
GLUT is outdated, but still popular; good options nowadays are GLFW or SDL. I recommend GLFW.
(BTW, why did you even need to compile GLUT? Doesn't it have precompiled binaries for Windows?)
Or you can use system-specific functionality; in your case - WinAPI. However, this is a very tedious process; much unlike the portable solutions which create a window in just one or two lines of code and provide easy input handling.
Once you get your GL window up and running, you can learn texturing (or anything else) from any tutorial. The OpenGL calls will be the same, it doesn't matter how the window was created.
Comment: Again, tried that. It just won't work. I'll just need to keep trying.
Comment: Hm. Try to get [GLFW](http://www.glfw.org) and run any empty GLFW program - the [user's guide](http://www.glfw.org/GLFWUsersGuide27.pdf) has a simple Hello World code. If that works, you can proceed to learning texturing etc; if it doesn't, please describe a specific problem and we'll see what's wrong.
Answer: Here's a good tutorial:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06
This code does not use glut.
Comment: No, but it uses the GLaux library :/
Comment: thats true, I really cannot use that. Its far too old. (Glaux, not the tutorial)
Comment: @Alexander If you've managed to create a OpenGL render context, this tutorial should be trivial to port.
Comment: I've tried and failed, many times. I can never seem to get it right. Hopefully I will figure it all out.
Answer: You need a window manager to create a window, for which you are going to create a context, where you can render your image. You can not do that using standard c++.
It is not clear for which OS you are targeting, but there are cross-platform frameworks, like GLUT, SDL, etc. You can also do it using xlib, if you are on linux.

OpenGL texturing


When is it okay to not use model selection

Question: If I have a model in mind, to ask a very specific question, do I have to do some form of model/variable selection?
There are many papers describing different ways to do model selection, why some are bad, etc. However, I struggle to come across a peer-reviewed paper that discusses when it is okay to not use model selection.
I ask this because I have been asked by a reviewer 'how did I do model selection', and they frame it in a way that suggests that they think it is mandatory. My gut intuition tells me that it is not, but I am wondering if anyone can explain why it is okay not to do it or point me to some text that suggests this.
Comment: Unless someone else decided it for you, you have chosen the model you have chosen, and there is probably some reasoning behind. E.g. it is the only model that is used in your field or maybe the most popular model that almost everyone is using.
Answer: You always do model selection in some ways. You either use statistical methods like optimising AIC or BIC; or you do what everybode else does; or you use some form of theory (could be ad hoc) that tells you which variables are relevant and what is the functional form you are looking at.
The advantages of the first way is that you don't need a good theory. The data "decides". I've seen this approach mainly for prediction exercises. If you care more on the effect of one variable on the other rather than prediction, careful reasoning might be more powerful. For understanding a relationship between two variables it is more important to understand which other variables could confound this relationship rather than maximising the explanatory power of the model. Even if an independent variable adds little to the explanatory power of the model, it can still be an important confounder.
It seems as if you had used the third way. Whether this is seen as appropriate depends a bit on the field. I've seen this mostly in papers that care about a causal relationship between two or more variables. Whether choosing a model based on theory is appropriate depends also on your confidence in the theory you use to set up the model. If your theory is very good it is likely that you coose the right model. There are also mixtures possible. You could explain to the referee why you chose your model, and run alternative models that are at least somewhat resonable as robustness checks.


How to perform cross validation in semi-supervised learning

Question: Suppose in semi-supervised learning, we have labeled set $X_L$ and unlabeled set $X_U$

Is it ok to validate model performance on labeled data only?
How to do cross-validation in transductive learning, in which the test set is $X_U$, which can also be considered as a part of the training data?
While performing label propagation or graph neural networks on graph-based data, should we split all nodes randomly, or preprocess(like finding connected components) first?
Answer: This is a good question, and is in an area where we need more research.  I believe that typically cross-validation or bootstrap resampling do not require inclusion of unsupervised learning steps in repeated loop.  What is the result of unsupervised learning (principal components analysis being a prime example) can be unstable, overfitted, and overinterpreted.  But this instability is in a random direction with regard to the response Y being predicted.  In other words, you may benefit from undersupervised learning, but you can also be hurt by it.  So it is not biased one way or another as it does not optimize prediction of Y.  It tries to optimize how predictors relate to each other.
It is a good idea to bootstrap patterns learning in unsupervised learning (data reduction) to learn about the stability, doing this separately from the Y prediction validation.  And there are some cases where to be confidence in the final predictions you want to include from-scratch data reduction inside the same loop as that used to validate predictive accuracy.
Comment: A new paper was just published that is related to this: https://rss.onlinelibrary.wiley.com/doi/10.1111/rssb.12537?af=R
Comment: In terms of inclusion of the variance from the unsupervised step there are instabilities in unsupervised learning that don't bias model validation, and instabilities that might bias it.  I'd like to better understand how to distinguish the two.
Comment: Yes, me too.  Model selection is a particularly important topic for ML as the models often have a lot of hyper-parameters or structural choices (especially things like deep neural nets) and automated model search is popular.  I prefer the safer approach and view CV as estimating the performance of a method of generating a model rather than of the final model itself, and that means repeating the whole procedure in each fold.  Sometimes it is overkill though.
Comment: I would include the unsupervised steps in each fold of the cross-validation as the variance in the performance due to the unsupervised step should be a component of the uncertainty of the overall performance estimate.
Comment: thanks, that looks like a very interesting/useful paper!


Tomcat log include servlet context

Question: I have a Tomcat instance running several websites. Recently I've been trying to deal with the various error messages that wind up in the Tomcat log file (catalina.out). None of the issues are affecting the websites, but all the noise is making it difficult to see actual problems.
My problem is that frequently the message is being emitted by a library that is used by multiple webapps. Unless a stacktrace is included (which it often isn't) I can't tell which webapp is responsible without a lot of digging.
So the question is, can I somehow configure Tomcat to include the servlet context in the log file? Or perhaps have different log files per context?
Answer: you have different options:

create a tomcat instance for each webapp and configure logging for each instance
use log4j and create different logfiles for each context
you could do the same with commons-logging

here is the documentation for log4j and commons-logging with an example for context-specific logging and here is a short how-to for multiple instances.

Tomcat log include servlet context


WSO2 : rewrite response

Question: I have a problem when rewriting a return flow, I created the point here(WSO2 : Transforming response xml), it's ok.
I try to rewrite my output stream, but when I do the output, the rewritten stream is with all the rest of the stream. I don't just have my rewritten stream.
the mediation is :
<property name="XMLBody"
    expression="$body//soap:Body//generic:xmlpres"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:gce="urn:GCE"
   xmlns:generic="http://www.generix.fr/technicalframework/businesscomponent/applicationmodule/common" type="OM" />

<enrich>
    <source type="property" property="XMLBody" />
    <target type="body" />
</enrich>

<property name="XMLBody2"
    expression="$body//VueTable"  type="OM" />

<enrich>
    <source type="property" property="XMLBody2" />
    <target type="body" />
</enrich>
<foreach expression="$body//JTblViewRow">
    <sequence>
       <payloadFactory media-type="xml">
          <format>

                $1
                <Libelle>$2</Libelle>

          </format>
          <args>
             <arg evaluator="xml" expression="//Cletbl/business_data"/>
             <arg evaluator="xml" expression="//Lib1/business_data"/>
          </args>
       </payloadFactory>
    </sequence>
 </foreach>
 <property name="ContentType" value="text/xml" scope="axis2"/>

out :
<VueTable type="View" name="Table" habctr="true" total_business_row="2" nbline="400" confNbline="400" numpage="1" nbpage="1">
               <JTblView name="JTblView" type="ViewObject" maxfetchsize="999" maxfetchsizeexceeded="false">
N<Libelle>Non</Libelle>

O<Libelle>Oui</Libelle>
</JTblView>
            </VueTable>

Comment: i just want this : NNonOOui
Comment: hello in the foreach , I would like to add an enrich to add my rewrite in a new flow which will be the answer.
I add this before the foreach :

but I don't know how to clone the new format into a child of my property created before.
i try this :

 but not work...
Answer: it's ok now !
<enrich>
        <source type="inline" clone="true">
            <Tables xmlns=""/>
         </source>
         <target type="property" property="Tables"/>
     </enrich>

    <foreach expression="$body//JTblViewRow">
        <sequence>
           <payloadFactory media-type="xml">
              <format>

                    $1
                    <Libelle>$2</Libelle>

              </format>
              <args>
                 <arg evaluator="xml" expression="//Cletbl/business_data"/>
                 <arg evaluator="xml" expression="//Lib1/business_data"/>
              </args>
           </payloadFactory>
            <enrich>
                <source clone="true" xpath="//Table"/>
                 <target action="child" xpath="$ctx:Tables"/>
               </enrich>
        </sequence>
     </foreach>

 <enrich>
        <source clone="true" xpath="$ctx:Tables"/>
        <target type="body"/>
 </enrich>

WSO2 : rewrite response


2 questions about the ring $\mathbb Q[X]/(X^{3}-1)$

Question: I am unable to solve this particular question in Ring Theory. This was asked in a masters exam for which I am preparing .
Let $A =\mathbb Q[X]/(X^{3}-1)$ .
(a) Prove that $A$ is direct product of two integral domains.
(b) Is the ring $A$ isomorphic to $\mathbb Q[X]/(X^{3}+1)$?
I can know by $X^{3}-1$ that now elements would be $ax^2+bx+c$, $a,b,c$ belonging to $\mathbb{Q}$. But I have no clue direct products of which integral domain will make this ring.
Also for 2nd I am having problems in defining a map as $X^3$ will act as -1 in 2nd ring. I don't think map like $\phi( ax^2+bx+c )=px^2 +qx+r$ would work as this map is not $1-1$.
So, can anyone please tell how should I approach both of these problems.
Comment: $x^3-1$ factors over $\mathbb{Q}$ as $x^3-1=(x-1)(x^2+x+1)$. This should give you an idea on what the two integral domains should be.
Comment: If the question had asked you about $\Bbb Z/21\Bbb Z$ instead, how would you have approached it?
Answer: HINT:
(a) Use the Chinese Remainder Theorem, which says that for a ring $A$ and ideals $\mathfrak a,\mathfrak b$ of $A$ such that $\mathfrak a+\mathfrak b=(1)$, $A/\mathfrak{ab}\cong A/\mathfrak a\times A/\mathfrak b$. Furthermore, a quotient ring $\mathbb Q[X]/(f(X))$ is an integral domain iff $(f(X))$ is a prime ideal iff $f(X)$ is irreducible (since $\mathbb Q[X]$ is a PID).
(b) I claim $\mathbb Q[X]/(X^3+1)\to\mathbb Q[X]/(X^3-1):X\mapsto-X$ is an isomorphism. Check all the axioms hold.
Answer: (a) As Kenta S stated, since $1=(x^2-x+1)+x(x-1)$ and $(x^2-x+1)(x-1)=x^3-1$, we have $\langle x^2-x+1\rangle+\langle  x-1\rangle=\mathbb Q[x]$ and so $\mathbb Q[x]/\langle x^3-1\rangle\cong \mathbb Q[x]/\langle x^2-x+1\rangle\times \mathbb Q[x]/\langle x-1\rangle$ by the Chinese Remainder Theorem. Clearly, $x^2-x+1$ and $x-1$ are irreducible. Hence, $\mathbb Q[x]/\langle x^2-x+1\rangle$ and $\mathbb Q[x]/\langle x-1\rangle$ are domains.
(b) Clearly, $\mathbb Q[x]/\langle x-1\rangle\cong \mathbb Q\cong\mathbb Q[x]/\langle x+1\rangle$. Also, $\mathbb Q[x]/\langle x^2-x+1\rangle\cong\mathbb Q[x]/\langle x^2+x+1\rangle$ by $x\to -x$. Hence, $\mathbb Q[x]/\langle x^3-1\rangle\cong \mathbb Q[x]/\langle x^2-x+1\rangle\times \mathbb Q[x]/\langle x-1\rangle\cong \mathbb Q[x]/\langle x^2+x+1\rangle\times \mathbb Q[x]/\langle x+1\rangle\cong\mathbb Q[x]/\langle x^3+1\rangle$.
Comment: $X$ is the same as $x$?
Comment: @E.R. The map $\phi(x)=-x$ is not a ring homomorphism as $\phi(xy)\neq \phi(x) \phi(y)$
Comment: @E.R. Also can you tell which map you used in proving $\mathbb{Q}[x]/$ isomorphic to $\mathbb{Q}$ ?
Comment: What is $y$? Also, for $\mathbb Q[x]/\langle x-1\rangle\cong \mathbb Q$ consider the ring epimorphism  $f(x)\to f(1)$ from $\mathbb Q[x]$ to $ \mathbb Q$ with kernel $\langle x-1\rangle\$.
Comment: @E.R 1 is not equal to $(x^2-x+1)+x(x-1)$ ( first line of your answer) . So , i think you made some mistake
Comment: @E.R can you please reply to my previous comment?


Ler um arquivo TXT, ordenar, e salvar um novo arquivo Java

Question: Estou fazendo um trabalho para a faculdade, e não estou conseguindo ler o arquivo e jogar os dados dentro de um ArrayList para ordenar os dados, abaixo segue como está o meu código até agora
public class Teste {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws FileNotFoundException {
    ArrayList<String> vet = new ArrayList<>();
    String aux = null;
    int i = 0;
    vet.add("nome");
    vet.add("cidade");
    vet.add("estado");
    vet.add("aula");
    vet.add("cifra");

      BufferedReader lerArq = new BufferedReader(new FileReader("Teste.txt"));
      String s;
      int n = 0;
      try{
          while ((s = lerArq.readLine()) != null){
              n++;
          }
          System.out.println(s);
      }
   catch(Exception e){
       System.out.println("Excecao1\n");
   }

    System.out.println("Vetor desordenado: ");
    for (i = 0; i < 5; i++) {
        System.out.println(" " + vet.get(i));
    }
    System.out.println(" ");
    for (i = 0; i < vet.size(); i++) {
        for (int j = 0; j < vet.size()-1; j++) {
            if (vet.get(j).compareToIgnoreCase(vet.get(j + 1)) > 0) {
                aux = vet.get(j);
                vet.set(j, vet.get(j + 1));
                vet.set(j + 1, aux);
            }
        }
    }
    System.out.println("Vetor organizado:");
    for (i = 0; i < vet.size(); i++) {
        System.out.println(" " + vet.get(i));

    }
    int x = 1;
     System.out.println(vet.get(x-1));
}
}

A ordenação está funcionando, só não estou conseguindo usar o FileReader, alguma dica de como jogar os dados para dentro do ArrayList?
Lembrando, os dados contidos no txt são os mesmos do abaixo, 5 palavras, cada uma em uma nova linha.
    vet.add("nome");
    vet.add("cidade");
    vet.add("estado");
    vet.add("aula");
    vet.add("cifra");

Comment: como as palavras estão no ficheiro? separadas por linhas ou na mesma linha? ou isso não é relevante?
Comment: Veja isto, é importante (talvez não para seu problema mas para sempre): http://pt.stackoverflow.com/a/30168/101. A leitura está apresentando algum erro? Ou está imprimindo os dados lidos corretamente e você só não consegue por os dados lidos no `ArrayList`? Eu imagino que esses 5 `add`s foram colocados só para testar, certo?
Comment: ramaral, estão separadas por linha.

bigow, a leitura está dando certo, só não estou conseguindo inserir os dados lidos dentro do meu arraylist, para esse fazer a ordenação.
Comment: Tem um modo de fazer a ordenação sem o arraylist?
Answer: Se as palavras estiveram uma em cada linha, podes usar este codigo:
try(BufferedReader br = new BufferedReader(new FileReader("file.txt"))) {
        String line = br.readLine();

        while (line != null) {
            vet.add(line);
            line = br.readLine();
        }
    }

Comment: acabei esquecendo... estava fazendo outros ajustes. marquei agora!
Comment: o teu código funcionou, consegui fazer a leitura do arquivo, mostrar na tela desordenado, ordenar, e mostrar na tela ordenado. Obrigado!
Comment: se o seu problema foi resolvido pode marcar a resposta como certa...


Let $f(z)= \frac {z^3}{(z+1)(z-2)}$. Find maximal $R$, minimal $r$ s.t. $f$ is holomorphic in $r \lt |z+1| \lt R$. Find $f's$ Laurant Series there

Question: Let $f(z)= \frac {z^3}{(z+1)(z-2)}$. Find maximal $R$, minimal $r$ s.t. $f$ is holomorphic in $r \lt |z+1| \lt R$. Find $f's$ Laurant Series there
So I got $f(z)= \frac {z^2}{3} \cdot \frac {1}{1+z}-\frac {z^2}{3} \cdot \frac {1}{1-\frac {z}{2}}$, which I can develop a Laurant series. However I get that $r=0$ and $R=1$ with this result. Is it correct?
Answer: No, the second is wrong. It's often helpful to substitute $w=z+1$ in this sort of thing, and then you are dealing with easier series to understand. Then we are looking at $r<\lvert w \rvert<R$, and the function is
$$ f(w-1) = \frac{(w-1)^3}{w(w-3)} = \frac{(w-1)^3}{3} \left( \frac{1}{w-3} - \frac{1}{w} \right). $$
The second fraction, after the bracket is multiplied out, is an analytic function of $w$ on $\mathbb{C} \setminus \{ 0 \}$, since you end up with a $1/w$ at the end, as well as a polynomial.
Similarly, the first fraction is analytic on $\mathbb{C} \setminus \{3\}$. Hence the whole expression is analytic on $\mathbb{C} \setminus \{0,3\}$, and the largest annulus of the form specified centred at $0$ containing neither of these is $0<\lvert w \rvert < 3$.


Apache2 reverse proxy seems to intermittently freeze?

Question: Apache2 reverse proxy seems to intermittently freeze when proxying a tomcat web app.
The problem is that every so often (once or twice a day usually after inactivity) when I try to log into this proxied web application it just freezes. The application just freezes indefinitely, no 500 response code... the browser just waits and waits.
If I keep trying to hint the web address from my browser it will eventually just start working again.
Ive tried to reproduce this issue by navigating directly to the web app on tomcat port 8080, but ive never been able to reproduce this without going through the reverse proxy.
Here is my reverse proxy config... any fault finding ideas? thanks
/etc/apache2/sites-available/default
ProxyPass /manage/ http://localhost:8080/manage/
ProxyPassReverse /manage/ http://localhost:8080/manage/

ProxyPass /manage http://localhost:8080/manage
ProxyPassReverse /manage http://localhost:8080/manage

/etc/apache2/mods-available/proxy.conf
  <IfModule mod_proxy.c>
    #turning ProxyRequests on and allowing proxying from all may allow
        #spammers to use your proxy to send email.

        ProxyRequests Off

        <Proxy *>
                AddDefaultCharset off
                Order deny,allow
                Deny from all
                Allow from all
        </Proxy>

        # Enable/disable the handling of HTTP/1.1 "Via:" headers.
        # ("Full" adds the server version; "Block" removes all outgoing Via: headers)
        # Set to one of: Off | On | Full | Block

        ProxyVia On
    </IfModule>

More info: (not sure if relevant)

Each web page is averaging 2 - 3 Ajax calls
Haven't applied 14 Rules for Faster-Loading Web Sites. Looking to apply expires header for caching static content soon.

Enabled apache modules:
core_module (static)
 log_config_module (static)
 logio_module (static)
 mpm_worker_module (static)
 http_module (static)
 so_module (static)
 alias_module (shared)
 auth_basic_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgid_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 proxy_module (shared)
 proxy_ajp_module (shared)
 proxy_connect_module (shared)
 proxy_http_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 status_module (shared)
Update: I am now using the ajp protocol for the proxy. An have set some addition ProxyPass config e.g.
ProxyPass /manage ajp://localhost:8009/manage max=20 ttl=120 acquire=10000 retry=0
ProxyPassReverse /manage ajp://localhost:8009/manage

Comment: Any errors in error.log? Or in catalina.out.
Comment: No errors in catalina.out but there is an interesting entry the appears every now and then in error.log                                 [Sat May 07 07:27:59 2011] [error] (111)Connection refused: proxy: HTTP: attempt to connect to 127.0.0.1:8080 (localhost) failed
[Sat May 07 07:27:59 2011] [error] ap_proxy_connect_backend disabling worker for (localhost)
Comment: I have the same problem. Didn't find solution yet. I have to restart httpd every time this freeze happens.
Answer: I would try to use ajp to connect to tomcat from apache.
Please test the configuration using mod_proxy_ajp with Tomcat.
From logs, it looks like the tomcat did not responded to apache's request. It refused the connection.
If you have high traffic, search deeper in your application's logs. It could be a deadlock or maxthreads reached.
HTH
Comment: Ive setup proxying using the ajp protocol. I did a bit of reading, sounds like a much better protocol for between apache and tomcat. Not sure if this will solve my problem. Time will tell. Thanks
Comment: Nope, didn't solve the problem. Still get intermittent freeze when using reverse proxy. Connecting directly to Tomcat (port 8080) is working well
Comment: Any errors in apache's logs (error.log or vhost's error logs)?
Comment: How many httpd processes do you have running when is not working? Count them with: ps ax | grep httpd | wc -l
Comment: No vhost error logging. I do have a few "Connection refused: proxy:" in error.log but I now think this was only from times when I restarted tomcat
Comment: OK, it happens :). It could be slow at startup.
Comment: Ran "ps ax | grep httpd | wc -l" the returned result was 1
Comment: Replace httpd with your apache's process name. I guess is "apache".
Comment: Ok, just ran "ps ax | grep apache | wc -l" result was 6. (While the application was frozen)
Comment: Please check apache's logs and tomcat's logs after you have modified to mod_proxy_ajp. If the application is running (tomcat running and the app is deployed) there can be only a networking problem. But, being on localhost makes this odd. Can we have details about the application is running inside tomcat?
Comment: Its a web app built with the Grails framework. About 1 - 3 Ajax calls per page. Secured using Grails spring security plugin. Using JQuery. Im also wondering if it might be a memory issue (I should have mentioned this earlier). This is a 512MB ubuntu VM running Apache, Tomcat and postgresql. "free -m" show 10MB ram free and 1MB swap in use. I wonder if I am tipping over into swap memory every now and then? Tomcat is currently setup for 512MB heap which I should lower. Also I do have iptables enabled so this might effect localhost networking....?
Answer: Check that your apache file cache is disabled.
# LoadModule file_cache_module modules/mod_file_cache.so

If that doesn't solve the problem (shouldn't, this doesn't seem a cache problem) try debugging using mod_jk. Download appropiate mod_jk version for your Apache, setup it and set the log level to DEBUG
# Set the jk log level [debug/error/info]
JkLogLevel          debug

Also, include tons of info in your apache logs
LogFormat "%h %l %u %t \" %m \"%V\" \"%r \" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D CustomLogFormat
. . .
CustomLog "|C:/Apache2/bin/rotatelogs.exe C:/Apache2/logs/access_%Y%m%d.log 86400" CustomLogFormat

You should now have an Apache log with microseconds taken to serve the page, and a debug-level log of your AJP 1.3 connection to tomcat (with mod_jk).
With that done, restart apache and try forcing that freezing error. When error happens, check time, and browse logs to see what happened in that instant, how much time did apache spend processing, and so.
It won't solve anything, but most possibly will give you some insight on what is happening.
Comment: No file cache module. Ive added a list of enable modules to my original post.
Answer: If you are getting a connection refused you may be hitting the maxthread count on Tomcat.  What is maxclient set to for Apache? What is maxthread set to on Tomcat? You want to make sure your maxclient doesn't exceed maxthread. If not Apache will attempt to proxy more connection than Tomcat can serve and Tomcat will refuse connections.
Also if you retry=0 to the end of your ProxyPass statements Apache won't disable the backend worker and your recovery when this problem is encountered will be faster.
Comment: maxClient in apache 150, maxThread in tomcat not set but defaults to 200 (I have now explicitly set it to 200 in my ajp connector). I will try retry=0
Comment: BTW I am the only user of this server right now. Very very low traffic.
Comment: Is it always after a period of inactivity? If so then you may be running into a situation where you are exceeding the tcp connection timeout setting for your OS. You may want to try setting a ttl timeout on your ProxyPass statements. For instance ttl=120 will cause inactive connections to not be used again after being inactive for 120 seconds.
Comment: Not sure about the period of inactivity anymore. Seems to sometimes happen after a short period of use. Although it does seem to become more stable during longer periods of use (if that makes sense???). Either way I think an explicitly defined ttl is a good idea. Thanks
Comment: Another thing ive noticed is that the application is much more responsive when accessed through the proxy (when its not frozen). Is apache doing any caching?


Oracle 10g default username and password

Question: I'm trying to import a database dump file into Oracle 10g.  I'm very very new to Oracle.
I've installed  Oracle Server ok, but when I go to SQLPlus, I'm prompted for a username and password. I've entered the defaults I found on websites (sys/sys, sys/change_on_install
system/manager, scott/tiger) but none are being accepted.
Comment: system/manager should work, but you need to specify `as sysdba` when you login.
Comment: Hi, 10x I got somewhere at least... now it's telling me "insufficient privileges"
Answer: When you built your database, you should have been prompted for a password at some point for the system and sys accounts. That's the password you need to use.
The comment above about logging in with "as sysdba" with the user SYSTEM is incorrect. SYSTEM does not have SYSDBA privilege.
If you've forgotten or don't know the password(s) you specified for these accounts, you can sneak in through the back door by doing the following (assuming Windows):

Add your Windows user ID to the ORA_DBA group.
In a command window, set ORACLE_SID appropriately and enter "sqlplus / as sysdba"
You should be logged in as SYSDBA. You can now reset the passwords as @Gaius stated.
One other potential gotcha is that you may need to modify the sqlnet.ora file in your ORACLE_HOME/network/admin folder to contain the line SQLNET.AUTHENTICATION_SERVICES=(NTS) if you continue to get the "insufficient privileges" error in step 2.
Answer: Do this at the Unix shell prompt as the Oracle user:
<code>$ sqlplus / as sysdba
</code>
You should get a prompt back saying SQL>. Now say
<code>SQL> alter user whoever identified by whatever;
</code>
Then you can log in as
<code>$ sqlplus whoever/whatever
</code>


How do I evaluate $\int_{0}^{\infty}{e^{-x}\frac{\sin^2{x}}{x}dx} = \frac{\ln{5}}{4}$ using iterated integrals?

Question: I'm studying for quals and I'm trying to solve the following.

Prove using the results concerning iterated integrals (i.e., you should write the integral below as a a double integral) that
$$\int_{0}^{\infty}{e^{-x}\frac{\sin^2{x}}{x}dx} = \frac{\ln{5}}{4}$$
(Note: In arguing for this problem, you may assume without proof that a continuous function $h : X \times Y \to \mathbb{R}$ is measurable with respect to the product measure if $X$ and $Y$ are Borel subsets of $\mathbb{R}$.)

Since the problem says to use iterated integrals, I tried to use the fact that
$$e^{-x} = \int_{x}^{\infty}{-e^{-y}dy}$$
and re-write this as
$$\int_{0}^{\infty}{\int_{x}^{\infty}{-e^{-y}dy}\frac{\sin^2{x}}{x}dx} = \int_{0}^{\infty}{\int_{x}^{\infty}{-e^{-y}}\frac{\sin^2{x}}{x}dydx} = \int_{0}^{\infty}{\int_{0}^{y}{-e^{-y}}\frac{\sin^2{x}}{x}dxdy}.$$
But this doesn't make things any easier. I have a feeling I'm missing something important since this is a practice problem for a real analysis/measure theory qual but I don't remember/can't find any measure theory theorems that really help with this.
Comment: My immediate thought is that you can use Fubini to evaluate $\int_0^\infty \frac{\sin x}{x}\,dx$, which suggests doing the same thing here
Answer: Amusingly, I solved this as part of a homework assignment last semester.
The hint that I was given would probably prove helpful though: verify and use the fact that
$$
\int_0^1 e^{-y} \sin(2xy) \, \mathrm{d}x
= \frac{1}{ye^y} \sin^2(y)
$$
Once you have this the remainder is fairly trivial, so I'll leave that to you.
Answer: Attempt:
\begin{align*}
\frac {\sin^2 x}x &= \frac {\cos (0x)- \cos (2x)}{2x - 0x}\\
&= \frac 1{2x}\int_0^{2x} \sin (t)\,\mathrm dt\\
&= \frac 1{2x} \int_0^2 \sin (ux) \,\mathrm d(ux) {\quad}{[t = ux, u \in(0,2)]}\\
&=\frac 12 \int_0^2 \sin (ux)\,\mathrm du.
\end{align*}
Then
$$
\cdots =\frac 12 \int_0^{+\infty}\mathrm e^{-x}\mathrm dx \int_0^2\sin (ux) \,\mathrm du.
$$
If Fubini is feasible, then
\begin{align*}
\cdots&=\frac 12\int_0^2 \mathrm du\int_0^{+\infty} \mathrm e^{-x} \sin (ux)\, \mathrm dx\\
&= \frac 12 \int_0^2 \mathrm du \int_{+\infty}^0\sin (ux) \mathrm d(\mathrm e^{-x})\\
&=\frac 12 \int_0^2 \frac u{u^2 +1} \,\mathrm du{\qquad}{[\text{integration by parts}]}\\
&= \frac 14 \log(u^2 +1) \Biggr\rvert_0^2 = \boxed{\,\frac {\log 5}4\,}.
\end{align*}
To validate the application of Fubini, note that the measurability is obvious and that $\vert \mathrm e^{-x} \sin (ux) \vert \leqslant \mathrm e^{-x}$ and that $$\int_{(u,x) \in [0,2]\times [0, +\infty)} \mathrm e^{-x}\ \mathrm dx \,\mathrm du$$ is clearly finite, thus we are done.


What if Redis triggers a snapshot in the middle of transaction?

Question: Say i have set my Redis backup with snapshot every few minutes, and unlucky when a snapshot is triggered, a transaction (use pipeline) is in the process. How does Redis deal with this situation? Will snapshot be delayed until transaction finished? Or save the first part of transaction? Or exclude the whole transaction until next backup?
Answer: Keep in mind that Redis is a single-threaded event loop. A transaction is applied atomically when the EXEC command is executed. So either the RDB background save process is forked before the EXEC, or after the EXEC. You can consider that the fork takes an instantaneous snapshot of the memory of Redis.
If the EXEC is applied before the fork, then your transaction will be in the resulting dump. If the EXEC is applied after the fork, your transaction will not be in the dump, even if Redis takes minutes to generate it. Nothing will be delayed (neither the transaction, neither the dump).
On a side note, except if your database is tiny, doing a dump every few minutes is probably too heavy. Perhaps you should consider using the append-only file instead.


How to delete a managed folder and its contents programmatically via hook_uninstall?

Question: My hook_update_N() implementation looks like this:
$directory2 = 'public://folder_name';
file_prepare_directory($directory2, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);

How can I remove "folder_name" and its contents in hook_uninstall using drupal's API?
Answer: Drupal doesn't consider a folder to be a group of files, and doesn't have a method for bulk deleting managed files (like it does for unmanaged files: file_unmanaged_delete_recursive). So you'll need to identify which files you want to delete manually. A query with WHERE uri LIKE 'public://folder_name/%' might be sufficient in this case, for example, but you'll know you're own setup better than I can guess.
Once you have a list of file IDs, load up the objects, loop through them, and call file_delete on each. If you have the File Entity module installed, you can shorten this by using file_delete_multiple(), and just pass the IDs.
Once you're happy all the files have been deleted (you could stat the folder after running the loop), then remove the folder with drupal_rmdir().
Bear in mind that file_delete() is not guaranteed to remove the file; other parts of the system can declare their interest in a managed file by way of the file_usage table. If you want to unconditionally remove files regardless of any other entity in the system that they're attached to, you can use the file_usage_* methods in file.inc.


Customized google maps marker icon not showing in partial view

Question: Something strange ( at least for me) is happening. I have a partial view that is showing  a couple of google map markers. However as soon as I use my own customized icon if refuses to display. But when I give my route in the RegisterRoutes function of global.asax.cs for instance like so
   routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

And if my partial view is in Index view ,it for reasons unknown to me decides to show itself?
Why is this and how is this solvable?
Update (code):
This is my code in the partial view called MapResults.


software.amazon.awssdk.core.exception.SdkClientException Profile file contained no credentials for profile 'my-queue': ProfileFile(profiles=[])

Question: I am trying to access SQS queue and have profile my-queue for which i have created credentials and config file under ~/.aws folder.
This works fine in my windows machine with credentials and config file under username folder but it is throwing error on a Linux system which is an EC2 instance.
I am using ProfileCredentialsProvider.create("my-queue") to build client
Answer: For EC2 instance, best practice is not to use IAM profile.

Create instance role in IAM console with SQS permission
Attach that instance role to your instance
Don't specify any credentials in your instance.

Have a look at AWS guide for more information.


Battle for Britain, David Bowie

Question: I'm trying to figure out what's going on in David Bowie's song, Battle for Britain. (The intro ends at 0:35 or so.) These are the chords, near as I can tell. One chord per measure.
<code>En
B   F#   A    A
B   F#   A    A
B   F#   A    A
B   F#   A    A
G   F#   E    E
G   F#   E    E
G   F#   A  (skipped measure)
C   G  Bbmaj7 F
En...
</code>
The first 4 lines follow the common I-V-bVII sequence (or V-I-IV if you prefer).
The next 2 raise the tension by switching things up somehow. I think maybe it's good to say the key changes? Changes to E and there's some kind of chromatic planing, or is the F# after G a substitution for something, or...?
In the next line it goes to A instead of E, and somehow it sounds like a new key all of a sudden! It sounds like the A suddenly acts like secondary dominant V/V in G. Then on the next line you can say IV in G follows, as commonly occurs after a V/V in pop music.
On this next line you then have IV-I-bIII-bVII, similar to the common I-V-bVII-IV except the tonal center is on the second chord.
So what's going on in lines 5-7? Specifically, what's happening to the tonal center? Can the rest of my analysis be improved?
Answer: I'm inclined to say that you could view those two phrases as bVI - V - IV in B major.
If you consider the vocal part in those phrases - all the vocal melodies use G#, A# (this is the crucial note), and B which fits the B major pitch set which was the key from before. If you're hearing the tonal center around E in those measures I think you could say it's E Lydian, being that the pitch set fits B Ionian and the mode centered on E is the fourth mode of B Ionian.
Hope this helps!

Battle for Britain, David Bowie


How many representations of a non-commutative groups from $n$-dimensional Latin Squares

Question: I would like to know if there is a method to determine how many $n \times n$ Latin square define the same non-commutative group $G$. This is how many representations of $G$ can be obtained from $n$ dimensional Latin squares.
It results that I'm interested on building examples of non-abelian groups to toy with and test how many representations do they have.
Comment: Symmetric groups appear everywhere (so are ideal for toy examples). Any group table is a Latin square, see for example [here](https://en.wikipedia.org/wiki/Latin_square_property). For a given Latin square we have its automorphism group. See also the other posts at this site, e.g., [this one](https://math.stackexchange.com/questions/1360228/relations-between-the-latin-squares-of-order-n-and-the-groups-of-order-n) and its links.
Comment: Concretely the table can be built using the principle from the action of $f: G \times G \to G$ so $f(a,b)=c$ If I'm correct such representation is the core of Cayley's theorem as the group would be embedded into a permutation group (if it's action is faithful). My concern here is to build arbitrary non-abelian groups of order $n$ and to obtain the different number of Latin squares that define the same non-abelian group. I should point that on my question.
Comment: Then why aren't you just taking the known non-abelian groups, e.g., all finite simple non-abelian groups?
Answer: (I'm going to assume that the elements of the Latin Square are the elements of the group. If that's not what you want, then make your question clearer.)
For a given group, once you've chosen how you label the rows and columns, the Cayley table is uniquely determined. So if the group has order $n$, it has $(n!)^2$ tables.


Show that $A\setminus (B\setminus C)=(A\setminus B)\cup(A\cap B\cap C)$

Question: I'm having difficulty showing this equality (assuming that the question doesn't have a typo).. I've tried in both directions and I can't seem to get what I need.
\begin{align}
A\setminus (B\setminus C)&=A\cap\overline{(B\cap \overline{C})}\\
&=A\cap(\overline{B}\cup C)\\
&=(A\cap \overline{B})\cup(A\cap C)\\
&=(A\setminus B)\cup (A\cap C)
\end{align}
And in the other direction (A bit more convoluted):
\begin{align}
(A\setminus B)\cup (A\cap B\cap C)&=(A\cap\overline{B})\cup(A\cap B\cap C)\\
&=[A\cup (A\cap \overline{B})]\cup [B\cup (A\cap \overline{B})]\cup [C\cup (A\cap \overline{B})]\\
&=[A\cup (A\cap \overline{B})]\cup [(B\cup A)\cap(B\cup\overline{B})]\cup [C\cup (A\cap \overline{B})]\\
&=[A\cup (A\cap \overline{B})]\cup [(B\cup A)\cap\mathcal{U}]\cup [C\cup (A\cap \overline{B})]\\
&=[A\cup (A\cap \overline{B})]\cup (B\cup A)\cup [C\cup (A\cap \overline{B})]\\
&=[(A\cap \overline{B})\cup (A\cap \overline{B})]\cup(A\cup A)\cup B\cup C\\
&=(A\setminus B)\cup A\cup B\cup C
\end{align}
Both of these seem to be "close", but neither is the same, and neither quite get to the goal. Is there a flaw in my algebra? Or is this not even possible using this method?
Answer: Write $A\cap C = (A\cap B\cap C)\cup (A\cap \overline{B}\cap C)$ in the second-to-last last line of the first part:
$$\begin{align}A\setminus(B\setminus C)&=(A\cap \overline{B})\cup(A\cap C)
=(A\cap \overline{B})\cup(A\cap \overline{B}\cap C)\cup(A\cap B\cap C)
\end{align}$$
Then note that $$(A\cap \overline{B})\cup(A\cap \overline{B}\cap C)=A\cap \overline B.$$
You need $$X\cup (X\cap Y)= X\tag{1}$$$$X\cap(Y\cup\overline{Y})=X\tag{2}$$
You can prove (2) if you know that:
$$X\cup\overline{X} = Y\cup\overline{Y}\tag{3}$$
$$X\cap (X\cup Y)=X\tag{4}$$
Proof of $2$ using $3,4$:
$$X\cap (Y\cup \overline Y)=X\cap (X\cup \overline X) = X$$
Comment: I vaguely recall this from some years ago -- what is this property/equality/law called? I'm referring to the addition of $B$ and $\overline{B}$ to both sides of a union
Comment: In general: $X = (X\cap B)\cup(X\cap \overline B)$. This follows because $X=X\cap (B\cup \overline{B})$, which is just saying that $B\cup\overline{B}$ is the entire universe. Not sure what that is called.
Comment: The second equality is that $X\cup(X\cap B)=X$. Again, not sure what that is called.
Answer: Hint: Using $^c$ to denote complement,
$$
A\setminus\left(B\setminus C\right)=A\cap\left(B\cap C^{c}\right)^{c}=A\cap\left(B^{c}\cup C\right)=A\cap\left(B^{c}\cup\left(B\cap C\right)\right).
$$


Pyramidal Histogram Of Oriented Gradients - Trilinear interpolation

Question: Hello im struggling with an implementation of this article: https://goo.gl/8mpIuq
I performed bilinear interpolation over the histogram bins and the results are better with this interpolation, however on page 2 its also mentioned that a trilinear interpolation is added when the pyramid level reaches level 2. I have read this answer HOG trilinear interpolation and I completely understand the formula behind trilinear interpolation over 2x2 block sizes, but in this article we have a 3x3 block size and 7x7 on pyramid level 3, because these block sizes yield the best results.
The main point about trilinear interpolation is that each pixel in a cell contributes to its local cell by a weight which is defined as the position in each block. I don't know how to represent the location of a pixel in 3x3 block size or what kind of formula should i use.
Thank you for all your help!
EDIT: Another explanation with 2x2 block size http://pep.ijieee.org.in/journal_pdf/11-126-142960909718-22.pdf
Comment: "This answer"? Is there a link missing?
Comment: I just added the link to the answer, thank you for noticing it.
Answer: Hint Since the question is kind of fuzzily asked I won't claim this to be anything more than a hint to help the thinking going.
So my interpretation is that each pixel has two integer coordinates, each cell spans a range of coordinates in two dimensions. So two dimensions of the interpolation is x and y in the image and the third dimension is "angle". Say one pixel has gradient $g_p$, we then calculate the contributions to bins of neighbouring cells depending on all three of these distances $(\Delta_x, \Delta_y, \Delta_{\theta})$.
Let us say we have a local coordinate system for each cell, the mid point (origo) would naturally be the middle pixel if 3x3 pixels and 1 "step" away in a particular dimension should be the center pixel of the neighoburing cell. Now we can straight forwardly calculate coordinates for all the pixels in between for each coordinate system since we know how many pixels are in between two centers and that the coordinate system is linear and cartesian. In the 3x3 there would be two pixels inbetween of two middle-pixels, right? So then the coordinates $(0,\frac{1}{3},\frac{2}{3},1)$ for the left and $(-1,-\frac{2}{3},-\frac{1}{3},0)$ for the right.
Say we want to distribute the gradient of pixel 2. (1-1/3) of that will contribute to the left cells and (1-2/3) to the right cells. Since we have the multilinear property we can further subdivide on up and down and angle. How much to the up or down cells depend on the position of pixel 2 in the second dimension and so on.
Any further description than this would probably be dependent on data structures available and/or programming language to use I guess.


Unit Vector Perpendicular to Given Vector

Question: I understand there are questions on the Math Exchange already, but upon analyzing them I have still not figured out how to solve my own problem.
My problem is to find all vectors that are perpendicular to the vector $(1, -2, 5)$, have the y-components be equal to 3 times the x-components, and have a length of 5.
I know that the first step is to set the dot product of my vector and another vector equal to zero. And the result is $i-2j+5k=0$, correct?
After that my method falls apart as I am trying to find ALL vectors perpendicular to my vector. Help would be appreciated!
Comment: Your first equation is correct. Any vector satisfying that will be perpendicular to your given vector. Now create equations for the other conditions and solve.
Comment: Despite the title you've given this question, the problem doesn't want you to find a unit vector.
Comment: You do realize that there's an infinite number of vectors perpendicular to $(1,-2,5)$, yes? It looks like you've picked out just a single solution to the first equation that you formulated. The probability is zero that it happened to be the right one.
Comment: @amd I believe my answer below is sufficient, thanks!
Answer: A hint.
The thing is, you need all prependicular vectors.
Start with all vectors possible, let's designate them $(x;y;z)$.
Now choose all vectors that are perpendicular to your vector $0 = (1; -2; 5) \cdot (x;y;z) = x -2y + 5z$.
This gives you one equation.
The other two are $y = 3x$ and $5^2 = x^2 + y^2 + z^2$.
Solve the equations and you'll get the result.
Comment: @ThatOneNerdyBoy You should have at least two solutions.
Comment: Would solving this require a system of equations?
Comment: @ThatOneNerdyBoy , yes. We can call 3 equations a system. But in this case the system is quite simple. I can add a full solution for you if you feel need.
Comment: I solved it and got x = sqrt(25/11), y = 3sqrt(25/11), and z = sqrt(25/11). Does that seem right?
Comment: @ThatOneNerdyBoy , looks good for me. But there is one more solution to this system of equations. Try vector directed just opposite to the one you found.
Comment: @amd and guest Oh silly me, the negative would also work just fine! Thanks!


Still making mistakes in pieces after years of practising them

Question: I think my question has been partially answered before:

How to play a song without making mistakes?
Practice to avoid mistakes or practice to cover mistakes

I am happy to take it down if it is considered a duplicate.
I have been practising almost every day (I think I have missed out on a total of like 2 weeks) for at least 1 hour for a few years by now ("older" musician here, I am way beyond my teens), I am still making mistakes, even in short pieces that I've been playing for years (thankfully, I have patient neighbours), and it makes me feel like I am doing something wrong. I frequently go to my teacher's performances, and he often doesn't make a single mistake, even if his band plays for 3 hours or more! As for me, I can count the number of practice sessions where I haven't made a single mistake on the fingers of one hand, which is very disappointing after so many years of continuous work (not to mention my compositions are a lot shorter and easier).
I am updating my question to provide some additional data. I am playing (tenor/soprano) saxophone (and have just recently started flute), and I did not specify it initially, because I wanted the question to be helpful to all musicians, and because I do not think my problems have anything to do with the instrument I play.
It is also important to note that the mistakes I make are irregular, meaning I make mistakes in different places, so it's not a case of "learnt helplessness".
Since the very beginning, I have followed what is considered good practice hygiene by most:

Itemising (playing a new piece section by section, until you get it right)
Analysing a piece compositionally before and during play
Playing very slow in the beginning (to the point where my teacher would say I had remarkable patience) to avoid "learning to always play wrong"
Recording practice sessions and listening to them
Listening to professional musicians (excessively) perform the piece in question or recording electronic versions of it otherwise
Using a metronome
Keeping a practice diary

Despite all that and being able to play all basic (and some "advanced") scales from memory, I still make mistakes, even when playing said scales (the mistakes are physical, like "fingers slipping", I have no trouble recalling scales and chords from memory without looking at the print-outs). They do not seem to come from lack of sight-reading experience or proficiency with the instrument, I would describe most as "mind blanks", which I thankfully snap out of immediately upon hearing them. I either stop or run up/down the scale/arpeggios until getting back into the next section (depending on how OCD I feel on that day, but I am trying to get out of that habit of "covering up", because it feels psychotic and not helpful in learning to play intelligently).
So it seems like I am doing most things right, but it doesn't seem to produce perfect results. I do not play pieces from memory (my visual memory is virtually non-existent) or by ear. I do remember some sections kinesthetically (some people seem to believe such memory does not exist), and I think that's the only component that might be causing problems (because if you play something automatically, your conscious mind might go blank for the duration).
Am I expecting too much after less than 10 years of playing (I am discounting my experience in an orchestra when I was at school, because I stopped playing while being at university, and I played a different assortment of instruments at the time anyway), and should I just continue "sucking it up", or am I missing some crucial components? I have tried asking my teacher and some other professional musicians what to do, but most have been playing for decades and cannot remember or relate to what I am experiencing.
Comment: You might find this useful.  https://www.youtube.com/watch?time_continue=157&v=wwQBv2sATuE&feature=emb_logo
Comment: One way to practice is to forget the metronome and play the piece with no mistakes - even if it means playing one note per minute. .
Comment: What instrument?
Comment: Do you make, pay attention to rhythm/timing mistakes?
Comment: @Tim, (tenor/soprano) saxophone and flute (albeit only a few months on the latter).
Comment: @MichaelCurtis, very rarely. Whenever I pick up a new piece, it's always with a metronome, until I am comfortable with playing it. And I always count, even when I play pieces I've played hundreds of times before. I must admit I do have trouble getting into the rhythmical "feel" if I am given something I haven't seen before. I _need_ to have some alone time with a metronome to get it right, otherwise I can't play.
Answer: I have some ideas to share.  These are intended as ideas for you to consider trying.  One or more of these may help you.

Memorize the piece or etude or whatever it is that is giving you trouble.  This may be easier if you map it out for yourself, possibly pictorially. It can be helpful to make up a story that helps you remember what section you're in -- because often the trickiest part of memorization is when two sections start the same, but diverge at some point.

Analyze the ergonomics.  I don't know what your instrument is, but here is how I would do it for my instrument, cello.  I consider the hand shapes, and how I will transition from one hand shape to another, with minimal tension.  I consider the positions, and how I will need to prepare for the shift from one position to the other.  I analyze the optimal bow technique -- what part of the bow do I need to use for this bit or that bit, how can I get the optimal sound, without pinching off the sound, or raising my shoulder (which could cause pain eventually)?

Sing the phrase, to discover what phrasing you like.

Conduct the phrase.  Again, this helps you discover what phrasing you like, but also it helps you realize where rubato is called for, exactly how you would like to do any tempo changes there may be, etc.

When I was my children's Suzuki coach, their teacher taught me a fun practice technique.  I made a little stop sign with construction paper and a popsicle stick.  One side was green and one side was red.  If you are the practice coach, here's how you do it: first, identify the place in the score where the mistake has a tendency to occur.  Then, as the student is playing the piece, hold up the stop sign with the green side facing the student.  Flip it around suddenly (but without fanfare) about half a measure or a measure before the mistake place.  When the student sees the red stop sign, he should stop playing, but not lift the bow from the string, or take his left hand down.  During the frozen moment, the coach gives a brief verbal or physical reminder of the correction needed, and then flips the stop sign around again.  This is the signal for the student to continue playing.
What makes this technique so effective is that it allows the student to re-imprint, with the correct notes (or correct dynamics, or whatever) in place of the ingrained mistake.

Dance to your piece.

Imagine a ballet or modern dance choreography set to your piece.

Visualize yourself playing your piece.  I found it helpful to do this in bed before going to sleep.  I did this with a piece I knew inside and out, getting ready for a recital.  I would watch myself walk on stage, bow, sit down, start to play, and I saw myself play the whole piece beginning to end.

Go to master classes at a university or conservatory near you.  Any instrument will do.  You'll get ideas, and perspective, too.

Something to think about: Do some of your mistakes come from too much adrenaline?  It's good to have some adrenaline -- to avoid a dry, emotionless performance. But you need to strike a balance. With too much adrenaline things can run away from you and you lose the precise control of your fingers, and you lose track of your mental map of the piece.
Finally, I would like to make a comment about the remark in another answer, "To tell you the truth 1 hour a day is nothing. Pros and serious students are at it for 8 hours a day."  The amount of time needed for a student to progress or meet his goals is very individual.  I can say that in music school I practiced four hours a day most days.  Later, playing professionally in an orchestra, I practiced less.  I believe that quality is more important than quantity.
Comment: Even though I do not play a string instrument and my visual memory is non-existent, I find this answer to be the most "complete" one that allows me personally and, in my opinion, other people having similar problems to develop a helpful routine of improving. You are also the only person who brought adrenaline up, which is something I failed to consider and now understand to be the main culprit behind my mistakes (hence their irregularity). I will update my question to reflect what instruments I play, I tried to make it general and potentially useful to anyone, not just me.
Comment: P.S. I fully agree that quality trumps quantity. I didn't go to music school (got interested in music too late to be taken in), but I attended a conservatorium as an adult, and I still see my teacher every now and then despite years of regular practice.
Answer: Perhaps the most valuable single bit of advice I ever got from a teacher is this:

Don't practice until you get it right:  practice until you can't get
  it wrong.

The reason you are making mistakes may be largely psychological at this point, but don't underestimate how hard it is to get rid of bad habits (i.e. wrong notes or rhythms).  Play the passage carefully, slowly, until you get it right. Then play it again. Then again. If you can't play it at least 5X in a row correctly, and preferably 10X, then you haven't purged the errors from your system.  Keep going at it.  And don't expect to succeed in a single practice session.  Neurons take time to develop new connections, so do the passage again the next day, and the day after that.
Comment: I think a problem some have is that unless they play something *the same* every time, it's not 'learned'. If music was actually like that, it would get very tedious. I can only actually say I '*know*' something when I can stretch it, squash it, mess about with the timing, dynamics, etc., etc. Not merely regurgitate it like a robot. +1.
Comment: Thank you, I should've mentioned in my question that I make mistakes in _different_ places, not the same ones... I will update my question to reflect it.
Comment: @Tim It should be an answer, not a comment! I never realized that messing around in such ways can help memorizing!
Comment: @anatolyg - I commented thus on this answer, as I feel it advocates being able to play something verbatim, identically, several times to prove 'I now know it'. I disagree to an extent. That's more like  - I'm not sure!
Answer: I know this has already been answered, and this isn't an answer per se, but I think it will be super helpful for you.
Basically, get ahold of a copy of "Fundamentals of Piano Practice" by Chuan C. Chang as soon as you can. I'm 28 years old and started piano at age 4. I discovered this book last year after over two decades of piano playing and a couple years of teaching piano at a private college, and it completely changed how I view and teach piano practice.
There's more in that book than I can discuss here; please read it! To sum up a couple high points that I think apply to you:

A couple of your techniques are what the author calls "common sense" techniques, specifically starting slow and picking up speed. These "common sense" techniques are actually incorrect. In the instance of "start slow and gradually pick up tempo," you should instead start by figuring out what fingering/positioning/execution/motions are required to play it extremely fast. This assures you that your technique is solid. It's all about technique. If you start slow, your technique may be faulty and you wouldn't even know it.

For example, if I finger a right hand C major scale 1-2-3-4-5-3-4-5 (an atrocious fingering!), but played it very slow, I still wouldn't feel any tension until I tried speeding it up. When I played it fast, I'd hit what the author calls a "speed wall" - when your fingers can only play so fast and simply won't move any faster. This will not change until I correct my technique, and the only way to know if my technique is right is to start by (once I've correctly read the notes) trying that small section (hands separate - see below) fast to see if it is loose and smooth. That's an extreme example, but it demonstrates the idea. You stated that you start slow to make sure you don't practice it the wrong way; however, you won't ever know if your technique is wrong until you try it fast! This is why Mr. Chang recommends both fast AND slow practice from the get go. Use fast to figure out what is the most loose, free way of playing, then practice it slow that same exact way.

Always, always, ALWAYS start hands separate. Never play hands together in the beginning, even on small sections, unless you can play it hands together flawlessly WAY above tempo. In order to properly work out technique as I described in (1.) above, you need to work it out hands separate, then drill it over and over hands separate, from memory.

I know this is lengthy, but honestly it's just a taste of some of the gems you'll find in Mr. Chang's book. I think this will be a huge help to you because I've dealt with the exact same problems even after over two decades of playing a ton. Only when I found this book did I realize what I'd not been taught in lessons.
Bonus: I think there's a free version of the entire text of the book available on readthedocs. Check it out!
Best of luck to you, my friend!
Comment: Ah I missed that you were not a pianist. Sorry.  Some of the techniques still apply I would say. Especially when it comes to practice tempo and technique. The biggest thing to stress is absolute, 100% zoned in focus when you practice. If you accustom your brain to think about anything besides what you're playing during the practice season, then when you're playing for people, the music will be relegated to your subconscious while your conscious brain thinks about something else — namely, the "scary" people watching you!
Comment: Thank you so much! I am very grateful to you for taking the time to respond despite the question being marked as answered. Even though I am not a pianist, I do believe this book will help me greatly. In the worst case scenario, it's a good technique to try, and if it worked for you on the piano, it will most likely work on my keyed instrument. Except, perhaps, the hand separation technique, because it won't quite work on the saxophone and flute, unless it's just an exercise and not actual playing.
Comment: I think so too! And, as a musician, I have to have some level of playing piano (and I do, I just do not consider myself proficient enough). Like with the answer from the celloist, I think I can still rework more than 95% percent for my instruments. Your answer is extremely helpful, and it's a shame I cannot accept it as a second one. I've already started reading the book you suggested.
Answer: Are you being honest with yourself?
You have provided a laundry list of things to do and they should work.
You need to critique yourself and if you haven't already you should take lessons with a professional music teacher (musician).  They can help you identify what you are doing wrong.
For example did you follow a traditional path of learning your instrument or are you self taught?  Self taught players can achieve a lot but often suffer from missing some basics that they cannot see objectively.
To tell you the truth 1 hour a day is nothing.  Pros and serious students are at it for 8 hours a day (it's their job), and they still make mistakes!  So what you are experiencing may just be normal.  I recently saw a video of Pepe Romero (one of my favorite classical guitarists and a brilliant musician).  He stated that he would spend close to 4 hours every day going over simple chromatic and diatonic exercises on the guitar.  And this is just the stuff we learn in lesson 1, 1-2-3-4 up the neck and across the strings with every picking combo.  The basics need drilling every day to make advanced playing possible.
As for memorizing, music does not need visual memory.  Can you recall a tune in your head?  Can you sing the Dorian mode for one octave?  This is more basic than fingering.  The fingers need a lot of attention to learn to do their job correctly but music has to be in the ear.  So if you are not hearing it perhaps spend some time doing different exercise.  Use a program like Ear Master Pro and spend 20 min a day doing exercises without your instrument.  This will help you develop musical skills that transcend the fingering issue.  Many players will tell you that if you can sing something you will be able to play it.
How do you know your teacher doesn't make mistakes?  I find this hard to believe.  It is important to not practice mistakes but we all make them until we get familiar with a piece.  If you think you can do what you are attempting to practice but keep getting it wrong you may not be taking an objective approach to your basic technique development.  I can draw on a personal example I'm going through.  I have arranged a Weiniawski violin piece for guitar.  I can play most of it at 150-160 bpm which I'm very proud of.  However one section kills me every time.  For a while I just tried playing through it at tempo hoping it would clear up.  That was never going to work.  After some analysis I realized that the issue was turning around (changing direction) and transitioning from an alternate pick sequence to a sweep at the turning point.  This is a very specific detail.  So I had to isolate this 3 note segment and drill it with the m-nome for days, 2 beats up 1 beat down.  Once I passed 130 bpm higher speeds were easy.  I'm not saying this is your problem but each thing that's holding you back needs to be identified and rooted out and only you (and/or your teacher) can do that.
Based on all you've written I don't think you have been specific enough for anyone to isolate what you are experiencing. You mentioned that you are still making mistakes in scales but that it's not from sight reading.  Are these physical errors?  Like your fingers getting it wrong?  Or memory errors like you start playing whole tone and run into major?  This would help.
The kind of fluidity that pros demonstrate comes from decades of regular daily habitual practice.  They make it look easy but it takes dedication.
Comment: Good day. I thought it would be obvious from my question that I do have a teacher and practised properly from the start. I practise scales and arpeggios every day. 1 hour might indeed be nothing, but I am not a "professional" musician (no degree in music), and I have a full-time job to boot. I can recall even "complex" tunes, like [this](https://www.youtube.com/watch?v=SJxd_Lu8VPA), but I do not play by ear (not enough experience). I think my teacher doesn't make mistakes, because I know their band's scores, and I spent a few sessions looking at them while they were playing. Thank you!
Comment: I have a day job too.  Still get 4h in minimum.   Then what exactly is the nature of you mistakes?
Comment: I am happy for you, but you play guitar, and I play tenor saxophone. I do not own a car, and I stop playing before 21:00 out of respect for my neighbours. The thing's so loud, my friend who plays harmonica has to stay in a different room when we jam with his speaker turned on to 100%. And no, saxophone mutes are not a thing - it's not a trumpet. I have updated my question. I now believe my problems came from being overexcited when playing, because the mistakes were irregular and accompanied by "mind blanks". I am not sure how to answer your question otherwise.


Changing Technique and Style in Music

Question: I've played guitar for over 14 years and I've developed a very distinct style in my guitar playing. Some people have mentioned that my style is much in line with John Butler.
I now want to expand/change my style. I've developed a habit of composing most of my music based on my current style and I want to change this. I see other artists that I'm interested in (Alt-J, Estas Tonne, etc.) and want to fuse my style with theirs (I understand that the two artists mentioned above have very very different styles). Besides learning their songs, what are some techniques/exercises that can help me transition and fuse my style with theirs.
Comment: I've enjoyed the comments so far. Each one has their own distinct and valid answer. I wish I could give credit to all, but I decided to award it to the person who posted first.
Answer: Something that I think is really underrated is simply listening. If you listen closely, and its something you really love, you'll definitely pick up some of their licks and other ideas to add into your playing. But I'm assuming if you want to get their style, you're already doing that. So, maybe be patient with it.
Another thing that I was always told to help me learning jazz is transcription. I guess this goes along with learning the songs, but it definitely going beyond that. Learning how to transcribe is a great skill to have on its own and will definitely improve your ear, but you'll get into the music and see things you never would have seen before.
Whatever you do, don't force it because whether you're playing in front of musicians or not, they'll somehow know that what you're playing is just not authentic and natural. So just really get into their music (the artists you want to sound like) and let it silently, naturally influence your playing.
Answer: One of the hardest decisions to make when you compose, or write songs (depending upon how you view the process…!), is really fundamental. It's not about techniques, chords, harmonies, modes, scales and other processes…
…it's about what you want your music to sound like.
I think this is the same whether you are a "classical" composer or a song-writer.
I see two main ways you can arrive at satisfactory points with finding your sound.

Firstly, discover other artists, bands, composers etc. who create a similar sound to the sound you want to achieve (it sounds like you have a good idea already!) Listen to them. Read their scores. Read their lyrics. Play their music. This will give you an insight into how their music works. But, also ask other musicians you know, "How did this artist create this sound?; What is this chord sequence they wrote?; Why does this melody work (or what does it do)?; How did they perform/record this?".
Secondly, Experiment. Noodle. Improvise. See where your fingers take you on your instrument. But do this using your ears. All the time you should be asking yourself, "Have I discovered something closer to the sound I want to create? Or, have I discovered something unexpected that excites me, and makes me want to compose more music like this?"

But, this is quite abstract…
How about I suggest some more specific approaches:

play songs by bands, artists, composers you are interested in (and want to take influence from) - get their music under you fingers, and into your ears.
try yourself to be analytical: What is it you most enjoy about their music?; Are there any short musical ideas or characteristics that seem to recur in their music?; If you had to tell another person (musician or otherwise) what the best "bit" from a song you like is, how would you explain it?

These approaches will give you a broader understanding of the sound of the music you are interested in, and suggest ways to emulate, vary and (hopefully) move beyond your influences.
Answer: Music is about expression, and your style should represent you. It sounds to me like you listen to a fair bit of these guys already, and if you want to implement aspects of their style into your own I suggest you learn their songs, try to replicate their songs accurately, transcribe some sections (especially solo lines) etc.
You should be trying to achieve your own unique style, and you will notice that your style will evolve naturally to represent your influences in life (not specially just musical influences). The more time you spend listening and playing other artists music, the more their stuff will influence you in your own style.
E.g. I spent a lot of time listening to Metallica, Creed/Alter Bridge and others when I was a teenager, then I went and studied jazz for a few years, and have spent the last few years listening to gypsy jazz (especially Bireli Lagrene), and Sylvain Luc, and as a result now my playing style has influences of those artists (rhythmic elements from Metallica, Mark Tremonti's gorgeous open tuning guitar riffs, Bireli's feel and Sylvain's tone, etc) while I still feel like my style is my own. You need to be happy and progress with your own style.

Changing Technique and Style in Music


How to recognize a knot, practically?

Question: This question was inspired by the very first exercise in Thurston's Three Dimensional Geometry and Topology, where he gives a picture of a very tangled up loop and asks what manifold it depicts.

I understand there are several knot invariants and algorithms that can be used to detect  the unknot. But where are the practical implementations? Are there programs into which one can feed an actual picture of a knot (as opposed to more directly computational representations) and have it at least recognize unknots? One test would be whether it would accept the above picture as input and give the correct answer.
Answer: It's somewhat limited in its abilities to do so, but I made KnotFolio so that you can paste in a picture of a knot and (with some massaging) turn it into some computational representation and calculate knot invariants.
Starting with a higher-resolution screenshot of the first exercise in Thurston and Levy, "Three-Dimensional Geometry and Topology", pasting it in I get a screen that looks like

If you want, you can lower the "Threshold" slider to thin out the lines a little. I did this, though I didn't need to, and clicked "Accept." This brought me back to the painting mode, if it needs any more touching up.

Clicking "Convert to diagram" does some simple image recognition algorithms and comes up with a combinatorial description. If there are broken or merged lines (from being too thick) it might fail at this step.

We can read off that it has 6 components and 0 crossings, so as a knot this must be a disjoint union of 6 unknots. In particular, to answer the exercise, the manifold is a disjoint union of 6 circles.
We can also take the knot from Thurston's notes (which the book is based on):

With a little bit of editing from inside KnotFolio I can clean it up to look like this:

This is convertable to a diagram:

I only have the KnotInfo data for knots with up to 12 crossings (and the LinkInfo data for links with up to 11 crossings). This is a 38-crossing knot, and it's so big that some of the internal computations get a bit too big for its data types (hence the "assertion failed" error, likely due to a failure to compute the Conway potential). At least the Kauffman bracket shows the knot is nontrivial.
While we're here, one fun feature is that you can click Beautify and (after waiting for an unoptimized algorithm to complete) get to see

Going back to the original diagram, you can also identify the manifold using an image editor. I'm using GIMP here. We know that the only connected 1-manifold with empty boundary is a circle, so the problem reduces to counting connected components.
First I used the bucket tool to create a black/white coloring one way, and I needed to click two times:

Second I used the bucket tool again to create a black/white coloring the other way, and I needed to click five times:

Using some basic algebraic topology (or, less sophisticated, some innermost disk induction argument) one can see that in a black-white coloring of the plane with $B$ black regions, $W$ white regions, and $C$ curves, then $B + W = 1 + C$. With $B=2$ and $W=5$ we get $C=6$.
Hence this manifold is homeomorphic to a disjoint union of six circles.
(In retrospect, one doesn't need to count black and white regions separately, and one can calculate $B + W$ by counting how many clicks it takes to fill in the entire picture.)
Comment: @Kariuki The very first argument that came to mind is that if you triangulate everything in sight, you can eventually notice that $B + W - C$ is the Euler characteristic of the plane. But it's much much cleaner to notice $R = 1 + C$, where $R$ is the number of regions in the complement of the curves, for essentially the same argument you give.
Comment: Wow. Great answer, great tool. What other arguments did you have in mind for $B +W = 1 + C?$ Seems to me you just note that this holds when the entire plane is just one color, and every black or white region you had adds 1 to both sides of the equation.
Comment: Cool and interesting!

How to recognize a knot, practically?