Skip to content

Commit

Permalink
Added support of other than linear machines in modelselectionoutput
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jul 24, 2012
1 parent 629ccb8 commit 8e7d14c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/shogun/modelselection/ModelSelectionOutput.cpp
Expand Up @@ -10,6 +10,9 @@
#include <shogun/modelselection/ModelSelectionOutput.h>
#include <shogun/base/Parameter.h>
#include <shogun/machine/LinearMachine.h>
#include <shogun/machine/LinearMulticlassMachine.h>
#include <shogun/machine/KernelMachine.h>
#include <shogun/machine/KernelMulticlassMachine.h>

using namespace shogun;

Expand All @@ -33,10 +36,28 @@ void CModelSelectionOutput::output_test_indices(SGVector<index_t> indices)

void CModelSelectionOutput::output_trained_machine(CMachine* machine)
{
if ((CLinearMachine*)machine)
if (dynamic_cast<CLinearMachine*>(machine))
{
CLinearMachine* linear_machine = (CLinearMachine*)machine;
linear_machine->get_w().display_vector("learned_w");
SG_PRINT("learned_bias=%f\n",linear_machine->get_bias());
}
if (dynamic_cast<CKernelMachine*>(machine))
{
CKernelMachine* kernel_machine = (CKernelMachine*)machine;
kernel_machine->get_alphas().display_vector("learned_alphas");
SG_PRINT("learned_bias=%f\n",kernel_machine->get_bias());
}
if (dynamic_cast<CLinearMulticlassMachine*>(machine) ||
dynamic_cast<CKernelMulticlassMachine*>(machine))
{
CMulticlassMachine* mc_machine = (CMulticlassMachine*)machine;
for (int i=0; i<mc_machine->get_num_machines(); i++)
{
CMachine* sub_machine = mc_machine->get_machine(i);
this->output_trained_machine(sub_machine);
SG_UNREF(sub_machine);
}
}
}

Expand Down

5 comments on commit 8e7d14c

@vigsterkr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lisitsyn afaik dynamic_cast<> will throw a bad_cast exception if it fails... shouldn't that be caught or at least indicated by the function to propagate that exception throw?

@lisitsyn
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it return NULL? Will change it to some switch in that case.

@karlnapf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it returns NULL

@vigsterkr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it returns NULL and throws and exception...

@lisitsyn
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it throws nothing out cause actually it works ok

Please sign in to comment.