Main Page | Namespace List | Class Hierarchy | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

streamdctrain.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (c) 2003, Cornell University
00004 All rights reserved.
00005 
00006 Redistribution and use in source and binary forms, with or without
00007 modification, are permitted provided that the following conditions are met:
00008 
00009    - Redistributions of source code must retain the above copyright notice,
00010        this list of conditions and the following disclaimer.
00011    - Redistributions in binary form must reproduce the above copyright
00012        notice, this list of conditions and the following disclaimer in the
00013        documentation and/or other materials provided with the distribution.
00014    - Neither the name of Cornell University nor the names of its
00015        contributors may be used to endorse or promote products derived from
00016        this software without specific prior written permission.
00017 
00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00022 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00028 THE POSSIBILITY OF SUCH DAMAGE.
00029 
00030 */
00031 
00032 // -*- C++ -*-
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             // read first the discrete variables and check the range
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                 //cerr << dDomainSize[j] << endl;
00068                 assert( d_data[j] < dDomainSize[j]);
00069                 // check if out of the domain
00070                 ExitIf ( (d_data[j] < 0 || d_data[j] >= dDomainSize[j]), "Discrete value out of bounds" );
00071             }
00072             // read the continuous part
00073             double* data=Table[i];
00074             for(int j=0; j<c_dims; j++)
00075                 in >> data[j];
00076             in.ignore(BIG_NR,'\n'); // ignore the rest of the line
00077         }
00078     }
00079 };
00080 
00081 StreamDCTrainingData* CreateStreamDCTrainingDataFromFile(char* filename)
00082 {
00083     /* The file looks like:
00084        # M d_dims c_dims
00085        # d1 d2 d3 ... d_{d_dims}
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

Generated on Mon Jul 21 16:57:25 2003 for SECRET by doxygen 1.3.2