com.waspring.wasindoor.locale.libsvm.SVMTrainer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wasindoor Show documentation
Show all versions of wasindoor Show documentation
冰泉室内定位,一种基于wifi和地磁信号的室内定位解决方案,集成svm和knn等算法
The newest version!
package com.waspring.wasindoor.locale.libsvm;
import java.io.File;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.waspring.wasdbtools.DaoUtil;
import com.waspring.wasindoor.locale.DivideIntoFoldsTrain;
public class SVMTrainer {
//private String gmTrainFileAddr; //ѵ���ļ�����Ŀ¼
private Integer buildingId; //��������
private Integer floor; //�ڼ���
private int rowsInOneline; //ѵ���ļ���ÿ���м������
private int numOfLocation; //��ǰ������ǰ¥���еĵص����
private int numOfFolds; //ѵ���ļ�360�ȷ��۵�����
public SVMTrainer(Integer buildingId, Integer floor, int rowsInOneline, int numOfLocation, int numOfFolds)
{
this.buildingId = buildingId;
this.floor = floor;
this.rowsInOneline = rowsInOneline;
this.numOfLocation = numOfLocation;
this.numOfFolds = numOfFolds;
}
//����ѵ��model�ļ�
//�����ļ�ÿ��Ϊ�� -160��z�Ƕȣ� 30.03(x��ǿ) 40.67(y��ǿ) -79.04(z��ǿ) 1(���ǩ)
//���Զ����и�ʽת����1 1:30.03 2:40.67 3��-79.04��������������
public boolean buildTrainModel(String gmTrainFileAddr){
//ѵ�����
//step 1: ת����ʽ
String completeFileAddr = gmTrainFileAddr + File.separator + buildingId + File.separator + floor + File.separator+"train.txt";
// 5��ÿ������, 28�Dz���λ�ø���8������
DivideIntoFoldsTrain di = new DivideIntoFoldsTrain(completeFileAddr, rowsInOneline, numOfLocation, numOfFolds);
if(di.readFile()!=1)
{
System.out.println("ѵ����ݸ�ʽת�����?�� ��");
return false;
}
int start_index = completeFileAddr.lastIndexOf(File.separator);
int end_index = completeFileAddr.lastIndexOf(".");
String fileName = completeFileAddr.substring(start_index+1, end_index);
String fileAddrTrim = completeFileAddr.substring(0,end_index); //ȥ����.txt
String fileAddrWithoutFileName = completeFileAddr.substring(0,start_index);
//step 2: ��ݱ���
//�ȵõ�һ�����������model
String [] scaleArgs = {"-l","-1","-u","1","-s",fileAddrTrim+"_scale_model",fileAddrTrim + "_whole.txt"};
try {
SVMScaler s = new SVMScaler(fileAddrTrim + "_whole_scale.txt");
s.scaleIntoFile(scaleArgs);
} catch (IOException e) {
e.printStackTrace();
System.out.println("��ݱ������?�� ��");
return false;
}
// ÿ���۵���ݸ��model���б���
for(int i=0;i