Skip to content

Commit

Permalink
KnowledgeBase is now an interface, while the implementation moved to …
Browse files Browse the repository at this point in the history
…StandardKnowledgeBase. The interface contains a static factory method to produce any KB. This enable us to define the knowledgeBase field of BaseTrainable private and final.
  • Loading branch information
datumbox committed Jan 8, 2016
1 parent a378241 commit ce5d2f1
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 166 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,7 +1,7 @@
CHANGELOG CHANGELOG
========= =========


Version 0.7.0-SNAPSHOT - Build 20160107 Version 0.7.0-SNAPSHOT - Build 20160108
--------------------------------------- ---------------------------------------


- Rename the erase() method to delete() in all interfaces. - Rename the erase() method to delete() in all interfaces.
Expand Down Expand Up @@ -50,6 +50,7 @@ Version 0.7.0-SNAPSHOT - Build 20160107
- Changed the behaviour and the public methods of the DatabaseConnector interface. The dropDatabase() is replaced with a clear() method that deletes all the data but does not close the connection with the database. - Changed the behaviour and the public methods of the DatabaseConnector interface. The dropDatabase() is replaced with a clear() method that deletes all the data but does not close the connection with the database.
- KnowledgeBase is no longer serializable. Its serializable fields are stored individually into the Database. - KnowledgeBase is no longer serializable. Its serializable fields are stored individually into the Database.
- Restructuring the framework to remove all FindBug warnings. - Restructuring the framework to remove all FindBug warnings.
- KnowledgeBase is now an interface, while the implementation moved to StandardKnowledgeBase. The interface contains a static factory method to produce any KB. This enable us to define the knowledgeBase field of BaseTrainable private and final.


Version 0.6.1 - Build 20160102 Version 0.6.1 - Build 20160102
------------------------------ ------------------------------
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -15,7 +15,7 @@ The code is licensed under the [Apache License, Version 2.0](https://github.com/
Version Version
------- -------


The latest version is 0.7.0-SNAPSHOT (Build 20160107). The latest version is 0.7.0-SNAPSHOT (Build 20160108).


The [master branch](https://github.com/datumbox/datumbox-framework/tree/master) is the latest stable version of the framework. The [devel branch](https://github.com/datumbox/datumbox-framework/tree/devel) is the development branch. All the previous stable versions are marked with [tags](https://github.com/datumbox/datumbox-framework/releases). The [master branch](https://github.com/datumbox/datumbox-framework/tree/master) is the latest stable version of the framework. The [devel branch](https://github.com/datumbox/datumbox-framework/tree/devel) is the development branch. All the previous stable versions are marked with [tags](https://github.com/datumbox/datumbox-framework/releases).


Expand Down
1 change: 1 addition & 0 deletions TODO.txt
Expand Up @@ -4,6 +4,7 @@ CODE IMPROVEMENTS
- Checkout some of the "Load of known null value" perhaps we can completely remove this parameter if it is always null. MatrixDataframe.newInstance param recordIdsReference. - Checkout some of the "Load of known null value" perhaps we can completely remove this parameter if it is always null. MatrixDataframe.newInstance param recordIdsReference.
- Checkout that the example project passes as is. Check that the hybridized is on by default. - Checkout that the example project passes as is. Check that the hybridized is on by default.
- Update the example project to the latest version build and the config file. - Update the example project to the latest version build and the config file.

- Add a predictRecord() method BaseMLmodel and refactor the code to be implemented by every algorithm. - Add a predictRecord() method BaseMLmodel and refactor the code to be implemented by every algorithm.
- Add multithreading support. - Add multithreading support.
- Update all maven plugins and dependencies to their latest versions. - Update all maven plugins and dependencies to their latest versions.
Expand Down
Expand Up @@ -18,21 +18,23 @@
import com.datumbox.common.dataobjects.Dataframe; import com.datumbox.common.dataobjects.Dataframe;
import com.datumbox.common.objecttypes.Trainable; import com.datumbox.common.objecttypes.Trainable;
import com.datumbox.common.persistentstorage.interfaces.DatabaseConfiguration; import com.datumbox.common.persistentstorage.interfaces.DatabaseConfiguration;
import com.datumbox.framework.machinelearning.common.dataobjects.StandardKnowledgeBase;
import com.datumbox.framework.machinelearning.common.dataobjects.KnowledgeBase; import com.datumbox.framework.machinelearning.common.dataobjects.KnowledgeBase;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;


/** /**
* Base class for every Model of the Framework. This includes Machine Learning * Base class for every Trainable Algorithm of the Framework. This includes Machine Learning
* Models, Data Transformers, Feature Selectors etc. * Models, Data Transformers, Feature Selectors etc.
* *
* @author Vasilis Vryniotis <bbriniotis@datumbox.com> * @author Vasilis Vryniotis <bbriniotis@datumbox.com>
* @param <MP> * @param <MP>
* @param <TP> * @param <TP>
* @param <KB> * @param <KB>
*/ */
public abstract class BaseTrainable<MP extends BaseModelParameters, TP extends BaseTrainingParameters, KB extends KnowledgeBase<MP, TP>> implements Trainable<MP, TP> { public abstract class BaseTrainable<MP extends BaseModelParameters, TP extends BaseTrainingParameters, KB extends StandardKnowledgeBase<MP, TP>> implements Trainable<MP, TP> {


/** /**
* The Logger of all algorithms. * The Logger of all algorithms.
Expand All @@ -43,13 +45,12 @@ public abstract class BaseTrainable<MP extends BaseModelParameters, TP extends B
/** /**
* The name of the Database where we persist our data. * The name of the Database where we persist our data.
*/ */
protected String dbName; protected final String dbName;


/** /**
* The KnowledgeBase instance of the algorithm. Do NOT access it directly, * The KnowledgeBase instance of the algorithm.
* use the kb() getter instead.
*/ */
protected KB knowledgeBase; private final KB knowledgeBase;


/** /**
* Generates a new instance of a BaseTrainable by providing the Class of the * Generates a new instance of a BaseTrainable by providing the Class of the
Expand All @@ -58,13 +59,13 @@ public abstract class BaseTrainable<MP extends BaseModelParameters, TP extends B
* @param <BT> * @param <BT>
* @param aClass * @param aClass
* @param dbName * @param dbName
* @param dbConfig * @param dbConf
* @return * @return
*/ */
public static <BT extends BaseTrainable> BT newInstance(Class<BT> aClass, String dbName, DatabaseConfiguration dbConfig) { public static <BT extends BaseTrainable> BT newInstance(Class<BT> aClass, String dbName, DatabaseConfiguration dbConf) {
BT algorithm = null; BT algorithm = null;
try { try {
algorithm = aClass.getConstructor(String.class, DatabaseConfiguration.class).newInstance(dbName, dbConfig); algorithm = aClass.getConstructor(String.class, DatabaseConfiguration.class).newInstance(dbName, dbConf);
} }
catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ex) { catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
Expand All @@ -74,34 +75,23 @@ public static <BT extends BaseTrainable> BT newInstance(Class<BT> aClass, String
} }


/** /**
* Protected Constructor which does not include the initialization of the * The basic Constructor of all BaseTrainable classes.
* KnowledgeBase.
* *
* @param dbName * @param baseDBname
* @param dbConf * @param dbConf
* @param kbClass
* @param kbSubtypeClasses
*/ */
protected BaseTrainable(String dbName, DatabaseConfiguration dbConf) { protected BaseTrainable(String baseDBname, DatabaseConfiguration dbConf, Class<? extends StandardKnowledgeBase> kbClass, Class<? extends Serializable>... kbSubtypeClasses) {
String methodName = this.getClass().getSimpleName(); String methodName = this.getClass().getSimpleName();
String dbNameSeparator = dbConf.getDBnameSeparator(); String dbNameSeparator = dbConf.getDBnameSeparator();
if(!dbName.contains(methodName+dbNameSeparator)) { //patch for the K-fold cross validation which already contains the name of the algorithm in the dbname if(!baseDBname.contains(methodName+dbNameSeparator)) { //patch for the K-fold cross validation which already contains the name of the algorithm in the dbname
dbName += dbNameSeparator + methodName; baseDBname += dbNameSeparator + methodName;
} }


this.dbName = dbName; dbName = baseDBname;
}

knowledgeBase = (KB) KnowledgeBase.newInstance(kbClass, dbName, dbConf, kbSubtypeClasses);
/**
* Protected Constructor which includes the initialization of the
* KnowledgeBase.
*
* @param dbName
* @param dbConf
* @param mpClass
* @param tpClass
*/
protected BaseTrainable(String dbName, DatabaseConfiguration dbConf, Class<MP> mpClass, Class<TP> tpClass) {
this(dbName, dbConf);
this.knowledgeBase = (KB) new KnowledgeBase(this.dbName, dbConf, mpClass, tpClass);
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
Expand Down
Expand Up @@ -22,7 +22,7 @@


import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseModelParameters; import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseModelParameters;
import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainingParameters; import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainingParameters;
import com.datumbox.framework.machinelearning.common.dataobjects.KnowledgeBase; import com.datumbox.framework.machinelearning.common.dataobjects.StandardKnowledgeBase;


/** /**
* Base class for all the Data Transformers of the framework. * Base class for all the Data Transformers of the framework.
Expand All @@ -31,7 +31,7 @@
* @param <MP> * @param <MP>
* @param <TP> * @param <TP>
*/ */
public abstract class DataTransformer<MP extends DataTransformer.ModelParameters, TP extends DataTransformer.TrainingParameters> extends BaseTrainable<MP, TP, KnowledgeBase<MP, TP>> { public abstract class DataTransformer<MP extends DataTransformer.ModelParameters, TP extends DataTransformer.TrainingParameters> extends BaseTrainable<MP, TP, StandardKnowledgeBase<MP, TP>> {


/** /**
* The ModelParameters class stores the coefficients that were learned during * The ModelParameters class stores the coefficients that were learned during
Expand Down Expand Up @@ -65,7 +65,7 @@ public static abstract class TrainingParameters extends BaseTrainingParameters {
* @see com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainable#BaseTrainable(java.lang.String, com.datumbox.common.persistentstorage.interfaces.DatabaseConfiguration, java.lang.Class, java.lang.Class) * @see com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainable#BaseTrainable(java.lang.String, com.datumbox.common.persistentstorage.interfaces.DatabaseConfiguration, java.lang.Class, java.lang.Class)
*/ */
protected DataTransformer(String dbName, DatabaseConfiguration dbConf, Class<MP> mpClass, Class<TP> tpClass) { protected DataTransformer(String dbName, DatabaseConfiguration dbConf, Class<MP> mpClass, Class<TP> tpClass) {
super(dbName, dbConf, mpClass, tpClass); super(dbName, dbConf, StandardKnowledgeBase.class, mpClass, tpClass);
} }


/** /**
Expand Down
Expand Up @@ -22,7 +22,7 @@
import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainable; import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainable;
import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseModelParameters; import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseModelParameters;
import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainingParameters; import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainingParameters;
import com.datumbox.framework.machinelearning.common.dataobjects.KnowledgeBase; import com.datumbox.framework.machinelearning.common.dataobjects.StandardKnowledgeBase;


/** /**
* Base class for all the Feature Selectors of the framework. * Base class for all the Feature Selectors of the framework.
Expand All @@ -31,7 +31,7 @@
* @param <MP> * @param <MP>
* @param <TP> * @param <TP>
*/ */
public abstract class FeatureSelection<MP extends FeatureSelection.ModelParameters, TP extends FeatureSelection.TrainingParameters> extends BaseTrainable<MP, TP, KnowledgeBase<MP, TP>> { public abstract class FeatureSelection<MP extends FeatureSelection.ModelParameters, TP extends FeatureSelection.TrainingParameters> extends BaseTrainable<MP, TP, StandardKnowledgeBase<MP, TP>> {


/** /**
* The ModelParameters class stores the coefficients that were learned during * The ModelParameters class stores the coefficients that were learned during
Expand Down Expand Up @@ -65,7 +65,7 @@ public static abstract class TrainingParameters extends BaseTrainingParameters {
* @see com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainable#BaseTrainable(java.lang.String, com.datumbox.common.persistentstorage.interfaces.DatabaseConfiguration, java.lang.Class, java.lang.Class) * @see com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainable#BaseTrainable(java.lang.String, com.datumbox.common.persistentstorage.interfaces.DatabaseConfiguration, java.lang.Class, java.lang.Class)
*/ */
protected FeatureSelection(String dbName, DatabaseConfiguration dbConf, Class<MP> mpClass, Class<TP> tpClass) { protected FeatureSelection(String dbName, DatabaseConfiguration dbConf, Class<MP> mpClass, Class<TP> tpClass) {
super(dbName, dbConf, mpClass, tpClass); super(dbName, dbConf, StandardKnowledgeBase.class, mpClass, tpClass);
} }




Expand Down
Expand Up @@ -72,17 +72,16 @@ public static abstract class ValidationMetrics extends BaseValidationMetrics {
} }


/** /**
* @param dbName * @param baseDBname
* @param dbConf * @param dbConf
* @param mpClass * @param mpClass
* @param tpClass * @param tpClass
* @param vmClass * @param vmClass
* @param modelValidator * @param modelValidator
* @see com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainable#BaseTrainable(java.lang.String, com.datumbox.common.persistentstorage.interfaces.DatabaseConfiguration, java.lang.Class, java.lang.Class) * @see com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainable#BaseTrainable(java.lang.String, com.datumbox.common.persistentstorage.interfaces.DatabaseConfiguration, java.lang.Class, java.lang.Class)
*/ */
protected BaseMLmodel(String dbName, DatabaseConfiguration dbConf, Class<MP> mpClass, Class<TP> tpClass, Class<VM> vmClass, ModelValidation<MP, TP, VM> modelValidator) { protected BaseMLmodel(String baseDBname, DatabaseConfiguration dbConf, Class<MP> mpClass, Class<TP> tpClass, Class<VM> vmClass, ModelValidation<MP, TP, VM> modelValidator) {
super(dbName, dbConf); super(baseDBname, dbConf, MLmodelKnowledgeBase.class, mpClass, tpClass, vmClass);
this.knowledgeBase = new MLmodelKnowledgeBase<>(this.dbName, dbConf, mpClass, tpClass, vmClass);
this.modelValidator = modelValidator; this.modelValidator = modelValidator;
} }


Expand Down
Expand Up @@ -21,9 +21,9 @@
import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseModelParameters; import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseModelParameters;
import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainingParameters; import com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainingParameters;
import com.datumbox.framework.machinelearning.common.bases.mlmodels.BaseMLmodel; import com.datumbox.framework.machinelearning.common.bases.mlmodels.BaseMLmodel;
import com.datumbox.framework.machinelearning.common.dataobjects.KnowledgeBase;
import com.datumbox.framework.machinelearning.common.bases.datatransformation.DataTransformer; import com.datumbox.framework.machinelearning.common.bases.datatransformation.DataTransformer;
import com.datumbox.framework.machinelearning.common.bases.featureselection.FeatureSelection; import com.datumbox.framework.machinelearning.common.bases.featureselection.FeatureSelection;
import com.datumbox.framework.machinelearning.common.dataobjects.StandardKnowledgeBase;


/** /**
* The BaseWrapper is a trainable object that uses composition instead of inheritance * The BaseWrapper is a trainable object that uses composition instead of inheritance
Expand All @@ -35,7 +35,7 @@
* @param <MP> * @param <MP>
* @param <TP> * @param <TP>
*/ */
public abstract class BaseWrapper<MP extends BaseWrapper.ModelParameters, TP extends BaseWrapper.TrainingParameters> extends BaseTrainable<MP, TP, KnowledgeBase<MP, TP>> { public abstract class BaseWrapper<MP extends BaseWrapper.ModelParameters, TP extends BaseWrapper.TrainingParameters> extends BaseTrainable<MP, TP, StandardKnowledgeBase<MP, TP>> {


/** /**
* The DataTransformer instance of the wrapper. * The DataTransformer instance of the wrapper.
Expand Down Expand Up @@ -214,7 +214,7 @@ public void setMLmodelTrainingParameters(ML.TrainingParameters mlmodelTrainingPa
* @see com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainable#BaseTrainable(java.lang.String, com.datumbox.common.persistentstorage.interfaces.DatabaseConfiguration, java.lang.Class, java.lang.Class) * @see com.datumbox.framework.machinelearning.common.bases.baseobjects.BaseTrainable#BaseTrainable(java.lang.String, com.datumbox.common.persistentstorage.interfaces.DatabaseConfiguration, java.lang.Class, java.lang.Class)
*/ */
protected BaseWrapper(String dbName, DatabaseConfiguration dbConf, Class<MP> mpClass, Class<TP> tpClass) { protected BaseWrapper(String dbName, DatabaseConfiguration dbConf, Class<MP> mpClass, Class<TP> tpClass) {
super(dbName, dbConf, mpClass, tpClass); super(dbName, dbConf, StandardKnowledgeBase.class, mpClass, tpClass);
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
Expand Down

0 comments on commit ce5d2f1

Please sign in to comment.