/***************************************************************************
 *   Copyright (C) 2005 by Robot Group Leipzig                             *
 *    martius@informatik.uni-leipzig.de                                    *
 *    fhesse@informatik.uni-leipzig.de                                     *
 *    der@informatik.uni-leipzig.de                                        *
 *                                                                         *
 *   This program 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 2 of 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 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, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 *                                                                         *
 *   $Log: inspectable.h,v $
 *   Revision 1.5  2005/10/27 15:46:38  martius
 *   inspectable interface is expanded to structural information for network visualiser
 *
 *   Revision 1.4  2005/10/06 17:06:57  martius
 *   switched to stl lists
 *
 *   Revision 1.3  2005/09/11 11:20:01  martius
 *   virtual destructor
 *
 *   Revision 1.2  2005/08/06 20:47:54  martius
 *   Commented
 *
 *   Revision 1.1  2005/08/03 20:28:57  martius
 *   inspectable interface
 *
 *                                                                 *
 ***************************************************************************/
#ifndef __INSPECTABLE_H
#define __INSPECTABLE_H

#include <list>
#include <utility>
#include <string>
using namespace std;
#include "stl_adds.h"

/**
 * Interface for inspectable objects.
 * That means that one can read out some internal parameters indentified by string keys
*/
class Inspectable {
public:

  typedef string iparamkey;
  typedef double iparamval;  

  typedef struct ILayer{
    ILayer(const string& vectorname, const string& biasname, int dimension, int rank, const string& layername)
      : vectorname(vectorname), biasname(biasname), dimension(dimension), rank(rank), layername(layername) {}
    string vectorname;  //< prefix of the internal parameter vector e.g. "v"
    string biasname;    //< prefix of the internal parameter vector used as bias for the neurons e.g. "h"
    int dimension;      //< length of the vector (number of units)
    int rank;           //< rank of the layer (0 are input layers)
    string layername;   //< name of the layer as displayed by the visualiser
  }ILayer;
  
  typedef struct IConnection{
    IConnection(const string& matrixname, const string& vector1, const string& vector2)
      : matrixname(matrixname), vector1(vector1), vector2(vector2) {}
    string matrixname; //< matrix name is the prefix of the internal parameter matrix e.g. "A"
    string vector1;    //< vectorname of input layer
    string vector2;    //< vectorname of output layer
  }IConnection;

  /// nice predicate function for finding a Layer with its vectorname
  struct matchName : public unary_function<ILayer, bool> {
    matchName(string name) : name(name) {}
    string name;
    bool operator()(ILayer l) { return l.vectorname == name; }
  };

  virtual ~Inspectable(){}
  /** The list of the names of all internal parameters given by getInternalParams().
      The naming convention is "v[i]" for vectors 
       and "A[i][j]" for matrices, where i, j start at 0.
      @return: list of keys
   */
  virtual list<iparamkey> getInternalParamNames() const = 0;
  /** @return: list of values 
   */
  virtual list<iparamval> getInternalParams() const = 0;

  /** Specifies which parameter vector forms a structural layer (in terms of a neural network)
      The ordering is important. The first entry is the input layer and so on. 
      @return: list of layer names with dimension 
      
   */
  virtual list<ILayer> getStructuralLayers() const { return list<ILayer>();}
  /** Specifies which parameter matrix forms a connection between layers (in terms of a neural network)
      The orderning is not important.
      @return: list of layer names with dimension       
   */
  virtual list<IConnection> getStructuralConnections() const { return list<IConnection>();}

};

#endif
