📄 kddcup98data.cpp
字号:
/* Scalable K-means clustering softwareCopyright (C) 2000 Fredrik Farnstrom and James LewisThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.See the file README.TXT for more information.*//* kddcup98data.cpp */#include <math.h>#include <stdio.h>#include <stdlib.h>#include <time.h>#include "singleton.h"#include "subcluster.h"#include "database.h"#include "kddcup98data.h"#define READBINARY 1KddCupData::KddCupData(){ data = new float[dimensions]; mean = new float[dimensions]; stdDev = new float[dimensions]; DataFp = NULL; numPoints = 0;}KddCupData::~KddCupData(void){ delete []data; delete []mean; delete []stdDev;}// Reset counter, i.e return first point next time getPoint is called.void KddCupData::reset(void){ if (DataFp != NULL) fclose(DataFp); if ((DataFp = fopen("cup98msd.txt", "r")) == NULL) { perror("Unable to open data file."); exit(1); } for (int i = 0; i < dimensions; i++) { if ((fscanf(DataFp, "%f", &mean[i])) != 1) { perror("Error reading stat file."); exit(0); } } for (int i = 0; i < dimensions; i++) { if ((fscanf(DataFp, "%f", &stdDev[i])) != 1) { perror("Error reading stat file."); exit(0); } } if (DataFp != NULL) fclose(DataFp);#if READBINARY != 1 if ((DataFp = fopen("cup98b.dat", "r")) == NULL) {#else if ((DataFp = fopen("cup98data.dat", "r")) == NULL) {#endif perror("Unable to open data file."); exit(1); } numPoints = 0;}// Return a pointer to an array of floats containing the current point.// The allocated memory may be read by the user but belongs to the// Database class.float *KddCupData::getPoint(void){ // Read next record. float tmp;#if READBINARY != 1 for (int i = 0; i < dimensions; i++) { if ((fscanf(DataFp, "%f", &tmp) != 1)) return 0; else if(tmp < 0) data[i] = 0; else data[i] = (tmp - mean[i]) / stdDev[i]; }#else if(fread(data, sizeof(float), dimensions, DataFp) != dimensions) return 0; for (int i = 0; i < dimensions; i++) { if(data[i] < 0) data[i] = 0; else data[i] = (data[i] - mean[i]) / stdDev[i]; }#endif numPoints++; if(!(numPoints%1000)) fprintf(stderr, "%d\n", numPoints); return data;}/* End of file kddcup98data.cpp */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -