Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/karlnapf/shogun
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeren Sonnenburg committed Jul 27, 2011
2 parents 7821411 + 637aa52 commit 440c5ef
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 78 deletions.
Expand Up @@ -29,7 +29,7 @@ CModelSelectionParameters* create_param_tree()

CModelSelectionParameters* c=new CModelSelectionParameters("C1");
root->append_child(c);
c->build_values(1, 2, R_EXP);
c->build_values(1.0, 2.0, R_EXP);

CGaussianKernel* gaussian_kernel=new CGaussianKernel();
CModelSelectionParameters* param_gaussian_kernel=
Expand All @@ -39,7 +39,7 @@ CModelSelectionParameters* create_param_tree()

CModelSelectionParameters* param_gaussian_kernel_width=
new CModelSelectionParameters("width");
param_gaussian_kernel_width->build_values(1, 2, R_EXP);
param_gaussian_kernel_width->build_values(1.0, 2.0, R_EXP);
param_gaussian_kernel->append_child(param_gaussian_kernel_width);

return root;
Expand Down
Expand Up @@ -36,18 +36,18 @@ CModelSelectionParameters* create_param_tree()

CModelSelectionParameters* c1=new CModelSelectionParameters("C1");
root->append_child(c1);
c1->build_values(-5, 5, R_EXP);
c1->build_values(-5.0, 5.0, R_EXP);

CModelSelectionParameters* c2=new CModelSelectionParameters("C2");
root->append_child(c2);
c2->build_values(-5, 5, R_EXP);
c2->build_values(-5.0, 5.0, R_EXP);

CGaussianKernel* gaussian_kernel=new CGaussianKernel();
CModelSelectionParameters* param_gaussian_kernel=
new CModelSelectionParameters("kernel", gaussian_kernel);
CModelSelectionParameters* gaussian_kernel_width=
new CModelSelectionParameters("width");
gaussian_kernel_width->build_values(-5, 5, R_EXP, 1, 2);
gaussian_kernel_width->build_values(-5.0, 5.0, R_EXP, 1.0, 2.0);
param_gaussian_kernel->append_child(gaussian_kernel_width);
root->append_child(param_gaussian_kernel);

Expand All @@ -59,7 +59,7 @@ CModelSelectionParameters* create_param_tree()

CModelSelectionParameters* param_power_kernel_degree=
new CModelSelectionParameters("degree");
param_power_kernel_degree->build_values(1, 1, R_EXP);
param_power_kernel_degree->build_values(1.0, 1.0, R_EXP);
param_power_kernel->append_child(param_power_kernel_degree);

CMinkowskiMetric* m_metric=new CMinkowskiMetric(10);
Expand All @@ -70,7 +70,7 @@ CModelSelectionParameters* create_param_tree()

CModelSelectionParameters* param_power_kernel_metric1_k=
new CModelSelectionParameters("k");
param_power_kernel_metric1_k->build_values(1, 12, R_LINEAR);
param_power_kernel_metric1_k->build_values(1.0, 12.0, R_LINEAR);
param_power_kernel_metric1->append_child(param_power_kernel_metric1_k);

return root;
Expand Down
Expand Up @@ -32,11 +32,11 @@ CModelSelectionParameters* create_param_tree()

CModelSelectionParameters* c1=new CModelSelectionParameters("C1");
root->append_child(c1);
c1->build_values(-15, 15, R_EXP);
c1->build_values(-15.0, 15.0, R_EXP);

CModelSelectionParameters* c2=new CModelSelectionParameters("C2");
root->append_child(c2);
c2->build_values(-15, 15, R_EXP);
c2->build_values(-15.0, 15.0, R_EXP);

return root;
}
Expand Down
Expand Up @@ -29,7 +29,7 @@ CModelSelectionParameters* build_complex_example_tree()

CModelSelectionParameters* c=new CModelSelectionParameters("C");
root->append_child(c);
c->build_values(1, 1, R_EXP);
c->build_values(1.0, 1.0, R_EXP);

CPowerKernel* power_kernel=new CPowerKernel();
CModelSelectionParameters* param_power_kernel=
Expand All @@ -39,7 +39,7 @@ CModelSelectionParameters* build_complex_example_tree()

CModelSelectionParameters* param_power_kernel_degree=
new CModelSelectionParameters("degree");
param_power_kernel_degree->build_values(1, 1, R_EXP);
param_power_kernel_degree->build_values(1.0, 1.0, R_EXP);
param_power_kernel->append_child(param_power_kernel_degree);

CMinkowskiMetric* m_metric=new CMinkowskiMetric(10);
Expand All @@ -50,7 +50,7 @@ CModelSelectionParameters* build_complex_example_tree()

CModelSelectionParameters* param_power_kernel_metric1_k=
new CModelSelectionParameters("k");
param_power_kernel_metric1_k->build_values(1, 12, R_LINEAR);
param_power_kernel_metric1_k->build_values(1.0, 12.0, R_LINEAR);
param_power_kernel_metric1->append_child(param_power_kernel_metric1_k);

CGaussianKernel* gaussian_kernel=new CGaussianKernel();
Expand All @@ -61,7 +61,7 @@ CModelSelectionParameters* build_complex_example_tree()

CModelSelectionParameters* param_gaussian_kernel_width=
new CModelSelectionParameters("width");
param_gaussian_kernel_width->build_values(1, 2, R_EXP);
param_gaussian_kernel_width->build_values(1.0, 2.0, R_EXP);
param_gaussian_kernel->append_child(param_gaussian_kernel_width);

CDistantSegmentsKernel* ds_kernel=new CDistantSegmentsKernel();
Expand All @@ -72,12 +72,12 @@ CModelSelectionParameters* build_complex_example_tree()

CModelSelectionParameters* param_ds_kernel_delta=
new CModelSelectionParameters("delta");
param_ds_kernel_delta->build_values(1, 2, R_EXP);
param_ds_kernel_delta->build_values(1.0, 2.0, R_EXP);
param_ds_kernel->append_child(param_ds_kernel_delta);

CModelSelectionParameters* param_ds_kernel_theta=
new CModelSelectionParameters("theta");
param_ds_kernel_theta->build_values(1, 2, R_EXP);
param_ds_kernel_theta->build_values(1.0, 2.0, R_EXP);
param_ds_kernel->append_child(param_ds_kernel_theta);

return root;
Expand All @@ -95,7 +95,7 @@ CModelSelectionParameters* build_sgobject_no_childs_tree()
CModelSelectionParameters* build_leaf_node_tree()
{
CModelSelectionParameters* c_1=new CModelSelectionParameters("C1");
c_1->build_values(1, 1, R_EXP);
c_1->build_values(1.0, 1.0, R_EXP);

return c_1;
}
Expand All @@ -111,11 +111,11 @@ CModelSelectionParameters* build_root_value_childs_tree()

CModelSelectionParameters* c_1=new CModelSelectionParameters("C1");
root->append_child(c_1);
c_1->build_values(1, 1, R_EXP);
c_1->build_values(1.0, 1.0, R_EXP);

CModelSelectionParameters* c_2=new CModelSelectionParameters("C2");
root->append_child(c_2);
c_2->build_values(1, 1, R_EXP);
c_2->build_values(1.0, 1.0, R_EXP);

return root;
}
Expand Down Expand Up @@ -143,7 +143,7 @@ CModelSelectionParameters* build_root_sg_object_child_value_child_tree()

CModelSelectionParameters* c=new CModelSelectionParameters("C");
root->append_child(c);
c->build_values(1, 1, R_EXP);
c->build_values(1.0, 1.0, R_EXP);

root->append_child(param_power_kernel);

Expand Down
2 changes: 2 additions & 0 deletions src/shogun/features/SimpleFeatures.h
Expand Up @@ -969,6 +969,8 @@ template<class ST> class CSimpleFeatures: public CDotFeatures
/** Creates a new CFeatures instance containing copies of the elements
* which are specified by the provided indices.
*
* possible with subset
*
* @param indices indices of feature elements to copy
* @return new CFeatures instance with copies of feature data
*/
Expand Down
30 changes: 30 additions & 0 deletions src/shogun/features/StringFeatures.h
Expand Up @@ -2112,6 +2112,36 @@ template <class ST> class CStringFeatures : public CFeatures
}
*/

/** Creates a new CFeatures instance containing copies of the elements
* which are specified by the provided indices.
*
* possible with subset
*
* @param indices indices of feature elements to copy
* @return new CFeatures instance with copies of feature data
*/
virtual CFeatures* copy_subset(SGVector<index_t> indices) const
{
/* string list to create new CStringFeatures from */
SGStringList<ST> copy(indices.vlen, max_string_length);

/* copy all features */
for (index_t i=0; i<indices.vlen; ++i)
{
/* eventually check subset */
index_t real_idx=subset_idx_conversion(indices.vector[i]);
copy.strings[i]=features[real_idx];
}

/* create copy instance */
CStringFeatures* result=new CStringFeatures(copy, alphabet);

/* max string length may have changed */
result->determine_maximum_string_length();

return result;
}

/** @return object name */
inline virtual const char* get_name() const { return "StringFeatures"; }

Expand Down
59 changes: 57 additions & 2 deletions src/shogun/lib/DataType.h
Expand Up @@ -142,23 +142,78 @@ template<class T> class SGNDArray

template<class T> struct SGString
{
public:
/** default constructor */
SGString() : string(NULL), length(0), do_free(false) { }

/** constructor for setting params */
SGString(T* s, index_t l, bool free_string=false)
: string(s), length(l), do_free(free_string) { }

/** constructor for setting params from a SGVector*/
SGString(SGVector<T> v)
: string(v.vector), length(v.vlen), do_free(v.do_free) { }

/** constructor to create new matrix in memory */
SGString(index_t len, bool free_string=false) :
length(len), do_free(free_string)
{
string=new T[len];
}

/** copy constructor */
SGString(const SGString &orig)
: string(orig.string), length(orig.length), do_free(orig.do_free) { }

public:
/** string */
T* string;
/** length of string */
index_t length;
/** whether string needs to be freed */
bool do_free;
};

/** template class SGStringList */
template <class T> struct SGStringList
{
public:
/** default constructor */
SGStringList() : strings(NULL), num_strings(0), max_string_length(0),
do_free(false) { }

/** constructor for setting params */
SGStringList(T* s, index_t num_s, index_t max_length, bool free_strings=false)
: strings(s), num_strings(num_s), max_string_length(max_length),
do_free(free_strings) { }

/** constructor to create new matrix in memory */
SGStringList(index_t num_s, index_t max_length, bool free_strings=false)
: num_strings(num_s), max_string_length(max_length),
do_free(free_strings)
{
strings=new SGString<T>[num_strings];
}

/** copy constructor */
SGStringList(const SGStringList &orig)
: num_strings(orig.num_strings),
max_string_length(orig.max_string_length), strings(orig.strings),
do_free(orig.do_free) { }


public:
/* number of strings */
int32_t num_strings;
index_t num_strings;

/** length of longest string */
int32_t max_string_length;
index_t max_string_length;

/// this contains the array of features.
SGString<T>* strings;

/** whether vector needs to be freed */
bool do_free;
};

/** template class SGSparseVectorEntry */
Expand Down

0 comments on commit 440c5ef

Please sign in to comment.