00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _STREAMDCTRAIN_H
00035 #define _STREAMDCTRAIN_H
00036
00037 #include "dctraingen.h"
00038 #include <iostream>
00039 #include "general.h"
00040
00041 using namespace std;
00042
00043 namespace CLUS
00044 {
00045
00046 class StreamDCTrainingData : public DCTrainingData
00047 {
00048
00049 protected:
00050 istream& in;
00051
00052 public:
00053 StreamDCTrainingData(istream& In, int M, int Ddims, int Cdims,
00054 Vector<int>& DDomainSize) :
00055 DCTrainingData(M,Ddims,Cdims,DDomainSize), in(In)
00056 {
00057 int d_dims = NumDiscreteCols();
00058 int c_dims = NumCols();
00059 for (int i=0; i<M; i++)
00060 {
00061
00062 int* d_data = DTable[i];
00063 for (int j=0; j<d_dims; j++)
00064 {
00065 in >> d_data[j];
00066 assert(d_data[j]>=0);
00067
00068 assert( d_data[j] < dDomainSize[j]);
00069
00070 ExitIf ( (d_data[j] < 0 || d_data[j] >= dDomainSize[j]), "Discrete value out of bounds" );
00071 }
00072
00073 double* data=Table[i];
00074 for(int j=0; j<c_dims; j++)
00075 in >> data[j];
00076 in.ignore(BIG_NR,'\n');
00077 }
00078 }
00079 };
00080
00081 StreamDCTrainingData* CreateStreamDCTrainingDataFromFile(char* filename)
00082 {
00083
00084
00085
00086
00087
00088
00089 StreamDCTrainingData* data;
00090 ifstream in(filename);
00091 int M, d_dims, c_dims;
00092
00093 string sharp;
00094
00095 in >> sharp;
00096 ExitIf( (sharp!="#"), "Incorrect file format" );
00097
00098 in >> M;
00099 in >> d_dims;
00100 in >> c_dims;
00101
00102 Vector<int> dDomainSize(d_dims);
00103
00104 if (d_dims > 0)
00105 {
00106 in >> sharp;
00107 ExitIf( (sharp!="#"), "Incorrect file format" );
00108
00109 for (int i=0; i<d_dims; i++)
00110 in >> dDomainSize[i];
00111 }
00112
00113 data = new StreamDCTrainingData(in,M,d_dims,c_dims,dDomainSize);
00114 return data;
00115 }
00116
00117 }
00118
00119 #endif // _STREAMDCTRAIN_H