Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Soeren Sonnenburg
committed
Aug 29, 2011
1 parent
50aac3e
commit ace079d
Showing
28 changed files
with
1,247 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
examples/undocumented/csharp_modular/distance_euclidian_modular.cs
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,30 @@ | ||
using System; | ||
|
||
public class distance_euclidian_modular { | ||
public static void Main() { | ||
modshogun.init_shogun_with_defaults(); | ||
|
||
double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat"); | ||
double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat"); | ||
|
||
RealFeatures feats_train = new RealFeatures(traindata_real); | ||
RealFeatures feats_test = new RealFeatures(testdata_real); | ||
|
||
EuclidianDistance distance = new EuclidianDistance(feats_train, feats_train); | ||
|
||
double[,] dm_train = distance.get_distance_matrix(); | ||
distance.init(feats_train, feats_test); | ||
double[,] dm_test = distance.get_distance_matrix(); | ||
|
||
foreach(double item in dm_train) { | ||
Console.Write(item); | ||
} | ||
|
||
foreach(double item in dm_test) { | ||
Console.Write(item); | ||
} | ||
|
||
modshogun.exit_shogun(); | ||
} | ||
} | ||
|
48 changes: 48 additions & 0 deletions
48
examples/undocumented/csharp_modular/distance_manhattenword_modular.cs
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,48 @@ | ||
using System; | ||
|
||
public class distance_manhattenword_modular { | ||
public static void Main() { | ||
|
||
modshogun.init_shogun_with_defaults(); | ||
int order = 3; | ||
int gap = 0; | ||
bool reverse = false; | ||
|
||
String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat"); | ||
String[] fm_test_dna = Load.load_dna("../data/fm_test_dna.dat"); | ||
double[,] fm_test_real = Load.load_numbers("../data/fm_test_real.dat"); | ||
|
||
StringCharFeatures charfeat = new StringCharFeatures(EAlphabet.DNA); | ||
charfeat.set_features(fm_train_dna); | ||
StringWordFeatures feats_train = new StringWordFeatures(charfeat.get_alphabet()); | ||
feats_train.obtain_from_char(charfeat, order-1, order, gap, reverse); | ||
SortWordString preproc = new SortWordString(); | ||
preproc.init(feats_train); | ||
feats_train.add_preprocessor(preproc); | ||
feats_train.apply_preprocessor(); | ||
|
||
StringCharFeatures charfeat_test = new StringCharFeatures(EAlphabet.DNA); | ||
charfeat_test.set_features(fm_test_dna); | ||
StringWordFeatures feats_test = new StringWordFeatures(charfeat.get_alphabet()); | ||
feats_test.obtain_from_char(charfeat_test, order-1, order, gap, reverse); | ||
feats_test.add_preprocessor(preproc); | ||
feats_test.apply_preprocessor(); | ||
|
||
ManhattanWordDistance distance = new ManhattanWordDistance(feats_train, feats_train); | ||
|
||
double[,] dm_train = distance.get_distance_matrix(); | ||
distance.init(feats_train, feats_test); | ||
double[,] dm_test = distance.get_distance_matrix(); | ||
|
||
foreach(double item in dm_train) { | ||
Console.Write(item); | ||
} | ||
|
||
foreach(double item in dm_test) { | ||
Console.Write(item); | ||
} | ||
|
||
modshogun.exit_shogun(); | ||
} | ||
} | ||
|
33 changes: 33 additions & 0 deletions
33
examples/undocumented/csharp_modular/distribution_linearhmm_modular.cs
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,33 @@ | ||
using System; | ||
|
||
public class distribution_linearhmm_modular { | ||
public static void Main() { | ||
bool reverse = false; | ||
modshogun.init_shogun_with_defaults(); | ||
int order = 3; | ||
int gap = 4; | ||
|
||
String[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat"); | ||
|
||
StringCharFeatures charfeat = new StringCharFeatures(fm_train_dna, EAlphabet.DNA); | ||
StringWordFeatures feats = new StringWordFeatures(charfeat.get_alphabet()); | ||
feats.obtain_from_char(charfeat, order-1, order, gap, reverse); | ||
|
||
LinearHMM hmm = new LinearHMM(feats); | ||
hmm.train(); | ||
|
||
hmm.get_transition_probs(); | ||
|
||
int num_examples = feats.get_num_vectors(); | ||
int num_param = hmm.get_num_model_parameters(); | ||
for (int i = 0; i < num_examples; i++) | ||
for(int j = 0; j < num_param; j++) { | ||
hmm.get_log_derivative(j, i); | ||
} | ||
|
||
double[] out_likelihood = hmm.get_log_likelihood(); | ||
double out_sample = hmm.get_log_likelihood_sample(); | ||
|
||
modshogun.exit_shogun(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
examples/undocumented/csharp_modular/kernel_anova_modular.cs
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,23 @@ | ||
using System; | ||
|
||
public class kernel_anova_modular { | ||
public static void Main() { | ||
modshogun.init_shogun_with_defaults(); | ||
int cardinality = 2; | ||
int size_cache = 5; | ||
|
||
double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat"); | ||
double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat"); | ||
|
||
RealFeatures feats_train = new RealFeatures(traindata_real); | ||
RealFeatures feats_test = new RealFeatures(testdata_real); | ||
|
||
ANOVAKernel kernel = new ANOVAKernel(feats_train, feats_train, cardinality, size_cache); | ||
|
||
double[,] km_train = kernel.get_kernel_matrix(); | ||
kernel.init(feats_train, feats_test); | ||
double[,] km_test = kernel.get_kernel_matrix(); | ||
|
||
modshogun.exit_shogun(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
examples/undocumented/csharp_modular/kernel_cauchy_modular.cs
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,50 @@ | ||
using System; | ||
|
||
public class kernel_cauchy_modular { | ||
public static void Main() { | ||
modshogun.init_shogun_with_defaults(); | ||
double sigma = 1.0; | ||
|
||
double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat"); | ||
double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat"); | ||
|
||
RealFeatures feats_train = new RealFeatures(traindata_real); | ||
RealFeatures feats_test = new RealFeatures(testdata_real); | ||
|
||
EuclidianDistance distance = new EuclidianDistance(feats_train, feats_train); | ||
|
||
CauchyKernel kernel = new CauchyKernel(feats_train, feats_train, sigma, distance); | ||
|
||
double[,] km_train = kernel.get_kernel_matrix(); | ||
|
||
kernel.init(feats_train, feats_test); | ||
double[,] km_test=kernel.get_kernel_matrix(); | ||
|
||
|
||
// Parse and Display km_train | ||
Console.Write("km_train:\n"); | ||
int numRows = km_train.GetLength(0); | ||
int numCols = km_train.GetLength(1); | ||
|
||
for(int i = 0; i < numRows; i++){ | ||
for(int j = 0; j < numCols; j++){ | ||
Console.Write(km_train[i,j] +" "); | ||
} | ||
Console.Write("\n"); | ||
} | ||
|
||
// Parse and Display km_test | ||
Console.Write("\nkm_test:\n"); | ||
numRows = km_test.GetLength(0); | ||
numCols = km_test.GetLength(1); | ||
|
||
for(int i = 0; i < numRows; i++){ | ||
for(int j = 0; j < numCols; j++){ | ||
Console.Write(km_test[i,j] +" "); | ||
} | ||
Console.Write("\n"); | ||
} | ||
|
||
modshogun.exit_shogun(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
examples/undocumented/csharp_modular/kernel_chi2_modular.cs
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,49 @@ | ||
using System; | ||
|
||
public class kernel_chi2_modular { | ||
public static void Main() { | ||
modshogun.init_shogun_with_defaults(); | ||
double width = 1.4; | ||
int size_cache = 10; | ||
|
||
double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat"); | ||
double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat"); | ||
|
||
RealFeatures feats_train = new RealFeatures(traindata_real); | ||
RealFeatures feats_test = new RealFeatures(testdata_real); | ||
|
||
Chi2Kernel kernel = new Chi2Kernel(feats_train, feats_train, width, size_cache); | ||
|
||
double[,] km_train = kernel.get_kernel_matrix(); | ||
|
||
kernel.init(feats_train, feats_test); | ||
double[,] km_test=kernel.get_kernel_matrix(); | ||
|
||
// Parse and Display km_train | ||
Console.Write("km_train:\n"); | ||
int numRows = km_train.GetLength(0); | ||
int numCols = km_train.GetLength(1); | ||
|
||
for(int i = 0; i < numRows; i++){ | ||
for(int j = 0; j < numCols; j++){ | ||
Console.Write(km_train[i,j] +" "); | ||
} | ||
Console.Write("\n"); | ||
} | ||
|
||
// Parse and Display km_test | ||
Console.Write("\nkm_test:\n"); | ||
numRows = km_test.GetLength(0); | ||
numCols = km_test.GetLength(1); | ||
|
||
for(int i = 0; i < numRows; i++){ | ||
for(int j = 0; j < numCols; j++){ | ||
Console.Write(km_test[i,j] +" "); | ||
} | ||
Console.Write("\n"); | ||
} | ||
|
||
modshogun.exit_shogun(); | ||
} | ||
} | ||
|
50 changes: 50 additions & 0 deletions
50
examples/undocumented/csharp_modular/kernel_circular_modular.cs
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,50 @@ | ||
using System; | ||
|
||
public class kernel_circular_modular { | ||
public static void Main() { | ||
modshogun.init_shogun_with_defaults(); | ||
double sigma = 1.0; | ||
|
||
double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat"); | ||
double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat"); | ||
|
||
RealFeatures feats_train = new RealFeatures(traindata_real); | ||
RealFeatures feats_test = new RealFeatures(testdata_real); | ||
|
||
EuclidianDistance distance = new EuclidianDistance(feats_train, feats_train); | ||
|
||
CircularKernel kernel = new CircularKernel(feats_train, feats_train, sigma, distance); | ||
|
||
double[,] km_train = kernel.get_kernel_matrix(); | ||
|
||
kernel.init(feats_train, feats_test); | ||
double[,] km_test=kernel.get_kernel_matrix(); | ||
|
||
|
||
// Parse and Display km_train | ||
Console.Write("km_train:\n"); | ||
int numRows = km_train.GetLength(0); | ||
int numCols = km_train.GetLength(1); | ||
|
||
for(int i = 0; i < numRows; i++){ | ||
for(int j = 0; j < numCols; j++){ | ||
Console.Write(km_train[i,j] +" "); | ||
} | ||
Console.Write("\n"); | ||
} | ||
|
||
// Parse and Display km_test | ||
Console.Write("\nkm_test:\n"); | ||
numRows = km_test.GetLength(0); | ||
numCols = km_test.GetLength(1); | ||
|
||
for(int i = 0; i < numRows; i++){ | ||
for(int j = 0; j < numCols; j++){ | ||
Console.Write(km_test[i,j] +" "); | ||
} | ||
Console.Write("\n"); | ||
} | ||
|
||
modshogun.exit_shogun(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
examples/undocumented/csharp_modular/kernel_const_modular.cs
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,45 @@ | ||
using System; | ||
|
||
public class kernel_const_modular { | ||
public static void Main() { | ||
modshogun.init_shogun_with_defaults(); | ||
double c = 23; | ||
|
||
DummyFeatures feats_train = new DummyFeatures(10); | ||
DummyFeatures feats_test = new DummyFeatures(17); | ||
|
||
ConstKernel kernel = new ConstKernel(feats_train, feats_train, c); | ||
|
||
double[,] km_train = kernel.get_kernel_matrix(); | ||
|
||
kernel.init(feats_train, feats_test); | ||
double[,] km_test=kernel.get_kernel_matrix(); | ||
|
||
// Parse and Display km_train | ||
Console.Write("km_train:\n"); | ||
int numRows = km_train.GetLength(0); | ||
int numCols = km_train.GetLength(1); | ||
|
||
for(int i = 0; i < numRows; i++){ | ||
for(int j = 0; j < numCols; j++){ | ||
Console.Write(km_train[i,j] +" "); | ||
} | ||
Console.Write("\n"); | ||
} | ||
|
||
// Parse and Display km_test | ||
Console.Write("\nkm_test:\n"); | ||
numRows = km_test.GetLength(0); | ||
numCols = km_test.GetLength(1); | ||
|
||
for(int i = 0; i < numRows; i++){ | ||
for(int j = 0; j < numCols; j++){ | ||
Console.Write(km_test[i,j] +" "); | ||
} | ||
Console.Write("\n"); | ||
} | ||
|
||
modshogun.exit_shogun(); | ||
} | ||
} | ||
|
45 changes: 45 additions & 0 deletions
45
examples/undocumented/csharp_modular/kernel_diag_modular.cs
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,45 @@ | ||
using System; | ||
|
||
public class kernel_diag_modular { | ||
public static void Main() { | ||
modshogun.init_shogun_with_defaults(); | ||
double diag = 23; | ||
|
||
DummyFeatures feats_train = new DummyFeatures(10); | ||
DummyFeatures feats_test = new DummyFeatures(17); | ||
|
||
ConstKernel kernel = new ConstKernel(feats_train, feats_train, diag); | ||
|
||
double[,] km_train = kernel.get_kernel_matrix(); | ||
|
||
kernel.init(feats_train, feats_test); | ||
double[,] km_test=kernel.get_kernel_matrix(); | ||
|
||
// Parse and Display km_train | ||
Console.Write("km_train:\n"); | ||
int numRows = km_train.GetLength(0); | ||
int numCols = km_train.GetLength(1); | ||
|
||
for(int i = 0; i < numRows; i++){ | ||
for(int j = 0; j < numCols; j++){ | ||
Console.Write(km_train[i,j] +" "); | ||
} | ||
Console.Write("\n"); | ||
} | ||
|
||
// Parse and Display km_test | ||
Console.Write("\nkm_test:\n"); | ||
numRows = km_test.GetLength(0); | ||
numCols = km_test.GetLength(1); | ||
|
||
for(int i = 0; i < numRows; i++){ | ||
for(int j = 0; j < numCols; j++){ | ||
Console.Write(km_test[i,j] +" "); | ||
} | ||
Console.Write("\n"); | ||
} | ||
|
||
modshogun.exit_shogun(); | ||
} | ||
} | ||
|
Oops, something went wrong.