Index: applications/robust/robustlib.h
===================================================================
--- applications/robust/robustlib.h (revision 1172)
+++ applications/robust/robustlib.h (revision 1186)
@@ -86,13 +86,17 @@
 };
 
-/// A
+/// A class for representing 0-dimensional polyhedron - a vertex. It will be located in the bottom row of the Hasse
+/// diagram representing a complex of polyhedrons. It has its coordinates in the parameter space.
 class vertex : public polyhedron
 {
+	/// A dynamic array representing coordinates of the vertex
 	vector<double> coordinates;
 
 public:
 
+	/// Default constructor
 	vertex();
 
+	/// Constructor of a vertex from a set of coordinates
 	vertex(vector<double> coordinates)
 	{
@@ -100,4 +104,6 @@
 	}
 
+	/// A method that widens the set of coordinates of given vertex. It is used when a complex in a parameter
+	/// space of certain dimension is established, but the dimension is not known when the vertex is created.
 	void push_coordinate(double coordinate)
 	{
@@ -105,9 +111,14 @@
 	}
 
+	/// A method obtaining the set of coordinates of a vertex. These coordinates are not obtained as a pointer 
+	/// (not given by reference), but a new copy is created (they are given by value).
 	vector<double> get_coordinates()
 	{
 		vector<double> returned_vec;
 
-		copy(this->coordinates.begin(),this->coordinates.end(),returned_vec.begin());
+		for(int i = 0;i<coordinates.size();i++)
+		{
+			returned_vec.push_back(coordinates[i]);
+		}
 
 		return returned_vec;
@@ -115,12 +126,17 @@
 };
 
+/// A class representing a polyhedron in a top row of the complex. Such polyhedron has a condition that differitiates
+/// it from polyhedrons in other rows. 
 class toprow : public polyhedron
 {
+	/// A condition used for determining the function of a Laplace-Inverse-Gamma density resulting from Bayesian estimation
 	vector<double> condition;
 
 public:
 
+	/// Default constructor
 	toprow();
 
+	/// Constructor creating a toprow from the condition
 	toprow(vector<double> condition)
 	{
@@ -134,11 +150,15 @@
 
 //! Conditional(e) Multicriteria-Laplace-Inverse-Gamma distribution density
-class emlig : public eEF
+class emlig // : eEF
 {
 
+	/// A statistic in a form of a Hasse diagram representing a complex of convex polyhedrons obtained as a result
+	/// of data update from Bayesian estimation or set by the user if this emlig is a prior density
 	vector<vector<polyhedron*>> statistic;
 	
 public:	
 
+	/// A default constructor creates an emlig with predefined statistic representing only the range of the given
+	/// parametric space, where the number of parameters of the needed model is given as a parameter to the constructor.
 	emlig(int number_of_parameters)
 	{
@@ -146,4 +166,6 @@
 	}
 
+	/// A constructor for creating an emlig when the user wants to create the statistic by himself. The creation of a
+	/// statistic is needed outside the constructor. Used for a user defined prior distribution on the parameters.
 	emlig(vector<vector<polyhedron*>> statistic)
 	{
@@ -151,47 +173,89 @@
 	}
 
-
-
 protected:
 
+	/// A method for creating plain default statistic representing only the range of the parameter space.
     void create_statistic(int number_of_parameters)
 	{
+		// An empty vector of coordinates.
 		vector<double> origin_coord;	
 
+		// We create an origin - this point will have all the coordinates zero, but now it has an empty vector of coords.
 		vertex *origin = new vertex(origin_coord);
 
+		// It has itself as a vertex. There will be a nice use for this when the vertices of its parents are searched in
+		// the recursive creation procedure below.
 		origin->vertices.push_back(origin);
 
+		// As a statistic, we have to create a vector of vectors of polyhedron pointers. It will then represent the Hasse
+		// diagram. First we create a vector of polyhedrons..
 		vector<polyhedron*> origin_vec;
 
+		// ..we fill it with the origin..
 		origin_vec.push_back(origin);
 
+		// ..and we fill the statistic with the created vector.
 		statistic.push_back(origin_vec);
 
+		// Now we have a statistic for a zero dimensional space. Regarding to how many dimensional space we need to 
+		// describe, we have to widen the descriptional default statistic. We use an iterative procedure as follows:
 		for(int i=0;i<number_of_parameters;i++)
 		{
+			// We first will create two new vertices. These will be the borders of the parameter space in the dimension
+			// of newly added parameter. Therefore they will have all coordinates except the last one zero. We get the 
+			// right amount of zero cooridnates by reading them from the origin
 			vector<double> origin_coord1 = origin->get_coordinates();
-			vector<double> origin_coord2 = origin->get_coordinates();
-
-			origin->push_coordinate(0);
-
+			vector<double> origin_coord2 = origin->get_coordinates();			
+
+			// And we incorporate the nonzero coordinates into the new cooordinate vectors
 			origin_coord1.push_back(max_range);
 			origin_coord2.push_back(-max_range);
 
+			// Now we create the points
 			vertex *new_point1 = new vertex(origin_coord1);
-			vertex *new_point2 = new vertex(origin_coord2);	
-
+			vertex *new_point2 = new vertex(origin_coord2);
+			
+			//*********************************************************************************************************
+			// The algorithm for recursive build of a new Hasse diagram representing the space structure from the old
+			// diagram works so that you create two copies of the old Hasse diagram, you shift them up one level (points
+			// will be segments, segments will be areas etc.) and you connect each one of the original copied polyhedrons
+			// with its offspring by a parent-child relation. Also each of the segments in the first (second) copy is
+			// connected to the first (second) newly created vertex by a parent-child relation.
+			//*********************************************************************************************************
+
+
+			// Create the vectors of vectors of pointers to polyhedrons to hold the copies of the old Hasse diagram
 			vector<vector<polyhedron*>> new_statistic1;
 			vector<vector<polyhedron*>> new_statistic2;
 
-			
+			// Copy the statistic by rows
 			for(int j=0;j<statistic.size();j++)
 			{
+				// an element counter
 				int element_number = 0;
 
+				vector<polyhedron*> supportnew_1;
+				vector<polyhedron*> supportnew_2;
+
+				new_statistic1.push_back(supportnew_1);
+				new_statistic2.push_back(supportnew_2);
+
+				// for each polyhedron in the given row
 				for(vector<polyhedron*>::iterator horiz_ref = statistic[j].begin();horiz_ref<statistic[j].end();horiz_ref++)
 				{	
+					// Append an extra zero coordinate to each of the vertices for the new dimension
+					// If j==0 => we loop through vertices
+					if(j == 0)
+					{
+						// cast the polyhedron pointer to a vertex pointer and push a zero to its vector of coordinates
+						((vertex*) (*horiz_ref))->push_coordinate(0);
+					}
+
+					// if it has parents
 					if(!(*horiz_ref)->parents.empty())
 					{
+						// save the relative address of this child in a vector kids_rel_addresses of all its parents.
+						// This information will later be used for copying the whole Hasse diagram with each of the
+						// relations contained within.
 						for(vector<polyhedron*>::iterator parent_ref = (*horiz_ref)->parents.begin();parent_ref < (*horiz_ref)->parents.end();parent_ref++)
 						{
@@ -200,10 +264,23 @@
 					}
 
+					// **************************************************************************************************
+					// Here we begin creating a new polyhedron, which will be a copy of the old one. Each such polyhedron
+					// will be created as a toprow, but this information will be later forgotten and only the polyhedrons
+					// in the top row of the Hasse diagram will be considered toprow for later use.
+					// **************************************************************************************************
+
+					// First we create vectors specifying a toprow condition. In the case of a preconstructed statistic
+					// this condition will be a vector of zeros. There are two vectors, because we need two copies of 
+					// the original Hasse diagram.
 					vector<double> vec1(i+2,0);
 					vector<double> vec2(i+2,0);
 
+					// We create a new toprow with the previously specified condition.
 					toprow *current_copy1 = new toprow(vec1);
 					toprow *current_copy2 = new toprow(vec2);					
 
+					// The vertices of the copies will be inherited, because there will be a parent/child relation
+					// between each polyhedron and its offspring (comming from the copy) and a parent has all the
+					// vertices of its child plus more.
 					for(vector<vertex*>::iterator vert_ref = (*horiz_ref)->vertices.begin();vert_ref<(*horiz_ref)->vertices.end();vert_ref++)
 					{
@@ -212,45 +289,84 @@
 					}
 					
-
+					// The only new vertex of the offspring should be the newly created point.
 					current_copy1->vertices.push_back(new_point1);
 					current_copy2->vertices.push_back(new_point2);
-
+					
+					// This method guarantees that each polyhedron is already triangulated, therefore its triangulation
+					// is only one set of vertices and it is the set of all its vertices.
 					current_copy1->triangulations.push_back(current_copy1->vertices);
 					current_copy2->triangulations.push_back(current_copy2->vertices);
-
-					
-
+					
+					// Now we have copied the polyhedron and we have to copy all of its relations. Because we are copying
+					// in the Hasse diagram from bottom up, we always have to copy the parent/child relations to all the
+					// kids and when we do that and know the child, in the child we will remember the parent we came from.
+					// This way all the parents/children relations are saved in both the parent and the child.
 					if(!(*horiz_ref)->kids_rel_addresses.empty())
 					{
 						for(vector<int>::iterator kid_ref = (*horiz_ref)->kids_rel_addresses.begin();kid_ref<(*horiz_ref)->kids_rel_addresses.end();kid_ref++)
-						{						
-							current_copy1->children.push_back(new_statistic1[i][(*kid_ref)]);
-							current_copy2->children.push_back(new_statistic2[i][(*kid_ref)]);
-
-							new_statistic1[i][(*kid_ref)]->parents.push_back(current_copy1);
-							new_statistic2[i][(*kid_ref)]->parents.push_back(current_copy2);
+						{	
+							// find the child and save the relation to the parent
+							current_copy1->children.push_back(new_statistic1[j-1][(*kid_ref)]);
+							current_copy2->children.push_back(new_statistic2[j-1][(*kid_ref)]);
+
+							// in the child save the parents' address
+							new_statistic1[j-1][(*kid_ref)]->parents.push_back(current_copy1);
+							new_statistic2[j-1][(*kid_ref)]->parents.push_back(current_copy2);
 						}						
 
+						// Here we clear the parents kids_rel_addresses vector for later use (when we need to widen the
+						// Hasse diagram again)
 						(*horiz_ref)->kids_rel_addresses.clear();
 					}
+					// If there were no children previously, we are copying a polyhedron that has been a vertex before.
+					// In this case it is a segment now and it will have a relation to its mother (copywise) and to the
+					// newly created point. Here we create the connection to the new point, again from both sides.
 					else
 					{
+						// Add the address of the new point in the former vertex
 						current_copy1->children.push_back(new_point1);
 						current_copy2->children.push_back(new_point2);
 
+						// Add the address of the former vertex in the new point
 						new_point1->parents.push_back(current_copy1);
 						new_point2->parents.push_back(current_copy2);
 					}
 
+					// Save the mother in its offspring
 					current_copy1->children.push_back(*horiz_ref);
 					current_copy2->children.push_back(*horiz_ref);
 
-					new_statistic1[i+1].push_back(current_copy1);
-					new_statistic2[i+1].push_back(current_copy2);
-					
+					// Save the offspring in its mother
+					(*horiz_ref)->parents.push_back(current_copy1);
+					(*horiz_ref)->parents.push_back(current_copy2);	
+								
+					
+					// Add the copies into the relevant statistic. The statistic will later be appended to the previous
+					// Hasse diagram
+					new_statistic1[j].push_back(current_copy1);
+					new_statistic2[j].push_back(current_copy2);
+					
+					// Raise the count in the vector of polyhedrons
 					element_number++;
+					
 				}				
-			}				
-			
+			}
+
+			statistic[0].push_back(new_point1);
+			statistic[0].push_back(new_point2);
+
+			// Merge the new statistics into the old one. This will either be the final statistic or we will
+			// reenter the widening loop. 
+			for(int j=0;j<new_statistic1.size();j++)
+			{
+				if(j+1==statistic.size())
+				{
+					vector<polyhedron*> support;
+					statistic.push_back(support);
+				}
+				
+				statistic[j+1].insert(statistic[j+1].end(),new_statistic1[j].begin(),new_statistic1[j].end());
+				statistic[j+1].insert(statistic[j+1].end(),new_statistic2[j].begin(),new_statistic2[j].end());
+			}
 		}
 	}
