ldaretrieval.cpp
来自「使用LDA实现三维模型相关反馈的算法注:1、使用本系统必须在本地计算机上安装ma」· C++ 代码 · 共 168 行
CPP
168 行
// LDAretrieval.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "LDAretrieval.h"
#include <fstream>
#include <string>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 唯一的应用程序对象
int round = -1;
double originfeaturesmatrix[OBJECTNUMBER][FEATHERLENTH];
double newfeaturesmatrix[OBJECTNUMBER][MAXCLASSNUM];
int allclassobjectmembers[MAXCLASSNUM][MAXOBJECTNUM];
int numofoneclass[MAXCLASSNUM];
int positiveobjects[OBJECTNUMBER];
int negativeobjects[OBJECTNUMBER];
int pandnobjects[OBJECTNUMBER];
int pandnnum;
int positivenum,negativenum;
double trans[MAXCLASSNUM][FEATHERLENTH];
double tempfeature[FEATHERLENTH];
double tempmatrix[FEATHERLENTH][FEATHERLENTH];
double tempsb[FEATHERLENTH*FEATHERLENTH];
double tempsw[FEATHERLENTH*FEATHERLENTH];
double* temptrans;
double Sb[FEATHERLENTH][FEATHERLENTH];
double Sw[FEATHERLENTH][FEATHERLENTH];
double mx[FEATHERLENTH];
double my[FEATHERLENTH];
double mm[FEATHERLENTH];
CWinApp theApp;
using namespace std;
void inputdataTransform()
{
CString infolderpath = "F:\\课题组\\fengleisvm\\TrainFVs(SIL300)\\";
//特征向量文件所在的路径
ofstream outfilename("featuresinfile.txt");
ifstream listfilename("train_classification.txt");
ifstream infilename;
CString ftitle;
CString fpath;
string tempstr;
int pos;
CString tfeature;
CString Ctempstr;
while (getline(listfilename,tempstr))
{
Ctempstr = tempstr.c_str();
infilename.open(infolderpath+"m"+Ctempstr+".txt");
//outfilename<<Ctempstr<<" ";
getline(infilename,tempstr);
infilename.close();
Ctempstr = tempstr.c_str();
pos = Ctempstr.Find(" ");
tfeature = Ctempstr.Left(pos);
outfilename<<tfeature<<" ";
Ctempstr.Delete(0,pos+1);
for (int i = 2; i < FEATHERLENTH+1; i++)
{
pos = Ctempstr.Find(" ");
tfeature = Ctempstr.Left(pos);
outfilename<<tfeature<<" ";
Ctempstr.Delete(0,pos+1);
}
outfilename<<endl;
//转换完一个特征向量
}
outfilename.close();
listfilename.close();
//infilename.close();
AfxMessageBox("finished");
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// 初始化 MFC 并在失败时显示错误
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: 更改错误代码以符合您的需要
_tprintf(_T("致命错误: MFC 初始化失败\n"));
nRetCode = 1;
}
else
{
// TODO: 在此处为应用程序的行为编写代码。
//inputdataTransform();
//////////////////////////////////////////////////////////////////////////
//文件转换部分,使用一次即可
//////////////////////////////////////////////////////////////////////////
//变量存储部分的初始化
CStorage storageobject;
storageobject.readalllabelsfromfile("train.txt");
storageobject.readallfeaturesfromfile("featuresinfile.txt");
//矩阵运算部分初始化
CMatrix matrixobject;
cout<<"Loading Complete!"<<endl;
//storageobject.labelnumber = 20;
//设定标记个数
int i,j;
//对所有模型遍历
for (i=0;i<MAXCLASSNUM;i++)//当前类
{
for (j=0;j<numofoneclass[i];j++)//当前模型
{
storageobject.computedistance(allclassobjectmembers[i][j]);
//初始化标注
pandnnum = 0;
positivenum = 0;
negativenum = 0;
for (round=0;round< ROUNDNUM ;round++)//反复反馈
{
storageobject.labelretrieval(i);
matrixobject.initvariables();
matrixobject.computemx();//positive
matrixobject.computemy();//negative
matrixobject.computeSb();
matrixobject.computeSw();
matrixobject.computetransformmatrix();
storageobject.computenewfeaturematrix();
storageobject.computedistancenew(allclassobjectmembers[i][j]);
}
cout<<allclassobjectmembers[i][j]<<endl;
}
}
}
return nRetCode;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?