This file is indexed.

/usr/include/timbl/TimblExperiment.h is in libtimbl4-dev 6.4.6-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/*
  $Id: TimblExperiment.h 16820 2014-01-06 10:12:30Z sloot $
  $URL: https://ilk.uvt.nl/svn/trunk/sources/Timbl6/include/timbl/TimblExperiment.h $

  Copyright (c) 1998 - 2014
  ILK   - Tilburg University
  CLiPS - University of Antwerp

  This file is part of timbl

  timbl is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 3 of the License, or
  (at your option) any later version.

  timbl is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, see <http://www.gnu.org/licenses/>.

  For questions and suggestions, see:
      http://ilk.uvt.nl/software.html
  or send mail to:
      timbl@uvt.nl
*/

#ifndef TIMBL_EXPERIMENT_H
#define TIMBL_EXPERIMENT_H

#include <sys/time.h>
#include <fstream>
#include <set>
#include "ticcutils/XMLtools.h"
#include "timbl/BestArray.h"
#include "timbl/Statistics.h"
#include "timbl/MBLClass.h"

namespace Timbl {

  class TimblAPI;
  class ConfusionMatrix;
  class CL_Options;
  class GetOptClass;

  class resultStore: public MsgClass {
  public:
  resultStore(): dist(0), disposable(false), isTop(false), beam(0) {};
    ~resultStore();
    bool reset( int, normType, double, const Target * );
    void clear();
    void addConstant( const ValueDistribution * );
    void addTop( const ValueDistribution * );
    void addDisposable( ValueDistribution * );
    const WValueDistribution *getResultDist();
    std::string getResult();
    void prepare();
    void normalize();
    double confidence( const TargetValue* tv ) const {
      return dist->Confidence( tv );
    };
  private:
    const ValueDistribution *rawDist;
    WValueDistribution *dist;
    bool disposable;
    bool isTop;
    int beam;
    normType norm;
    double factor;
    const Target *targets;
    std::string topCache;
    std::string resultCache;
  };

  class fCmp {
  public:
    bool operator()( const FeatureValue* F, const FeatureValue* G ) const{
      return F->Index() > G->Index();
    }
  };

  typedef std::map<FeatureValue*,std::set<std::streamsize>, fCmp> fileIndex;
  typedef std::map<FeatureValue*, fileIndex, fCmp > fileDoubleIndex;
  std::ostream& operator<< ( std::ostream&, const fileIndex& );
  std::ostream& operator<< ( std::ostream&, const fileDoubleIndex& );

  class threadData;

  class TimblExperiment: public MBLClass {
    friend class TimblAPI;
    friend class threadData;
    friend class threadBlock;
  public:
    virtual ~TimblExperiment();
    virtual TimblExperiment *clone() const = 0;
    TimblExperiment& operator=( const TimblExperiment& );
    virtual bool Prepare( const std::string& = "", bool = true, bool = false );
    virtual bool CVprepare( const std::string& = "",
			    WeightType = GR_w,
			    const std::string& = "" );
    virtual bool Increment( const std::string& )
    { FatalError( "Increment" ); return false; };
    virtual bool Decrement( const std::string& )
    { FatalError( "Decrement" ); return false; };
    virtual bool Expand( const std::string& );
    virtual bool Remove( const std::string& ){
    FatalError( "Remove" ); return false;};
    virtual bool Test( const std::string&,
		       const std::string& );
    virtual bool NS_Test( const std::string&,
			  const std::string& );
    virtual void InitInstanceBase() = 0;
    virtual bool ReadInstanceBase( const std::string& );
    virtual bool WriteInstanceBase( const std::string& );
    bool chopLine( const std::string& );
    bool WriteInstanceBaseXml( const std::string& );
    bool WriteInstanceBaseLevels( const std::string&, unsigned int );
    bool WriteNamesFile( const std::string& ) const;
    virtual bool Learn( const std::string& = "", bool = true );
    int Estimate() const { return estimate; };
    void Estimate( int e ){ estimate = e; };
    int Clones() const { return numOfThreads; };
    void Clones( int cl ) { numOfThreads = cl; };
    void setOutPath( const std::string& s ){ outPath = s; };
    TimblExperiment *CreateClient( int  ) const;
    TimblExperiment *splitChild() const;
    bool SetOptions( int, const char ** );
    bool SetOptions( const std::string& );
    bool SetOptions( const CL_Options&  );
    bool IndirectOptions( const CL_Options&  );
    bool ConfirmOptions();
    bool DefaultOptions();
    GetOptClass *getOptParams() const { return OptParams; };
    void setOptParams( GetOptClass *op ) { OptParams = op; };
    bool WriteArrays( const std::string& );
    bool GetArrays( const std::string& );
    bool WriteMatrices( const std::string& );
    bool GetMatrices( const std::string& );
    bool SaveWeights( const std::string& );
    bool GetWeights( const std::string&, WeightType );
    bool GetCurrentWeights( std::vector<double>& );
    xmlNode *weightsToXML();
    bool ShowOptions( std::ostream& );
    bool ShowSettings( std::ostream& );
    xmlNode *settingsToXML();
    bool showBestNeighbors( std::ostream& ) const;
    xmlNode *bestNeighborsToXML() const;
    bool showStatistics( std::ostream& ) const;
    void showInputFormat( std::ostream& ) const;
    const std::string& ExpName() const { return exp_name; };
    void setExpName( const std::string& s ) { exp_name = s; };
    bool Classify( const std::string& , std::string& );
    bool Classify( const std::string& , std::string&, double& );
    bool Classify( const std::string& , std::string&, std::string&, double& );
    size_t matchDepth() const { return match_depth; };
    bool matchedAtLeaf() const { return last_leaf; };

    virtual AlgorithmType Algorithm() const = 0;
    const TargetValue *Classify( const std::string& Line,
				 const ValueDistribution *& db,
				 double& di ){
      const TargetValue *res = classifyString( Line, di );
      if ( res ){
	normalizeResult();
	db = bestResult.getResultDist();
      }
      return res;
    }
    const TargetValue *Classify( const std::string& Line ){
      double dum_d;
      return classifyString( Line, dum_d  );
    }

    const TargetValue *Classify( const std::string& Line,
				 const ValueDistribution *& db ){
      double dum_d;
      const TargetValue *res = classifyString( Line, dum_d );
      if ( res ){
	normalizeResult();
	db = bestResult.getResultDist();
      }
      return res;
    }
    const TargetValue *Classify( const std::string& Line,
				 double& di ){
      return classifyString( Line, di );
    }

    const neighborSet *NB_Classify( const std::string& );

    virtual void initExperiment( bool = false );

  protected:
    TimblExperiment( const AlgorithmType, const std::string& = "" );
    virtual bool checkLine( const std::string& );
    virtual bool ClassicLearn( const std::string& = "", bool = true );
    virtual const TargetValue *LocalClassify( const Instance& ,
					      double&,
					      bool& );
    virtual bool GetInstanceBase( std::istream& ) = 0;
    virtual void showTestingInfo( std::ostream& );
    virtual bool checkTestFile();
    bool learnFromFileIndex( const fileIndex&, std::istream& );
    bool initTestFiles( const std::string&, const std::string& );
    void show_results( std::ostream&,
		       const double,
		       const std::string&,
		       const TargetValue *,
		       const double ) ;
    void testInstance( const Instance&,
		       InstanceBase_base *,
		       size_t = 0 );
    void normalizeResult();
    const neighborSet *LocalClassify( const Instance&  );
    bool nextLine( std::istream &, std::string&, int& );
    bool nextLine( std::istream &, std::string& );
    bool skipARFFHeader( std::istream & );

    void show_progress( std::ostream& os, time_t, unsigned int );
    bool createPercFile( const std::string& = "" ) const;

    void show_speed_summary( std::ostream& os,
			     const timeval& ) const;

    void show_ignore_info( std::ostream& os ) const;
    void show_weight_info( std::ostream& os ) const;
    void show_metric_info( std::ostream& os ) const;
    double sum_remaining_weights( size_t ) const;

    bool build_file_index( const std::string&, fileIndex&  );
    bool build_file_multi_index( const std::string&, fileDoubleIndex&  );

    bool Initialized;
    GetOptClass *OptParams;
    AlgorithmType algorithm;
    std::string CurrentDataFile;
    std::string WFileName;
    std::string outPath;
    std::string testStreamName;
    std::string outStreamName;
    std::ifstream testStream;
    std::ofstream outStream;
    unsigned long ibCount;
    ConfusionMatrix *confusionInfo;
    std::vector<Instance> instances;
    StatisticsClass stats;
    resultStore bestResult;
    size_t match_depth;
    bool last_leaf;

  private:
    TimblExperiment( const TimblExperiment& );
    int estimate;
    int numOfThreads;
    const TargetValue *classifyString( const std::string& , double& );
  };

  class IB1_Experiment: public TimblExperiment {
  public:
    IB1_Experiment( const size_t N = DEFAULT_MAX_FEATS,
		    const std::string& s= "",
		    const bool init = true );
    bool Increment( const std::string& );
    bool Decrement( const std::string& );
    //    bool Expand( const std::string& );
    bool Remove( const std::string& );
    AlgorithmType Algorithm() const { return IB1_a; };
    void InitInstanceBase();
    bool NS_Test( const std::string&,
		  const std::string& );
  protected:
    TimblExperiment *clone() const {
      return new IB1_Experiment( MaxFeats(), "", false );
    };
    bool checkTestFile();
    bool checkLine( const std::string& );
    bool Increment( const Instance& I ) { return UnHideInstance( I ); };
    bool Decrement( const Instance& I ) { return HideInstance( I ); };
  private:
    bool GetInstanceBase( std::istream& );
  };

  class IB2_Experiment: public IB1_Experiment {
  public:
  IB2_Experiment( size_t N, const std::string& s="" ):
    IB1_Experiment( N, s ) {
      IB2_offset( 0 );
    };
    bool Prepare( const std::string& = "", bool = false, bool = false );
    bool Expand( const std::string& );
    bool Remove( const std::string& );
    bool Learn( const std::string& = "", bool = false );
    AlgorithmType Algorithm() const { return IB2_a; };
  protected:
    bool checkTestFile( );
    TimblExperiment *clone() const { return new IB2_Experiment( MaxFeats() ); };
    bool Expand_N( const std::string& );
    bool show_learn_progress( std::ostream& os, time_t, size_t );
  };

  class LOO_Experiment: public IB1_Experiment {
  public:
  LOO_Experiment( int N, const std::string& s = "" ):
    IB1_Experiment( N, s ) {
    };
    bool Test( const std::string&,
	       const std::string& );
    AlgorithmType Algorithm() const { return LOO_a; };
    bool ReadInstanceBase( const std::string& );
    void initExperiment( bool = false );
  protected:
    bool checkTestFile( );
    void showTestingInfo( std::ostream& );
  };

  class CV_Experiment: public IB1_Experiment {
  public:
  CV_Experiment( int N = DEFAULT_MAX_FEATS, const std::string& s = "" ):
    IB1_Experiment( N, s ), NumOfFiles( 0 ), FileNames( NULL )
      { };
    ~CV_Experiment(){ delete [] FileNames; };
    bool Learn( const std::string& = "", bool = true );
    bool Prepare( const std::string& = "", bool = true, bool = false );
    bool Test( const std::string&,
	       const std::string& );
    bool CVprepare( const std::string& = "",
		    WeightType = GR_w,
		    const std::string& = "" );
    AlgorithmType Algorithm() const { return CV_a; };
  protected:
    bool checkTestFile();
    bool get_file_names( const std::string& );
  private:
    CV_Experiment( const CV_Experiment& );
    CV_Experiment& operator=( const CV_Experiment& );
    int NumOfFiles;
    std::string *FileNames;
    std::string CV_WfileName;
    std::string CV_PfileName;
    WeightType CV_fileW;
  };

  class TRIBL_Experiment: public TimblExperiment {
  public:
  TRIBL_Experiment( const size_t N = DEFAULT_MAX_FEATS,
		    const std::string& s = "",
		    const bool init = true ):
    TimblExperiment( TRIBL_a, s ) {
      if ( init ) InitClass( N );
    };
    void InitInstanceBase();
  protected:
    TimblExperiment *clone() const {
      return new TRIBL_Experiment( MaxFeats(), "", false ); };
    void showTestingInfo( std::ostream& );
    bool checkTestFile();
    AlgorithmType Algorithm() const { return TRIBL_a; };
    bool checkLine( const std::string& );
    const TargetValue *LocalClassify( const Instance& ,
				      double&,
				      bool& );
  private:
    bool GetInstanceBase( std::istream& );
  };

  class TRIBL2_Experiment: public TimblExperiment {
  public:
  TRIBL2_Experiment( const size_t N = DEFAULT_MAX_FEATS,
		     const std::string& s = "",
		     const bool init = true ):
    TimblExperiment( TRIBL2_a, s ) {
      if ( init ) InitClass( N );
    };
    void InitInstanceBase();
  protected:
    TimblExperiment *clone() const {
      return new TRIBL2_Experiment( MaxFeats(), "", false ); };
    bool checkTestFile();
    AlgorithmType Algorithm() const { return TRIBL2_a; };
    bool checkLine( const std::string& );
    const TargetValue *LocalClassify( const Instance& ,
				      double&,
				      bool& );
  private:
    bool GetInstanceBase( std::istream& );
  };

  class IG_Experiment: public TimblExperiment {
  public:
  IG_Experiment( const size_t N = DEFAULT_MAX_FEATS,
		 const std::string& s = "",
		 const bool init = true ):
    TimblExperiment( IGTREE_a, s ) {
      if ( init ) InitClass( N );
    };
    AlgorithmType Algorithm() const { return IGTREE_a; };
    void InitInstanceBase();
    bool WriteInstanceBase( const std::string& );
    bool ReadInstanceBase( const std::string& );
    void initExperiment( bool = false );
    bool Expand( const std::string& ){
      FatalError( "Expand not supported for IGTree" );
      return false;
    };

  protected:
    TimblExperiment *clone() const {
      return new IG_Experiment( MaxFeats(), "", false ); };
    bool ClassicLearn( const std::string& = "", bool = true );
    bool checkTestFile();
    void showTestingInfo( std::ostream& );
    bool checkLine( const std::string& );
    bool sanityCheck() const;
    const TargetValue *LocalClassify( const Instance&,
				      double&,
				      bool& );
  private:

    bool GetInstanceBase( std::istream& );
  };

}

#endif // TIMBL_EXPERIMENT_H