• 大小: 12.21MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-06-29
  • 语言: Matlab
  • 标签: sparse  codin  

资源简介

稀疏编码的matlab 程序实现,UC伯克利written by Bruno Olshausen

资源截图

代码片段和文件信息

/*
 * cgf.c: conj. grad. routine for finding optimal s - fast!
 */
#include 
#include 
#include “mex.h“

extern float frprmn();


#define sgn(x) (x>0 ? 1 : (x<0 ? -1 : 0))

extern  __declspec( dllexport )
void cgf(double *Sout double *nits double *nf double *ng
       double *Sin double *X int npats 
       double tol int maxiter int numflag);

/* Input & Output Arguments */

#define A_IN prhs[0] /* basis matrix */
#define X_IN prhs[1] /* data vectors */
#define S_IN prhs[2] /* initial guess for S */
#define LAMBDA_IN prhs[3] /* precision */
#define BETA_IN prhs[4] /* prior steepness */
#define SIGMA_IN        prhs[5]         /* scaling parameter for prior */
#define TOL_IN prhs[6] /* tolerance */
#define MAXITER_IN      prhs[7] /* maximum iterations for dfrpmin */
#define OUTFLAG_IN prhs[8] /* output flag */
#define NUMFLAG_IN prhs[9] /* pattern number output flag */

#define S_OUT           plhs[0] /* basis coeffs for each data vector */
#define NITS_OUT        plhs[1]         /* total iterations done by cg */
#define NF_OUT          plhs[2]         /* total P(s|xA) calcs */
#define NG_OUT          plhs[3]         /* total d/ds P(s|xA) calcs */

/* Define indexing macros for matricies */

/* L = dimension of input vectors
 * M = number of basis functions
 */

#define A_(ij) A[(i) + (j)*L] /* A is L x M */
#define X_(in) X[(i) + (n)*L] /* X is L x npats */

#define Sout_(in) Sout[(i) + (n)*M] /* S is M x npats */
#define Sin_(in) Sin[(i) + (n)*M] /* S is M x npats */

#define AtA_(ij) AtA[(i) + (j)*M] /* AtA is M x M */

/* Globals for using with frprmin */

static double *A; /* basis matrix */
static int L; /* data dimension */
static int M; /* number of basis vectors */
static double lambda; /* 1/noise_var */
static double beta; /* prior steepness */
static double sigma; /* prior scaling */
static double k1k2k3; /* precomputed constants for f1dim */

static double *x; /* current data vector being fitted */
static double *s0; /* init coefficient vector (1:M) */
static double *d; /* search dir. coefficient vector (1:M) */
static int outflag; /* print search progress */

static double *AtA; /* Only compute A‘*A once (1:M1:M) */
static double *Atx; /* A*x (1:M) */

static int fcount gcount;

static void init_global_arrays() 
{
  int  ijk;
  double *Ai *Aj sum;

  x      = (double *)malloc(L*sizeof(double));
  s0     = (double *)malloc(M*sizeof(double));
  d      = (double *)malloc(M*sizeof(double));
  AtA    = (double *)malloc(M*M*sizeof(double));
  Atx    = (double *)malloc(M*sizeof(double));

  /* Calc  A‘*A */
  for (i = 0; i < M; i++) {
    Ai=A+i*L;
    for (j = 0; j < M; j++) {
      Aj=A+j*L;
      sum=0.0;
      for (k = 0; k < L; k++) {
sum += Ai[k]*Aj[k];
      }
      AtA_(ij) = sum;
    }
  }
}

static void free_global_arrays() {

  free((double *)x);
  free((double *)s0);
  free((double *)d);
  free((double *)AtA);
  free((double *)Atx);
}



float init_f1

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2002-03-11 13:41  Code\Matlab\Bruno\sparsenet\
     文件      524472  2002-02-28 11:52  Code\Matlab\Bruno\sparsenet\A16.mat
     文件        7457  2002-02-27 12:22  Code\Matlab\Bruno\sparsenet\cgf.c
     文件       40960  2002-02-27 13:50  Code\Matlab\Bruno\sparsenet\cgf.dll
     文件       35250  2002-02-27 13:50  Code\Matlab\Bruno\sparsenet\cgf.map
     文件        1419  2002-02-27 14:35  Code\Matlab\Bruno\sparsenet\cgf_fitS.m
     文件         442  1998-04-14 21:43  Code\Matlab\Bruno\sparsenet\display_network.m
     文件    20971712  2000-07-12 12:05  Code\Matlab\Bruno\sparsenet\IMAGES.mat
     文件         975  2000-07-12 12:07  Code\Matlab\Bruno\sparsenet\make-your-own-images
     文件          97  2002-02-27 13:42  Code\Matlab\Bruno\sparsenet\makefile
     目录           0  2002-03-11 13:26  Code\Matlab\Bruno\sparsenet\nrf\
     文件        1494  2002-03-11 13:25  Code\Matlab\Bruno\sparsenet\nrf\brent.c
     文件        2010  2002-03-11 13:25  Code\Matlab\Bruno\sparsenet\nrf\brent.obj
     文件        1204  2002-03-11 13:25  Code\Matlab\Bruno\sparsenet\nrf\frprmn.c
     文件        1603  2002-03-11 13:25  Code\Matlab\Bruno\sparsenet\nrf\frprmn.obj
     文件         447  2002-03-11 13:25  Code\Matlab\Bruno\sparsenet\nrf\linmin.c
     文件         664  2002-03-11 13:25  Code\Matlab\Bruno\sparsenet\nrf\linmin.obj
     文件         386  2002-02-27 13:44  Code\Matlab\Bruno\sparsenet\nrf\makefile
     文件         176  2002-02-26 14:23  Code\Matlab\Bruno\sparsenet\nrf\Makefile.original
     文件         386  2002-02-27 13:46  Code\Matlab\Bruno\sparsenet\nrf\Makefile.vc
     文件         419  2002-03-11 13:25  Code\Matlab\Bruno\sparsenet\nrf\makefile.vcG6
     文件         509  2002-03-11 13:26  Code\Matlab\Bruno\sparsenet\nrf\makefile.vcGB
     文件        1309  2002-03-11 13:25  Code\Matlab\Bruno\sparsenet\nrf\mnbrak.c
     文件        1814  2002-03-11 13:25  Code\Matlab\Bruno\sparsenet\nrf\mnbrak.obj
     文件       45056  2002-02-27 13:44  Code\Matlab\Bruno\sparsenet\nrf\nrfopt.dll
     文件        1073  2002-02-27 13:44  Code\Matlab\Bruno\sparsenet\nrf\nrfopt.exp
     文件         609  2002-02-27 10:41  Code\Matlab\Bruno\sparsenet\nrf\nrfopt.h
     文件        2860  2002-02-27 13:44  Code\Matlab\Bruno\sparsenet\nrf\nrfopt.lib
     文件       34854  2002-02-27 13:44  Code\Matlab\Bruno\sparsenet\nrf\nrfopt.map
     文件       45056  2002-03-11 13:26  Code\Matlab\Bruno\sparsenet\nrf\nrfoptGB.dll
     文件        1081  2002-03-11 13:26  Code\Matlab\Bruno\sparsenet\nrf\nrfoptGB.exp
............此处省略17个文件信息

评论

共有 条评论