<commit_before>/*
 * 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 3 of the License, or
 * (at your option) any later version.
 *
 * Written (W) 2011 <NAME>
 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
 */

#include <shogun/modelselection/ParameterCombination.h>
#include <shogun/base/Parameter.h>
#include <shogun/machine/Machine.h>

using namespace shogun;

CParameterCombination::CParameterCombination()
{
	init();
}

CParameterCombination::CParameterCombination(Parameter* param)
{
	init();

	m_param=param;
}

void CParameterCombination::init()
{
	m_param=NULL;
	m_child_nodes=new CDynamicObjectArray<CParameterCombination> ();
	SG_REF(m_child_nodes);

	m_parameters->add((CSGObject**)m_child_nodes, "child nodes",
			"children of this node");
}

CParameterCombination::~CParameterCombination()
{
	delete m_param;
	SG_UNREF(m_child_nodes);
}

void CParameterCombination::append_child(CParameterCombination* child)
{
	m_child_nodes->append_element(child);
}

void CParameterCombination::print_tree(int prefix_num) const
{
	/* prefix is enlarged */
	char* prefix=SG_MALLOC(char, prefix_num+1);
	for (index_t i=0; i<prefix_num; ++i)
		prefix[i]='\t';

	prefix[prefix_num]='\0';

	/* cases:
	 * -node with a Parameter instance and a possible children
	 * -root node with children
	 */

	if (m_param)
	{
		SG_SPRINT("%s", prefix);
		for (index_t i=0; i<m_param->get_num_parameters(); ++i)
		{
			/* distinction between sgobject and values */
			if (m_param->get_parameter(i)->m_datatype.m_ptype==PT_SGOBJECT)
			{
				TParameter* param=m_param->get_parameter(i);
				CSGObject* current_sgobject=*((CSGObject**) param->m_parameter);
				SG_SPRINT("\"%s\":%s at %p ", param->m_name,
						current_sgobject->get_name(), current_sgobject);
			}
			else
			{
				SG_SPRINT("\"%s\"=%f ", m_param->get_parameter(i)->m_name,
						*((float64_t*)m_param->get_parameter(i)->m_parameter));
			}
		}

	}
	else<commit_msg>print method now handles different data types<commit_after>/*
 * 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 3 of the License, or
 * (at your option) any later version.
 *
 * Written (W) 2011 <NAME>
 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
 */

#include <shogun/modelselection/ParameterCombination.h>
#include <shogun/base/Parameter.h>
#include <shogun/machine/Machine.h>

using namespace shogun;

CParameterCombination::CParameterCombination()
{
	init();
}

CParameterCombination::CParameterCombination(Parameter* param)
{
	init();

	m_param=param;
}

void CParameterCombination::init()
{
	m_param=NULL;
	m_child_nodes=new CDynamicObjectArray<CParameterCombination> ();
	SG_REF(m_child_nodes);

	m_parameters->add((CSGObject**)m_child_nodes, "child nodes",
			"children of this node");
}

CParameterCombination::~CParameterCombination()
{
	delete m_param;
	SG_UNREF(m_child_nodes);
}

void CParameterCombination::append_child(CParameterCombination* child)
{
	m_child_nodes->append_element(child);
}

void CParameterCombination::print_tree(int prefix_num) const
{
	/* prefix is enlarged */
	char* prefix=SG_MALLOC(char, prefix_num+1);
	for (index_t i=0; i<prefix_num; ++i)
		prefix[i]='\t';

	prefix[prefix_num]='\0';

	/* cases:
	 * -node with a Parameter instance and a possible children
	 * -root node with children
	 */

	if (m_param)
	{
		SG_SPRINT("%s", prefix);
		for (index_t i=0; i<m_param->get_num_parameters(); ++i)
		{
			/* distinction between sgobject and values */
			if (m_param->get_parameter(i)->m_datatype.m_ptype==PT_SGOBJECT)
			{
				TParameter* param=m_param->get_parameter(i);
				CSGObject* current_sgobject=*((CSGObject**) param->m_parameter);
				SG_SPRINT("\"%s\":%s at %p ", param->m_name,
						current_sgobject->get_name(), current_sgobject);
			}
			else
			{
				SG_SPRINT("\"%s\"=", m_param->get_parameter(i)->m_name);
				void* param=m_param->get_parameter(i)->m_parameter;

				if (m_param->get_parameter(i)->m_datatype.m_ptype==PT_FLOAT64)
					SG_SPRINT("%f ", *((float64_t*)param));
				else if (m_param->get_parameter(i)->m_datatype.m_ptype==PT_INT32)
					SG_SPRINT("%i ", *((int32_t*)param));
				else if (m_param->get_parameter(i)->m_datatype.m_ptype==PT_BOOL)
					SG_SPRINT("%s ", *((bool*)param ? "true" : "false"));
				else
					SG_NOTIMPLEMENTED;
			}

		}

	}
	else
{'fraction_non_alphanumeric': 0.1419833988641328, 'fraction_numerical': 0.007863695937090432, 'mean_word_length': 5.017082785808147, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5557555', 'n_tokens_mistral': 1777, 'n_tokens_neox': 1602, 'n_words': 332}