Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Removed SLEP machine and redundant L1LogisticRegression, rebased Feat…
…ureBlockLogisticRegression and fixed missed weight initialization
- Loading branch information
Showing
15 changed files
with
234 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
examples/undocumented/libshogun/classifier_featureblocklogisticregression.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <shogun/labels/RegressionLabels.h> | ||
#include <shogun/features/DenseFeatures.h> | ||
#include <shogun/classifier/FeatureBlockLogisticRegression.h> | ||
#include <shogun/lib/IndexBlock.h> | ||
#include <shogun/lib/IndexBlockTree.h> | ||
#include <shogun/lib/IndexBlockGroup.h> | ||
#include <shogun/base/init.h> | ||
#include <shogun/lib/common.h> | ||
#include <shogun/io/SGIO.h> | ||
|
||
using namespace shogun; | ||
|
||
void print_message(FILE* target, const char* str) | ||
{ | ||
fprintf(target, "%s", str); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
init_shogun_with_defaults(); | ||
|
||
// create some data | ||
SGMatrix<float64_t> matrix(4,4); | ||
for (int32_t i=0; i<4*4; i++) | ||
matrix.matrix[i]=i; | ||
|
||
CDenseFeatures<float64_t>* features= new CDenseFeatures<float64_t>(matrix); | ||
|
||
// create three labels | ||
CBinaryLabels* labels=new CBinaryLabels(4); | ||
labels->set_label(0, -1); | ||
labels->set_label(1, +1); | ||
labels->set_label(2, -1); | ||
labels->set_label(3, +1); | ||
|
||
CIndexBlock* first_block = new CIndexBlock(0,2); | ||
CIndexBlock* second_block = new CIndexBlock(2,4); | ||
CIndexBlockGroup* block_group = new CIndexBlockGroup(); | ||
block_group->add_block(first_block); | ||
block_group->add_block(second_block); | ||
|
||
CFeatureBlockLogisticRegression* regressor = new CFeatureBlockLogisticRegression(0.5,features,labels,block_group); | ||
regressor->train(); | ||
|
||
regressor->get_w().display_vector(); | ||
|
||
CIndexBlock* root_block = new CIndexBlock(0,4); | ||
root_block->add_sub_block(first_block); | ||
root_block->add_sub_block(second_block); | ||
CIndexBlockTree* block_tree = new CIndexBlockTree(root_block); | ||
|
||
regressor->set_feature_relation(block_tree); | ||
regressor->train(); | ||
|
||
regressor->get_w().display_vector(); | ||
|
||
SG_UNREF(regressor); | ||
exit_shogun(); | ||
return 0; | ||
} |
36 changes: 36 additions & 0 deletions
36
examples/undocumented/python_modular/classifier_featureblock_logistic_regression.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from numpy import array,hstack | ||
from numpy.random import seed, rand | ||
from tools.load import LoadMatrix | ||
lm=LoadMatrix() | ||
|
||
traindat = lm.load_numbers('../data/fm_train_real.dat') | ||
testdat = lm.load_numbers('../data/fm_test_real.dat') | ||
label_traindat = lm.load_labels('../data/label_train_twoclass.dat') | ||
|
||
parameter_list = [[traindat,testdat,label_traindat]] | ||
|
||
def classifier_featureblock_logistic_regression(fm_train=traindat,fm_test=testdat,label_train=label_traindat): | ||
|
||
from modshogun import BinaryLabels, RealFeatures, IndexBlock, IndexBlockGroup, FeatureBlockLogisticRegression | ||
|
||
features = RealFeatures(hstack((traindat,traindat))) | ||
labels = BinaryLabels(hstack((label_train,label_train))) | ||
|
||
n_features = features.get_num_features() | ||
block_one = IndexBlock(0,n_features/2) | ||
block_two = IndexBlock(n_features/2,n_features) | ||
block_group = IndexBlockGroup() | ||
block_group.add_block(block_one) | ||
block_group.add_block(block_two) | ||
|
||
mtlr = FeatureBlockLogisticRegression(0.1,features,labels,block_group) | ||
mtlr.set_regularization(1) # use regularization ratio | ||
mtlr.set_tolerance(1e-2) # use 1e-2 tolerance | ||
mtlr.train() | ||
out = mtlr.apply().get_labels() | ||
|
||
return out | ||
|
||
if __name__=='__main__': | ||
print('FeatureBlockLogisticRegression') | ||
classifier_featureblock_logistic_regression(*parameter_list[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.