Kayıtlar

Similarity Methods (Cosine Similarty, L1 Distance, KullbackLeibler, Simetric KullbackLeibler, JensenShannon) in C#

 public static double CosineSimilarty(double[] q, double[] d)         {             if (d == null || q == null) return 0;             if (q.Length != d.Length) throw new Exception("both vectors must be of similar length");             // Calculate cosine similarity:             double numer = 0;             double denom = 1;             double d1 = 0, d2 = 0;                 for (int m = 0; m < q.Length; m++)             {                 numer += (q[m] * d[m]);                             d1 += (q[m] * q[m]);                 d2 += (d[m] * d[m]);   ...

T-SQL WITH

USE AdventureWorks2012; GO -- Define the CTE expression name and column list. WITH Sales_CTE (SalesPersonID, SalesOrderID, SalesYear) AS -- Define the CTE query. ( SELECT SalesPersonID, SalesOrderID, YEAR(OrderDate) AS SalesYear FROM Sales.SalesOrderHeader WHERE SalesPersonID IS NOT NULL ) -- Define the outer query referencing the CTE name. SELECT SalesPersonID, COUNT(SalesOrderID) AS TotalSales, SalesYear FROM Sales_CTE GROUP BY SalesYear, SalesPersonID ORDER BY SalesPersonID, SalesYear; GO source : http://msdn.microsoft.com/en-us/library/ms175972.aspx

How to retrieve the top N rows for each group

-- Solution   for   SQL   Server   2000   and   later       SELECT   ProductID ,           CategoryID ,           UnitPrice    FROM     @ Products   p1    WHERE    ProductID   IN  ( SELECT   TOP   3   ProductID                          FROM     @ Products   p2                          WHERE    p1 . CategoryID  =  p2 . CategoryID                          ORDER    BY   UnitPrice ...

T-Sql Case When

CASE WHEN durum1 THEN  yapılacaklar WHEN durum2 THEN yapılacaklar ELSE  yapılacaklar END

WITH common_table_expression (Transact-SQL)

WITH Sales_CTE (SalesPersonID, NumberOfOrders) AS ( SELECT SalesPersonID, COUNT(*) FROM Sales.SalesOrderHeader WHERE SalesPersonID IS NOT NULL GROUP BY SalesPersonID ) SELECT AVG(NumberOfOrders) AS "Average Sales Per Person" FROM Sales_CTE; GO source : http://msdn.microsoft.com/en-us/library/ms175972.aspx

install GSL on windows/Visual Studio

1. Within VisualStudio, go to File->New->Project, then "Visual C++ Projects," then "Win32," then "Win32 Console Application." Enter a name and click "OK." On the next screen click "Finish." 2. In the "Solution Explorer," right click on the name of your project and go to "Properties." 3. Under Configuration Properties->Linker->General-> Additional Library Directories , type in C:\Program Files\GnuWin32\lib 4. Under Configuration Properties->Linker->Input-> Additional Dependencies , type in libgslcblas.a;libgsl.a 5. Under Configuration Properties->C/C++->General-> Additional Include Directories , type in C:\Program Files\GnuWin32\include 6. Under Configuration Properties->C/C++->Code Generation->Runtime Library,select "Multi-threaded DLL" kaynak :  http://permalink.gmane.org/gmane.comp.lib.gsl.general/4071

Sql mükerrer kayıtları silmek

Resim
Sql Server’da bir tablodaki tekrar eden kayıtları nasıl silebiliriz ? L_User  isminde bir tablo oluşturup tabloya bir kaç kayıt girelim. CREATE   TABLE  [dbo].[L_User] (       [ColumnId] [ int ] IDENTITY (1, 1)  NOT   NULL  ,       [UserName] [ char ] (10)  NULL  ,       [UserPwd] [ char ] (10)  NULL    )  ON  [ PRIMARY ]   Böyle bir örnekte kesin ve doğru bir query şekli olmadığı için kişilere bağlı olarak farklı yöntemler kullanılabilir. while ile döngü kurma, cursor kullanmak, temporary table oluşturmak gibi yöntemler tercih edilebilir. Burada bunlardan bir iki tanesine örnek vereceğim. Bu yöntemlerden en kolayı, identity columndan yararlanmaktır.  Tekrar eden kayıtları gruplayıp en küçük veya en büyük ID’lerini alıp  diğerlerini sileceğiz. DEL...