Class PLNetDyadRanker
- java.lang.Object
-
- ai.libs.jaicore.ml.core.learner.ASupervisedLearner<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset,org.api4.java.ai.ml.ranking.IRanking<org.api4.java.ai.ml.ranking.dyad.dataset.IDyad>,org.api4.java.ai.ml.ranking.IRankingPredictionBatch>
-
- ai.libs.jaicore.ml.ranking.dyad.learner.algorithm.PLNetDyadRanker
-
- All Implemented Interfaces:
IDyadRanker,IPLDyadRanker,org.api4.java.ai.ml.core.learner.IFittable<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset>,org.api4.java.ai.ml.core.learner.IFittablePredictor<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset>,org.api4.java.ai.ml.core.learner.ILearnerConfigHandler,org.api4.java.ai.ml.core.learner.IPredictor<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset>,org.api4.java.ai.ml.core.learner.IProbabilisticPredictor,org.api4.java.ai.ml.core.learner.ISupervisedLearner<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset>,org.api4.java.ai.ml.ranking.learner.IRanker<org.api4.java.ai.ml.ranking.dyad.dataset.IDyad,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset>
public class PLNetDyadRanker extends ASupervisedLearner<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset,org.api4.java.ai.ml.ranking.IRanking<org.api4.java.ai.ml.ranking.dyad.dataset.IDyad>,org.api4.java.ai.ml.ranking.IRankingPredictionBatch> implements IPLDyadRanker, org.api4.java.ai.ml.core.learner.IProbabilisticPredictor
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 .voidfit(DyadRankingDataset dataset, int maxEpochs, double earlyStoppingTrainRatio)voidfit(java.util.List<org.nd4j.linalg.api.ndarray.INDArray> dataset)voidfit(java.util.List<org.nd4j.linalg.api.ndarray.INDArray> dataset, int maxEpochs, double earlyStoppingTrainRatio)voidfit(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset dTrain)doublegetCertainty(org.api4.java.ai.ml.core.dataset.supervised.ILabeledInstance testInstance, java.lang.Object label)doublegetCertainty(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance queryInstance, org.api4.java.ai.ml.ranking.IRanking<org.api4.java.ai.ml.ranking.dyad.dataset.IDyad> sizeTwoRanking)intgetEpoch()doublegetLogProbabilityOfTopKRanking(org.api4.java.ai.ml.ranking.dyad.dataset.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(org.api4.java.ai.ml.ranking.dyad.dataset.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(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance drInstance)Computes the logarithmic probability for a particular ranking according to the log Placket-Luce model.org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstancegetPairWithLeastCertainty(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance drInstance)Returns the pair ofDyads for which the model is least certain.org.deeplearning4j.nn.multilayer.MultiLayerNetworkgetPlNet()doublegetProbabilityOfTopKRanking(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance drInstance, int k)doublegetProbabilityOfTopRanking(org.api4.java.ai.ml.ranking.dyad.dataset.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(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance drInstance)Returns the probablity of a givenIDyadRankingInstanceunder the Plackett Luce model parametrized by the latent skill values predicted by the PLNet.doublegetSkillForDyad(org.api4.java.ai.ml.ranking.dyad.dataset.IDyad 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.org.api4.java.ai.ml.ranking.IRanking<org.api4.java.ai.ml.ranking.dyad.dataset.IDyad>predict(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance xTest)org.api4.java.ai.ml.ranking.IRankingPredictionBatchpredict(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance[] dTest)voidsaveModelToFile(java.lang.String filePath)Save a trained model at a given file path.voidupdate(java.util.Set<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance> instances)voidupdate(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance instance)Updates thisPLNetDyadRankerbased on the givenIInstance, which needs to be anIDyadRankingInstance.-
Methods inherited from class ai.libs.jaicore.ml.core.learner.ASupervisedLearner
fitAndPredict, fitAndPredict, fitAndPredict, getConfig, predict, setConfig
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.api4.java.ai.ml.core.learner.IFittablePredictor
fitAndPredict, fitAndPredict, fitAndPredict
-
-
-
-
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
-
update
public void update(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance instance) throws org.api4.java.ai.ml.core.exception.TrainingExceptionUpdates thisPLNetDyadRankerbased on the givenIInstance, which needs to be anIDyadRankingInstance. The update procedure is based on algorithm 2 in [1].- Parameters:
instances- TheIInstancethe update should be based on. Needs to be aIDyadRankingInstance.- Throws:
org.api4.java.ai.ml.core.exception.TrainingException- If something fails during the update process.
-
update
public void update(java.util.Set<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance> instances) throws org.api4.java.ai.ml.core.exception.TrainingException- Throws:
org.api4.java.ai.ml.core.exception.TrainingException
-
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()
-
getPairWithLeastCertainty
public org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance getPairWithLeastCertainty(org.api4.java.ai.ml.ranking.dyad.dataset.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(org.api4.java.ai.ml.ranking.dyad.dataset.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(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance drInstance, int k)
-
getLogProbabilityOfTopRanking
public double getLogProbabilityOfTopRanking(org.api4.java.ai.ml.ranking.dyad.dataset.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(org.api4.java.ai.ml.ranking.dyad.dataset.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(org.api4.java.ai.ml.ranking.dyad.dataset.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(org.api4.java.ai.ml.ranking.dyad.dataset.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.
-
getSkillForDyad
public double getSkillForDyad(org.api4.java.ai.ml.ranking.dyad.dataset.IDyad dyad)
Returns the latent skill value predicted by the PLNet for a givenDyad.
-
fit
public void fit(DyadRankingDataset dataset, int maxEpochs, double earlyStoppingTrainRatio)
-
fit
public void fit(java.util.List<org.nd4j.linalg.api.ndarray.INDArray> dataset, int maxEpochs, double earlyStoppingTrainRatio)
-
fit
public void fit(java.util.List<org.nd4j.linalg.api.ndarray.INDArray> dataset)
-
fit
public void fit(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset dTrain) throws org.api4.java.ai.ml.core.exception.TrainingException, java.lang.InterruptedException- Specified by:
fitin interfaceorg.api4.java.ai.ml.core.learner.IFittable<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset>- Throws:
org.api4.java.ai.ml.core.exception.TrainingExceptionjava.lang.InterruptedException
-
predict
public org.api4.java.ai.ml.ranking.IRanking<org.api4.java.ai.ml.ranking.dyad.dataset.IDyad> predict(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance xTest) throws org.api4.java.ai.ml.core.exception.PredictionException, java.lang.InterruptedException- Specified by:
predictin interfaceorg.api4.java.ai.ml.core.learner.IPredictor<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset>- Specified by:
predictin interfaceorg.api4.java.ai.ml.ranking.learner.IRanker<org.api4.java.ai.ml.ranking.dyad.dataset.IDyad,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset>- Specified by:
predictin classASupervisedLearner<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset,org.api4.java.ai.ml.ranking.IRanking<org.api4.java.ai.ml.ranking.dyad.dataset.IDyad>,org.api4.java.ai.ml.ranking.IRankingPredictionBatch>- Throws:
org.api4.java.ai.ml.core.exception.PredictionExceptionjava.lang.InterruptedException
-
getCertainty
public double getCertainty(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance queryInstance, org.api4.java.ai.ml.ranking.IRanking<org.api4.java.ai.ml.ranking.dyad.dataset.IDyad> sizeTwoRanking)
-
getCertainty
public double getCertainty(org.api4.java.ai.ml.core.dataset.supervised.ILabeledInstance testInstance, java.lang.Object label) throws org.api4.java.ai.ml.core.exception.PredictionException, java.lang.InterruptedException- Specified by:
getCertaintyin interfaceorg.api4.java.ai.ml.core.learner.IProbabilisticPredictor- Throws:
org.api4.java.ai.ml.core.exception.PredictionExceptionjava.lang.InterruptedException
-
predict
public org.api4.java.ai.ml.ranking.IRankingPredictionBatch predict(org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance[] dTest) throws org.api4.java.ai.ml.core.exception.PredictionException, java.lang.InterruptedException- Specified by:
predictin interfaceorg.api4.java.ai.ml.core.learner.IPredictor<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset>- Specified by:
predictin classASupervisedLearner<org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingInstance,org.api4.java.ai.ml.ranking.dyad.dataset.IDyadRankingDataset,org.api4.java.ai.ml.ranking.IRanking<org.api4.java.ai.ml.ranking.dyad.dataset.IDyad>,org.api4.java.ai.ml.ranking.IRankingPredictionBatch>- Throws:
org.api4.java.ai.ml.core.exception.PredictionExceptionjava.lang.InterruptedException
-
-