(***********************************************************************
This file was generated automatically by the Mathematica front end.
It contains Initialization cells from a Notebook file, which typically
will have the same name as this file except ending in ".nb" instead of
".m".

This file is intended to be loaded into the Mathematica kernel using
the package loading commands Get or Needs.  Doing so is equivalent to
using the Evaluate Initialization Cells menu command in the front end.

DO NOT EDIT THIS FILE.  This entire file is regenerated automatically 
each time the parent Notebook file is saved in the Mathematica front end.
Any changes you make to this file will be overwritten.
***********************************************************************)



BeginPackage["DataAnalysis`Covariances`"];

Column::usage = "Columna[X,i] extrae la columna i de la matriz X y 
		Columna[X,{i1,...,ik}] extrae las columnas i1, ..., ik de X, no se
		requiere que los \[IAcute]ndices de columna esten ordenados.";
Norm::usage = "Norm[u] calcula la norma del vector u con M = I,
		Norma[u,m|M] calcula la norma de u con la m\[EAcute]trica especificada por \
m o M.";
OneNorm::usage = 
    "OneNorm[u] calcula un vector unitario en la direcci\[OAcute]n de u,
		similarmente OneNorm[u,m|M] determina el vector unitario usando
        la m\[EAcute]trica dada por m o M. OneNorm[X] o OneNorm[X,m|M] \
normaliza
        cada una de las filas de la matriz X.";
Mean::usage = 
    "Mean[x] determina la media artim\[EAcute]tica de x,	al igual que 
		Mean[x,dp|Dp] que emplea la m\[EAcute]trica de pesos dada por dp o Dp.
		Mean[X] o Mean[X,dp|Dp] calcula la media de cada una de las columnas de la \
matriz X.";
ZeroMean::usage = 
    "ZeroMean[x] determina el vector centrado de x,	al igual que 
		ZeroMean[x,dp|Dp] que emplea la m\[EAcute]trica de pesos dada por dp o Dp.
		ZeroMean[X] o ZeroMean[X,dp|Dp] centra cada una de las columnas de la 
		matriz X.";
Variance::usage = "Variance[x] determina la varianza de x,	al igual que 
		Variance[x,dp|Dp] que emplea la m\[EAcute]trica de pesos dada por dp o Dp.
		Variance[X] o Variance[X,dp|Dp] calcula el vector de varianzas de las \
columnas 
		de la	matriz X.";
StandardDeviation::usage = 
    "StandardDeviation[x] determina la desviaci\[OAcute]n est\[AAcute]ndar de \
x,	al igual que 
		StandardDeviation[x,dp|Dp] que emplea la m\[EAcute]trica de pesos dada por \
dp o Dp.
		StandardDeviation[X] o StandardDeviation[X,dp|Dp] calcula las desviaciones \
estandar de las columnas de la matriz X.";
Standardize::usage = 
    "Standardize[x] centra y reduce el vector x o cada columna de la matriz \
X, con la sintaxis Standardize[x,dp|Dp] emplea la m\[EAcute]trica de pesos \
dada por dp o Dp.";
Covariance::usage = 
    "Covariance[x,y] calcula la covarianza entre x, y y. Similarmente
    		Covariance[x,y,dp|Dp] calcula lo mismo pero empleando la \
m\[EAcute]trica de pesos dada por dp o Dp.
    		Covariance[X] o Covariance[X,dp|Dp] calcula la matriz de varianzas y \
covarianzas 
    		de las columnas de la matriz X.";
Correlation::usage = 
    "Correlation[x,y] calcula el coeficiente de correlacion entre x y y,
    		como	Correlation[x,y,dp|Dp] que lo calcula empleando la m\[EAcute]trica \
de pesos dada
    		por dp o Dp.		Correlation[X] o Correlation[X,dp|Dp] calcula la matriz \
de correlaciones 	entre las columnas	de la	matriz X.";

Begin["`Private`"];

\!\(\(Unprotect[Column];\)\[IndentingNewLine]
  \(Column[dat : {___List}, 
        n_Integer] := \((#1\[LeftDoubleBracket]n\[RightDoubleBracket] &)\) /@ 
        dat;\)\n
  \(Column[dat : {___List}, 
        ni : {__Integer}] := \((#1\[LeftDoubleBracket]
              ni\[RightDoubleBracket] &)\) /@ dat;\)\[IndentingNewLine]
  \(Protect[Column];\)\n
  \(Norm[u_] := \@\(u . u\);\)\n
  \(Norm[u_, M_] := \@\(u . M . u\) /; MatrixQ[M];\)\n
  \(Norm[u_, m_] := \@\(u . \((m\ u)\)\) /; VectorQ[m];\)\n
  \(OneNorm[u : {__?NumberQ}] := u\/Norm[u];\)\n
  \(OneNorm[u : {__?NumberQ}, M_] := u\/Norm[u, M];\)\n
  \(OneNorm[mat : {__List}] := OneNorm /@ mat;\)\n
  \(OneNorm[mat : {__List}, M_] := \((OneNorm[#1, M] &)\) /@ mat;\)\n
  \(Mean[x_List] := Plus @@ x\/Length[x];\)\n
  \(Mean[x_List, Dp_] := Plus @@ \((Dp . x)\) /; MatrixQ[Dp];\)\n
  \(Mean[x_List, Dp_] := Plus @@ \((Dp\ x)\) /; VectorQ[Dp];\)\n
  \(ZeroMean[x : {__?NumberQ}] := x - Mean[x];\)\n
  \(ZeroMean[x : {__?NumberQ}, Dp_] := x - Mean[x, Dp];\)\n
  \(ZeroMean[X : {__List}] := Transpose[Transpose[X] - Mean[X]];\)\n
  \(ZeroMean[X : {__List}, Dp_] := Transpose[Transpose[X] - Mean[X, Dp]];\)\n
  \(Variance[x : {__?NumberQ}] := 
      With[{v = ZeroMean[x]}, v . v\/Length[x]];\)\n
  \(Variance[x : {__?NumberQ}, Dp_] := 
      With[{v = ZeroMean[x, Dp]}, v . Dp . v] /; MatrixQ[Dp];\)\n
  \(Variance[x : {__?NumberQ}, Dp_] := 
      With[{v = ZeroMean[x, Dp]}, v . \((Dp\ v)\)] /; VectorQ[Dp];\)\n
  \(Variance[mat : {__List}] := Variance /@ Transpose[mat];\)\n
  \(Variance[mat : {__List}, Dp_] := \((Variance[#1, Dp] &)\) /@ 
        Transpose[mat];\)\n
  \(StandardDeviation[x_] := \@Variance[x];\)\n
  \(StandardDeviation[x_, Dp_] := \@Variance[x, Dp];\)\n
  \(Covariance[x : {__?NumberQ}, y : {__?NumberQ}] := 
      ZeroMean[x] . ZeroMean[y]\/Length[x];\)\n
  \(Covariance[x : {__?NumberQ}, y : {__?NumberQ}, Dp_] := \n\t
      ZeroMean[x, Dp] . \((Dp\ \ ZeroMean[y])\) /; VectorQ[Dp];\)\n
  \(Covariance[x : {__?NumberQ}, y : {__?NumberQ}, Dp_] := \n\t
      ZeroMean[x, Dp] . Dp . ZeroMean[y] /; MatrixQ[Dp];\)\n
  \(Covariance[mat : {__List}] := 
      With[{xc = ZeroMean[mat]}, \n\tTranspose[xc] . xc\/Length[mat]] /; 
        MatrixQ[mat];\)\n
  \(Covariance[mat : {__List}, Dp_] := 
      With[{xc = ZeroMean[mat, Dp]}, \n\t\tTranspose[xc] . \((Dp\ xc)\)] /; 
        VectorQ[Dp];\)\n
  \(Covariance[mat : {__List}, Dp_] := 
      With[{xc = ZeroMean[mat, Dp]}, \n\t\tTranspose[xc] . Dp . xc] /; 
        MatrixQ[Dp];\)\n
  \(Correlation[x : {__?NumberQ}, y : {__?NumberQ}] := 
      Covariance[x, y]\/\(StandardDeviation[x]\ StandardDeviation[y]\);\)\n
  \(Correlation[x : {__?NumberQ}, y : {__?NumberQ}, Dp_] := 
      Covariance[x, y, Dp]\/\(StandardDeviation[x, Dp]\ StandardDeviation[y, \
Dp]\);\)\n
  \(Correlation[mat : {__List}] := 
      Module[{vc, d}, \n\t\tvc = Covariance[mat]; \n\t\td = 
          1/\@Table[vc\[LeftDoubleBracket]i, i\[RightDoubleBracket], {i, 1, \
Length[mat\[LeftDoubleBracket]1\[RightDoubleBracket]]}]; \n\t\td\ \ Thread[
            vc\ d]];\)\n
  \(Correlation[mat : {__List}, Dp_] := 
      Module[{vc, d}, \n\t\tvc = Covariance[mat, Dp]; \n\t\td = 
          1/\@Table[vc\[LeftDoubleBracket]i, i\[RightDoubleBracket], {i, 1, \
Length[mat\[LeftDoubleBracket]1\[RightDoubleBracket]]}]; \n\t\td\ \ Thread[
            vc\ d]];\)\[IndentingNewLine]
  \(Standardize[mat : {__List}] := 
      Module[{Xc, s}, \n\t\tXc = ZeroMean[mat]; \n\t\ts = 
          StandardDeviation[mat]; \n\t\t\ Map[\((#/s)\) &, 
          Xc]];\)\[IndentingNewLine]
  \(Standardize[mat : {__List}, Dp_] := 
      Module[{Xc, s}, \n\t\tXc = ZeroMean[mat, Dp]; \n\t\ts = 
          StandardDeviation[mat, Dp]; \n\t\tMap[\ \((#/s)\) &, \ \ Xc]];\)\)

End[];

EndPackage[];