Class PLNetDyadRanker
- java.lang.Object
-
- ai.libs.jaicore.ml.dyadranking.algorithm.PLNetDyadRanker
-
- All Implemented Interfaces:
IBatchLearner<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>,ICertaintyProvider<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>,IOnlineLearner<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>,IPredictiveModel<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>,IDyadRanker,IPLDyadRanker
public class PLNetDyadRanker extends java.lang.Object implements IPLDyadRanker, IOnlineLearner<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>, ICertaintyProvider<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>
A dyad ranker based on a Plackett-Luce network. All the provided algorithms are implementations of the PLModel introduced in [1]. [1] Schäfer, D., & Hüllermeier, E. (2018). Dyad ranking using Plackett--Luce models based on joint feature representations. Machine Learning, 107(5), 903–941. https://doi.org/10.1007/s10994-017-5694-9
-
-
Constructor Summary
Constructors Constructor Description PLNetDyadRanker()Constructs a newPLNetDyadRankerusing the defaultIPLNetDyadRankerConfiguration.PLNetDyadRanker(IPLNetDyadRankerConfiguration config)Constructs a newPLNetDyadRankerusing the givenIPLNetDyadRankerConfiguration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcreateNetworkFromDl4jConfigFile(java.io.File configFile)Creates a simple feed-forwardMultiLayerNetworkusing the json representation of aMultiLayerConfigurationin the file .doublegetCertainty(IDyadRankingInstance queryInstance)Returns the certainty for a givenIInstance.IPredictiveModelConfigurationgetConfiguration()Returns theIPredictiveModelConfigurationof this model.intgetEpoch()doublegetLogProbabilityOfTopKRanking(IDyadRankingInstance drInstance, int k)Returns the log of the probablity of the top k of a givenIDyadRankingInstanceunder the Plackett Luce model parametrized by the latent skill values predicted by the PLNet.doublegetLogProbabilityOfTopRanking(IDyadRankingInstance drInstance)Returns the the log of the probablity of the top ranking for a givenIDyadRankingInstanceunder the Plackett Luce model parametrized by the latent skill values predicted by the PLNet.doublegetLogProbabilityRanking(IDyadRankingInstance drInstance)Computes the logarithmic probability for a particular ranking according to the log Placket-Luce model.IDyadRankingInstancegetPairWithLeastCertainty(IDyadRankingInstance drInstance)Returns the pair ofDyads for which the model is least certain.org.deeplearning4j.nn.multilayer.MultiLayerNetworkgetPlNet()doublegetProbabilityOfTopKRanking(IDyadRankingInstance drInstance, int k)doublegetProbabilityOfTopRanking(IDyadRankingInstance drInstance)Returns the probablity of the top ranking for a givenIDyadRankingInstanceunder the Plackett Luce model parametrized by the latent skill values predicted by the PLNet.doublegetProbabilityRanking(IDyadRankingInstance drInstance)Returns the probablity of a givenIDyadRankingInstanceunder the Plackett Luce model parametrized by the latent skill values predicted by the PLNet.doublegetSkillForDyad(Dyad dyad)Returns the latent skill value predicted by the PLNet for a givenDyad.voidloadModelFromFile(java.lang.String filePath)Restore a trained model from a given file path.java.util.List<IDyadRankingInstance>predict(DyadRankingDataset dataset)Performs multiple predictions based on theIInstances contained in the givenAILabeledAttributeArrayDatasets and returns the result.IDyadRankingInstancepredict(IDyadRankingInstance instance)Performs a prediction based on the givenIInstanceand returns the result.voidsaveModelToFile(java.lang.String filePath)Save a trained model at a given file path.voidsetConfiguration(IPredictiveModelConfiguration configuration)Sets theIPredictiveModelConfigurationof this model to the given one.voidtrain(DyadRankingDataset dataset)Trains thisIBatchLearnerusing the givenAILabeledAttributeArrayDataset.voidtrain(DyadRankingDataset dataset, int maxEpochs, double earlyStoppingTrainRatio)voidtrain(java.util.List<org.nd4j.linalg.api.ndarray.INDArray> dataset)voidtrain(java.util.List<org.nd4j.linalg.api.ndarray.INDArray> dataset, int maxEpochs, double earlyStoppingTrainRatio)voidupdate(IDyadRankingInstance instance)Updates thisPLNetDyadRankerbased on the givenIInstance, which needs to be anIDyadRankingInstance.voidupdate(java.util.Set<IDyadRankingInstance> instances)
-
-
-
Constructor Detail
-
PLNetDyadRanker
public PLNetDyadRanker()
Constructs a newPLNetDyadRankerusing the defaultIPLNetDyadRankerConfiguration.
-
PLNetDyadRanker
public PLNetDyadRanker(IPLNetDyadRankerConfiguration config)
Constructs a newPLNetDyadRankerusing the givenIPLNetDyadRankerConfiguration.- Parameters:
config- Configuration for thePLNetDyadRanker.
-
-
Method Detail
-
train
public void train(DyadRankingDataset dataset) throws TrainingException
Description copied from interface:IBatchLearnerTrains thisIBatchLearnerusing the givenAILabeledAttributeArrayDataset.- Specified by:
trainin interfaceIBatchLearner<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>- Parameters:
dataset- TheAILabeledAttributeArrayDatasetwhich should be used for the training.- Throws:
TrainingException- If something fails during the training process.
-
train
public void train(java.util.List<org.nd4j.linalg.api.ndarray.INDArray> dataset)
-
train
public void train(DyadRankingDataset dataset, int maxEpochs, double earlyStoppingTrainRatio)
-
train
public void train(java.util.List<org.nd4j.linalg.api.ndarray.INDArray> dataset, int maxEpochs, double earlyStoppingTrainRatio)
-
update
public void update(IDyadRankingInstance instance) throws TrainingException
Updates thisPLNetDyadRankerbased on the givenIInstance, which needs to be anIDyadRankingInstance. The update procedure is based on algorithm 2 in [1].- Specified by:
updatein interfaceIOnlineLearner<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>- Parameters:
instances- TheIInstancethe update should be based on. Needs to be aIDyadRankingInstance.- Throws:
TrainingException- If something fails during the update process.
-
update
public void update(java.util.Set<IDyadRankingInstance> instances) throws TrainingException
Description copied from interface:IOnlineLearner- Specified by:
updatein interfaceIOnlineLearner<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>- Parameters:
instances- TheSetofIInstances the update should be based on.- Throws:
TrainingException- If something fails during the update process.
-
predict
public IDyadRankingInstance predict(IDyadRankingInstance instance) throws PredictionException
Description copied from interface:IPredictiveModelPerforms a prediction based on the givenIInstanceand returns the result.- Specified by:
predictin interfaceIPredictiveModel<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>- Parameters:
instance- TheIInstancefor which a prediction should be made.- Returns:
- The result of the prediction.
- Throws:
PredictionException- If something fails during the prediction process.
-
predict
public java.util.List<IDyadRankingInstance> predict(DyadRankingDataset dataset) throws PredictionException
Description copied from interface:IPredictiveModelPerforms multiple predictions based on theIInstances contained in the givenAILabeledAttributeArrayDatasets and returns the result.- Specified by:
predictin interfaceIPredictiveModel<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>- Parameters:
dataset- TheAILabeledAttributeArrayDatasetfor which predictions should be made.- Returns:
- The result of the predictions.
- Throws:
PredictionException- If something fails during the prediction process.
-
setConfiguration
public void setConfiguration(IPredictiveModelConfiguration configuration) throws ConfigurationException
Description copied from interface:IPredictiveModelSets theIPredictiveModelConfigurationof this model to the given one.- Specified by:
setConfigurationin interfaceIPredictiveModel<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>- Throws:
ConfigurationException- If something fails during the configuration process.
-
getConfiguration
public IPredictiveModelConfiguration getConfiguration()
Description copied from interface:IPredictiveModelReturns theIPredictiveModelConfigurationof this model.- Specified by:
getConfigurationin interfaceIPredictiveModel<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>- Returns:
- The
IPredictiveModelConfigurationof this model.
-
createNetworkFromDl4jConfigFile
public void createNetworkFromDl4jConfigFile(java.io.File configFile)
Creates a simple feed-forwardMultiLayerNetworkusing the json representation of aMultiLayerConfigurationin the file .- Parameters:
configFile-Filecontaining the json representation of theMultiLayerConfiguration
-
saveModelToFile
public void saveModelToFile(java.lang.String filePath) throws java.io.IOExceptionSave a trained model at a given file path. Note that the produced file is a zip file and a ".zip" ending is added.- Parameters:
filePath- The file path to save to.- Throws:
java.io.IOException
-
loadModelFromFile
public void loadModelFromFile(java.lang.String filePath) throws java.io.IOExceptionRestore a trained model from a given file path. Warning: does not check whether the loaded model is a valid PLNet or conforms to the configuration of the object.- Parameters:
filePath- The file to load from.- Throws:
java.io.IOException
-
getPlNet
public org.deeplearning4j.nn.multilayer.MultiLayerNetwork getPlNet()
-
getEpoch
public int getEpoch()
-
getCertainty
public double getCertainty(IDyadRankingInstance queryInstance)
Description copied from interface:ICertaintyProviderReturns the certainty for a givenIInstance.- Specified by:
getCertaintyin interfaceICertaintyProvider<IDyadRankingInstance,IDyadRankingInstance,DyadRankingDataset>- Parameters:
queryInstance-IInstancefor which certainty shall be obtained.- Returns:
- Certainty of the model for the given
IInstance
-
getPairWithLeastCertainty
public IDyadRankingInstance getPairWithLeastCertainty(IDyadRankingInstance drInstance)
Returns the pair ofDyads for which the model is least certain.- Parameters:
drInstance- Ranking for which certainty should be assessed.- Returns:
- The pair of
Dyads for which the model is least certain.
-
getProbabilityOfTopRanking
public double getProbabilityOfTopRanking(IDyadRankingInstance drInstance)
Returns the probablity of the top ranking for a givenIDyadRankingInstanceunder the Plackett Luce model parametrized by the latent skill values predicted by the PLNet. This may be useful as the probability of a particular ranking diminishes drastically with increasing length of the ranking.- Parameters:
drInstance-IDyadRankingInstancefor which the probability is computed.- Returns:
- Probablity of the top ranking for a given
IDyadRankingInstancegiven the Plackett Luce model parametrized by the skill values predicted by the PLNet.
-
getProbabilityOfTopKRanking
public double getProbabilityOfTopKRanking(IDyadRankingInstance drInstance, int k)
-
getLogProbabilityOfTopRanking
public double getLogProbabilityOfTopRanking(IDyadRankingInstance drInstance)
Returns the the log of the probablity of the top ranking for a givenIDyadRankingInstanceunder the Plackett Luce model parametrized by the latent skill values predicted by the PLNet. This may be useful as the probability of a particular ranking diminishes drastically with increasing length of the ranking.- Parameters:
drInstance-IDyadRankingInstancefor which the probability is computed.- Returns:
- Log of the probablity of the top ranking for a given
IDyadRankingInstancegiven the Plackett Luce model parametrized by the skill values predicted by the PLNet.
-
getLogProbabilityOfTopKRanking
public double getLogProbabilityOfTopKRanking(IDyadRankingInstance drInstance, int k)
Returns the log of the probablity of the top k of a givenIDyadRankingInstanceunder the Plackett Luce model parametrized by the latent skill values predicted by the PLNet. This may be useful as the probability of a particular ranking diminishes drastically with increasing length of the ranking.- Parameters:
drInstance-IDyadRankingInstancefor which the probability is computed.k- Number of top dyads to be considered.- Returns:
- Log of the probablity of the top k of a the given
IDyadRankingInstancegiven the Plackett Luce model parametrized by the skill values predicted by the PLNet.
-
getProbabilityRanking
public double getProbabilityRanking(IDyadRankingInstance drInstance)
Returns the probablity of a givenIDyadRankingInstanceunder the Plackett Luce model parametrized by the latent skill values predicted by the PLNet.- Parameters:
drInstance-IDyadRankingInstancefor which the probability is computed.- Returns:
- Probability of the given
IDyadRankingInstancegiven the Plackett Luce model parametrized by the skill values predicted by the PLNet.
-
getLogProbabilityRanking
public double getLogProbabilityRanking(IDyadRankingInstance drInstance)
Computes the logarithmic probability for a particular ranking according to the log Placket-Luce model.- Parameters:
drInstance-- Returns:
- Logarithmic probability of the given ranking.
-
-