void DiagramItem::save (QDomDocument *document, QDomElement *parent)
{
    // save ID
    createChildNode( document, parent, QString ("ID"), m_ID);
    
    // save type
    createChildNode( document, parent, QString ("Type"), getType());
    
    // save text
    createChildNode( document, parent, QString ("Text"), m_strText);
    
    // save pen
    QDomElement pen = document->createElement ("Pen");
    parent->appendChild(pen);
    createChildNode( document, &pen, QString ("Color"), m_pen.color().name());
    createChildNode( document, &pen, QString ("Style"), (int) m_pen.style());
    createChildNode( document, &pen, QString ("Width"), m_pen.width());
    
        // save brush
    QDomElement brush = document->createElement ("Brush");
    parent->appendChild(brush);
    createChildNode( document, &brush, QString ("Color"), m_brush.color().name());
    createChildNode( document, &brush, QString ("Style"), (int) m_brush.style());
}
示例#2
0
  /*
   This function updates the forest by splitting the nodes specified
   @param R_observations - observations of feature vectors
   @param R_responses - observations of response variable
   @param R_forest - forest 
   @param R_active_nodes - active nodes to update
   @param R_splits_info - best splits for all nodes 
   @param R_max_depth - the depth for which to stop growing trees 
   @return - count of observations in all leaf nodes
   */
  SEXP updateNodes(SEXP R_observations, SEXP R_responses, SEXP R_forest, SEXP R_active_nodes, SEXP R_splits_info, SEXP R_max_depth)
  {
    hpdRFforest *forest = (hpdRFforest *) R_ExternalPtrAddr(R_forest);

    int* features_categorical = forest-> features_cardinality;
    int* bin_num = forest->bin_num;
    int features_num = forest->features_num;
    int leaf_nodes = forest->nleaves -
      length(R_active_nodes) + 
      2*INTEGER(getAttrib(R_splits_info,install("total_completed")))[0];

    hpdRFnode **new_leaves = (hpdRFnode**)malloc(sizeof(hpdRFnode*)*leaf_nodes);

    SEXP R_node_counts;
    PROTECT(R_node_counts = allocVector(INTSXP,leaf_nodes));
    int *node_counts = INTEGER(R_node_counts);

    int max_depth = INTEGER(R_max_depth)[0];
    leaf_nodes = 0;
    int index = 0;
    for(int i  = 0; i < forest->nleaves;i++)
      {
	hpdRFnode* node_curr = forest->leaf_nodes[i];
	int next_active_node = index < length(R_active_nodes) ? 
	  INTEGER(R_active_nodes)[index]-1: -1;
	if(i == next_active_node) 
	  {
	    if(INTEGER(VECTOR_ELT(VECTOR_ELT(R_splits_info,index),0))[0]==1)
	      {
		int active_node = INTEGER(R_active_nodes)[index]-1;
		node_curr = forest->leaf_nodes[active_node];
		int* left_child_node_observations;
		int* right_child_node_observations;
		double* left_child_weights, *right_child_weights;
		int left_child_num_obs, right_child_num_obs;
		int* node_observations = node_curr->additional_info->indices;
		double* node_weights = node_curr->additional_info->weights;
		int node_observations_num = node_curr->additional_info->num_obs;
		int node_split_variable = INTEGER(VECTOR_ELT(VECTOR_ELT(R_splits_info,index),1))[0]-1;
		SEXP node_split_criteria = VECTOR_ELT(VECTOR_ELT(R_splits_info,index),2);
		updateNode(VECTOR_ELT(R_observations,node_split_variable),
			   node_split_criteria, node_observations, node_observations_num,
			   &left_child_node_observations,
			   &right_child_node_observations,
			   features_categorical[node_split_variable] != NA_INTEGER,
			   bin_num[node_split_variable],
			   node_weights,  &left_child_weights, &right_child_weights,
			   &left_child_num_obs, &right_child_num_obs);

		hpdRFnode *node_left_child = createChildNode(node_curr, FALSE,
						  left_child_node_observations, 
							     left_child_weights,
						  left_child_num_obs,features_num);
		hpdRFnode *node_right_child = createChildNode(node_curr, FALSE,
						   right_child_node_observations, 
							      right_child_weights,
						   right_child_num_obs,features_num);
		node_curr->left = node_left_child;
		node_curr->right = node_right_child;
		
		if(node_left_child->additional_info->depth <= max_depth)
		  {
		    node_left_child->additional_info->leafID = leaf_nodes+1;
		    node_counts[leaf_nodes] = 
		      node_left_child->additional_info->num_obs;
		    new_leaves[leaf_nodes++] = node_left_child;
		  }

		if(node_right_child->additional_info->depth <= max_depth)
		  {
		    node_right_child->additional_info->leafID = leaf_nodes+1;
		    node_counts[leaf_nodes] = 
		      node_right_child->additional_info->num_obs;
		    new_leaves[leaf_nodes++] = node_right_child;
		  }
	      }

	    cleanSingleNode(node_curr);
	    index ++;

	  }
	else if(i != next_active_node && 
		node_curr->additional_info->depth <= max_depth)
	  {
	    node_curr->additional_info->leafID = leaf_nodes+1;
	    node_counts[leaf_nodes] = node_curr->additional_info->num_obs;
	    new_leaves[leaf_nodes++]  = node_curr;
	  }
      }

    free(forest->leaf_nodes);
    forest->nleaves = leaf_nodes;
    forest->leaf_nodes = new_leaves;
    SETLENGTH(R_node_counts,leaf_nodes);
    UNPROTECT(1);
    return R_node_counts;
  }