Skip to content

Commit

Permalink
Merge pull request #932 from karlnapf/master
Browse files Browse the repository at this point in the history
removed parameter registration for multiclass labels again
  • Loading branch information
karlnapf committed Mar 14, 2013
2 parents b85414b + e651665 commit 9e0747f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
15 changes: 10 additions & 5 deletions examples/undocumented/python_modular/evaluation_clustering.py
Expand Up @@ -27,11 +27,9 @@ def prepare_data():

def run_clustering(data, k):
from shogun.Clustering import KMeans
from shogun.Mathematics import Math_init_random
from shogun.Distance import EuclideanDistance
from shogun.Features import RealFeatures

Math_init_random(42)
fea = RealFeatures(data)
distance = EuclideanDistance(fea, fea)
kmeans=KMeans(k, distance)
Expand All @@ -58,6 +56,11 @@ def assign_labels(data, centroids, ncenters):
def evaluation_clustering (features=fea, ground_truth=gnd_raw, ncenters=10):
from shogun.Evaluation import ClusteringAccuracy, ClusteringMutualInformation
from shogun.Features import MulticlassLabels
from shogun.Mathematics import Math

# reproducable results
Math.init_random(1)

centroids = run_clustering(features, ncenters)
gnd_hat = assign_labels(features, centroids, ncenters)
gnd = MulticlassLabels(ground_truth)
Expand All @@ -66,13 +69,15 @@ def evaluation_clustering (features=fea, ground_truth=gnd_raw, ncenters=10):
AccuracyEval.best_map(gnd_hat, gnd)

accuracy = AccuracyEval.evaluate(gnd_hat, gnd)
#print(('Clustering accuracy = %.4f' % accuracy))
print(('Clustering accuracy = %.4f' % accuracy))

MIEval = ClusteringMutualInformation()
mutual_info = MIEval.evaluate(gnd_hat, gnd)
#print(('Clustering mutual information = %.4f' % mutual_info))
print(('Clustering mutual information = %.4f' % mutual_info))

return gnd, gnd_hat, accuracy, MIEval, mutual_info
# TODO mutual information does not work with serialization
#return gnd, gnd_hat, accuracy, MIEval, mutual_info
return gnd, gnd_hat, accuracy

if __name__ == '__main__':
print('Evaluation Clustering')
Expand Down
13 changes: 9 additions & 4 deletions src/shogun/labels/MulticlassLabels.cpp
@@ -1,6 +1,7 @@
#include <shogun/labels/DenseLabels.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/labels/MulticlassLabels.h>
#include <shogun/base/ParameterMap.h>

using namespace shogun;

Expand Down Expand Up @@ -31,13 +32,17 @@ CMulticlassLabels::~CMulticlassLabels()

void CMulticlassLabels::init()
{
SG_ADD(&m_multiclass_confidences, "multiclass_confidences", "Vectors of "
"multiclass confidences", MS_NOT_AVAILABLE);
/* for this to work, migration has to be fixed */
// SG_ADD(&m_multiclass_confidences, "multiclass_confidences", "Vectors of "
// "multiclass confidences", MS_NOT_AVAILABLE);

// m_parameter_map->finalize_map();

m_multiclass_confidences=SGMatrix<float64_t>();
}

void CMulticlassLabels::set_multiclass_confidences(int32_t i, SGVector<float64_t> confidences)
void CMulticlassLabels::set_multiclass_confidences(int32_t i,
SGVector<float64_t> confidences)
{
REQUIRE(confidences.size()==m_multiclass_confidences.num_rows,
"%s::set_multiclass_confidences(): Length of confidences should "
Expand Down Expand Up @@ -70,7 +75,7 @@ CMulticlassLabels* CMulticlassLabels::obtain_from_generic(CLabels* base_labels)
if (!base_labels)
return NULL;

if(base_labels->get_label_type()!=LT_MULTICLASS)
if (base_labels->get_label_type()!=LT_MULTICLASS)
{
SG_SERROR("CMulticlassLabels::base_labels is of wrong type \"%s\"!\n",
base_labels->get_name());
Expand Down
3 changes: 3 additions & 0 deletions src/shogun/machine/KernelMachine.cpp
Expand Up @@ -690,10 +690,13 @@ void CKernelMachine::init()
MS_NOT_AVAILABLE);
SG_ADD(&m_svs, "m_svs", "Number of ``support vectors''.", MS_NOT_AVAILABLE);

/* new parameter from param version 0 to 1 */
m_parameter_map->put(
new SGParamInfo("custom_kernel", CT_SCALAR, ST_NONE, PT_SGOBJECT, 1),
new SGParamInfo()
);

/* new parameter from param version 0 to 1 */
m_parameter_map->put(
new SGParamInfo("kernel_backup", CT_SCALAR, ST_NONE, PT_SGOBJECT, 1),
new SGParamInfo()
Expand Down

0 comments on commit 9e0747f

Please sign in to comment.