/*
*
* mexCCACollectdata.c
* prepare data for cca.m to form SDP
*
* by feisha@cis.upenn.edu
*/
#include "mex.h"
#include "matrix.h"
#include <stdlib.h>
#include <float.h>
#include <string.h>
#include <math.h>
/* the computation engine */
void collectdata(double *x, double *y, int* edgerow, int *edgecol, int *relative,
int *nv, int *vidx, int D, int d, int n, int ks, double *a, double *b, double *g);
/* auxiliary functions */
void sanity_check(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]);
/* the gateway */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int n, ks=1, D, d;
double *x, *y, *a, *b, *g;
int *neighbors;
/* sanity_check(nlhs, plhs, nrhs, prhs); */
n = mxGetN(prhs[0]);
D = mxGetM(prhs[0]);
d = mxGetM(prhs[1]);
/*printf("%d data points, reducing from dimension %d ---> dimension %d, using \
%d nearest neighbors\n", n, D, d, ks); */
plhs[0] = mxCreateDoubleMatrix(d*d, d*d, mxREAL);
plhs[1] = mxCreateDoubleMatrix(d*d, n, mxREAL);
plhs[2] = mxCreateDoubleMatrix(n,1, mxREAL);
collectdata( (double*)mxGetData(prhs[0]),
(double*)mxGetData(prhs[1]),
(int*)mxGetData(prhs[2]),
(int*)mxGetData(prhs[3]),
(int*)mxGetData(prhs[4]),
(int*)mxGetData(prhs[5]),
(int*)mxGetData(prhs[6]),
D, d, n, ks,
(double*)mxGetData(plhs[0]),
(double*)mxGetData(plhs[1]),
(double*)mxGetData(plhs[2]));
return;
}
/* check input arguments */
void sanity_check(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int n1, n2, n3;
/* Check for proper number of input and output arguments. */
if (nrhs != 4) {
mexErrMsgTxt("Four input argument required.");
}
if (nlhs != 3) {
mexErrMsgTxt("Three output arguments required.");
}
/* Check data type of input argument. */
/*if (!(mxIsDouble(prhs[0])) || !(mxIsDouble(prhs[1])) || !(mxIsDouble(prhs[2]))) {
mexErrMsgTxt("Input array must be of type double.");
}*/
/* Check dimensions */
if(mxGetNumberOfDimensions(prhs[0])!=2 || mxGetNumberOfDimensions(prhs[1])!=2 || mxGetNumberOfDimensions(prhs[2])!=2) {
mexErrMsgTxt("Input arrays must be two-dimension arrays");
}
/* matching dimensions */
n1 = mxGetN(prhs[0]);
n2 = mxGetN(prhs[1]);
n3 = mxGetN(prhs[2]);
if (n1 != n2 || n1 !=n3) {
mexErrMsgTxt("Input arrays must have same number of columns!");
}
return;
}
/* computing */
double vecdot(double* v1, int n) { /* v1'*v2 */
double x = 0;
int i;
for(i = 0; i < n; i++) {
x += v1[i]*v1[i];
}
return x;
}
void vecsub(double* v1,double* v2, double* v3, int n) { /* v3=v1-v2 */
int incx=1;
double none = -1;
/* dcopy_(&n, v1, &incx,v3, &incx);
daxpy_(&n, &none, v2, &incx, v3, &incx);*/
int i;
for(i=0;i<n;i++) v3[i]=v1[i]-v2[i];
}
void vecout(double* v1, double* v3, int d) { /* v3 = v1*v2' */
double temp,one = 1.0;
int inca = 1;
int i,j,c;
/* dger_(&d , &d, &one, v1, &inca,v1, &inca, v3, &d); */
c=0;
for(i=0;i<d;i++){
temp=v1[i];
for(j=0;j<d;j++){
v3[c]=temp*v1[j];
c++;
}
}
}
void makevecsym(double *v, int d) { /* assume V is a dxd matrix, return (V+V')/2 */
int row, col, i;
double temp;
for(col=0; col < d; col++) {
for(row=col; row < d; row++) {
temp = (v[row*d+col] + v[col*d+row])/2;
v[row*d+col] = v[col*d+row] = temp;
}
}
}
void updateA(double *a, double *v, double alpha, int d) { /* update A */
int inca = 1;
char *uplo= "U";
double temp;
int i,j,c;
/* dspr_(uplo, &d , &alpha, v, &inca, a);*/
if(alpha==1.0){ /*optimize the common case */
c=0;
for(i=0;i<d;i++){
temp=v[i];
for(j=0;j<=i;j++) {
a[c]+=temp*v[j];
c++;
}
}
} else{
c=0;
for(i=0;i<d;i++){
temp=v[i]*alpha;
for(j=0;j<=i;j++) {
a[c]+=temp*v[j];
c++;
}
}
}
}
void updateB(double * b, double alpha, double *v, int d) { /* update B(:,i) */
int i;
int incx = 1;
/* daxpy_(&d, &alpha, v, &incx, b, &incx);*/
for(i=0;i<d;i++) b[i]+=alpha*v[i];
}
/* transform upper triangular matrix stored in A as full matrix */
void recoverA(int D, double *A, double *tempA)
{
int l = 0, idx, jdx,s, incx=1, incy=1;
int n = D*(D+1)/2;
for(jdx=0; jdx <D; jdx++) {
for(idx=0; idx <=jdx; idx++) {
A[jdx*D+idx] = tempA[l];
l++;
}
}
for(jdx=0; jdx <D; jdx++)
for(idx=jdx; idx <D; idx++) {
A[jdx*D+idx] = A[idx*D+jdx];
}
}
void collectdata(double *x, double *y, int* edgesrow, int *edgescol, int *relative, int *nv,
int *vidx, int D, int d, int n, int ks, double *a, double *b, double *g)
{
double *diffx, *diffy, *yij, *nid;
double gij;
int i, j, k, iEdge, iVertex,itemp, ii;
int nn_start, nn_end, nn;
double *diffxjk, *diffyjk;
double gjk, *yjk, *tempA;
int relflg = *relative;
/* clear data area */
memset(a, 0, sizeof(double)*d*d*d*d);
memset(b, 0, sizeof(double)*d*d*n);
memset(g, 0, sizeof(double)*n);
/* temporary working space */
diffx = (double*)calloc(D, sizeof(double));
diffy = (double*)calloc(d, sizeof(double));
yij = (double*)calloc(d*d, sizeof(double));
tempA = (double*)calloc((d*d)*(d*d+1)/2, sizeof(double));
if(!diffx || !diffy || !yij || !tempA) {
mexErrMsgTxt("Out of memory..cannot allocate working space..");
return;
}
iEdge = 0;
iVertex = 0;
if(relflg==0) {
for(i=0; i <n ; i++) {
/* figure out the nearest neighbors */
nn_start = edgescol[i]; nn_end = edgescol[i+1]-1;
if (nn_end >= nn_start) {
for(nn=nn_start; nn<=nn_end; nn++) {
j = edgesrow[nn];
/* compute diffx and diffy */
vecsub(x+i*D, x+j*D, diffx, D);
gij = vecdot(diffx, D);
vecsub(y+i*d, y+j*d, diffy, d);
vecout(diffy, yij, d);
/* update A, b */
updateA(tempA, yij, 1.0*nv[iEdge],d*d);
for(itemp=0; itemp < nv[iEdge]; itemp++) {
ii = vidx[iVertex]-1;
updateB(b+ii*d*d, gij, yij, d*d);
g[ii] = g[ii]+gij*gij;
iVertex++;
}
iEdge++;
}
}
}
printf("Iedge :%d, ivertex: %d\n", iEdge, iVertex);
} else {
/* reproducing the code above to some degree so that we don't have to
do if statement inside cache-intensive loop */
for(i=0; i <n ; i++) {
/* figure out the nearest neighbors */
nn_start = edgescol[i]; nn_end = edgescol[i+1]-1;
if (nn_end >= nn_start) {
for(nn=nn_start; nn<=nn_end; nn++) {
j = edgesrow[nn];
/* compute diffx and diffy */
vecsub(x+i*D, x+j*D, diffx, D);
gij = vecdot(diffx, D);
vecsub(y+i*d, y+j*d, diffy, d);
vecout(diffy, yij, d);
/* update A, b */
updateA(tempA, yij, 1*nv[iEdge]/(gij*gij), d*d);
for(itemp=0; itemp < nv[iEdge]; itemp++) {
ii = vidx[iVertex]-1;
updateB(b+ii*d*d, 1/gij, yij, d*d);
g[ii] = g[ii]+1;
iVertex++;
没有合适的资源?快使用搜索试试~ 我知道了~
MATLAB_Codes_for_Dimensionality_Reduction.rar_dimention reductio
共90个文件
m:63个
dll:4个
mexmaci:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 177 浏览量
2022-07-14
02:18:29
上传
评论
收藏 867KB RAR 举报
温馨提示
dimention reduction algorithm using matlab
资源推荐
资源详情
资源评论
收起资源包目录
MATLAB_Codes_for_Dimensionality_Reduction.rar (90个子文件)
MATLAB_Codes_for_Dimensionality_Reduction
MATLAB Codes for Dimensionality Reduction
components.m 2KB
gram.m 2KB
mexCCACollectData2.mexmaci 17KB
mppca.m 5KB
mexCCACollectData.c 8KB
pca.m 2KB
mexall.m 1KB
compute_mapping.m 15KB
computegr.mexmaci 13KB
prewhiten.m 2KB
mexCCACollectData2.mexa64 10KB
mexCCACollectData2.dll 8KB
charting.m 3KB
cca.m 15KB
diffusion_maps.m 3KB
spca.m 2KB
fibheap.h 3KB
mgs.m 995B
hillclimber2c.m 1KB
mexCCACollectData.mexmaci 17KB
backprop.m 5KB
find_nn.m 3KB
find_nn_adaptive.m 3KB
run_llc.m 2KB
sdecca2.m 9KB
dijk.m 4KB
out_of_sample.m 3KB
welcome.m 1KB
fastmvu.m 4KB
hlle.m 4KB
sparse_nn.m 983B
sne.m 4KB
hill_obj.m 792B
dijkstra.mexmaci 25KB
ltsa.m 3KB
L2_distance.m 2KB
spe.m 4KB
dijkstra.cpp 27KB
mexCCACollectData.dll 7KB
landmark_isomap.m 3KB
llc.m 4KB
computegr.mexa64 9KB
infermfa.m 2KB
dijkstra.dll 9KB
mexCCACollectData2.c 6KB
out_of_sample_est.m 2KB
intrinsic_dim.m 9KB
csdp.m 5KB
csdpmac 81KB
entropy.m 1KB
kernel_pca.m 4KB
mexCCACollectData.mexa64 12KB
dijkstra.m 2KB
lda.m 2KB
jdqr.m 71KB
Contents.m 62B
csdplinux 1.62MB
find_nn.c 4KB
dijkstra.mexa64 21KB
computegr.c 3KB
rbm.m 4KB
em_pca.m 3KB
autoencoder.m 3KB
mds.m 2KB
computegr.dll 7KB
lle.m 4KB
laplacian_eigen.m 3KB
computegr.mexglx 6KB
writesdpa.m 8KB
csdpmaci 88KB
mexCCACollectData2.mexglx 8KB
npe.m 3KB
hs_err_pid1128.log 8KB
dijkstra.mexglx 17KB
minimize.m 8KB
autoencoder_ea.m 7KB
lpp.m 3KB
jdqz.m 77KB
readsol.m 4KB
mexCCACollectData.mexglx 9KB
gda.m 4KB
lltsa.m 3KB
csdp.exe 1.06MB
cg_update.m 4KB
cfa.m 6KB
kernel_function.m 5KB
iterative_spca.m 874B
rbmhidlinear.m 4KB
isomap.m 2KB
generate_data.m 4KB
共 90 条
- 1
资源评论
weixin_42651887
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- fdgsfdgfdsgsf
- 基于CodeMirror5实现的mybatis+sql提示扩展功能,主要是用于在线设计开发场景中的动态sql部分.zip
- 计算机毕业设计-aSP.NET某中学学生成绩管理系统的设计(源代码+)-毕设源码实例.zip
- springboot集成mybatis动态sql.zip
- mybatis中的动态sql, 涉及 where trim set if foreach等
- 简单- 快递运输(Java & JS & Python & C).html
- mybatis框架 更改ems系统,使用动态sql等.zip
- 易语言工具条下拉菜单实现
- Mybatis动态SQL高级映射.zip
- 源码esp8266开发板机智云机智云智能灯
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功