Post on 07-May-2015
description
02/07/201002/07/2010
Contact: Shou Matsumoto (cardialfly@[yahoo|gmail].com)
11
UnBBayesUnBBayes –– PluginPlugin
Feature OverviewFeature Overview
~ ~ Usage and development ofUsage and development of pluginsplugins forfor UnBBayesUnBBayes ~~
Project page: http://sourceforge.net/projects/unbbayes/
22
ContentsContents
��ConceptsConcepts
��Features & BenefitsFeatures & Benefits
��Applications Applications
��Sample Sample Plugins Plugins (you may skip this section)(you may skip this section)
��SpecificationSpecification
��Extension PointsExtension Points’’ Spec. Spec. (you may skip this section)(you may skip this section)
��AvailabilityAvailability
Source: <http://sourceforge.net/projects/unbbayes/>33
What isWhat is UnBBayesUnBBayes??
�� UnBBayesUnBBayes is a probabilistic network is a probabilistic network
framework written in Java. It has both a framework written in Java. It has both a
GUI and an API with inference, GUI and an API with inference,
sampling, learning and evaluation. It sampling, learning and evaluation. It
supports BN, ID, MSBN, OOBN, HBN, supports BN, ID, MSBN, OOBN, HBN,
MEBN/PRMEBN/PR--OWL, structure, parameter OWL, structure, parameter
and incremental learning.and incremental learning.
Co
nce
pts
Co
nce
pts
A plugin descriptor is the main and minimal content of a plugin44
What is aWhat is a pluginplugin??
�� AA pluginplugin consists of a computer program that consists of a computer program that interacts with a host application to provide a interacts with a host application to provide a certain, usually very specific, function "on certain, usually very specific, function "on demand“ [demand“ [wikipediawikipedia].].
�� AnAn UnBBayes’ pluginUnBBayes’ plugin can be a folder, a ZIP or can be a folder, a ZIP or a JAR file located in “a JAR file located in “pluginsplugins” folder.” folder.
�� Content of an ordinalContent of an ordinal UnBBayes’ pluginUnBBayes’ plugin::
–– PluginPlugin descriptor (XML file)descriptor (XML file)
–– Classes (a program)Classes (a program)
–– Resources (e.g. icons, message files...)Resources (e.g. icons, message files...)
Co
nce
pts
Co
nce
pts
Modularization/componentization = organized system55
General Benefits ofGeneral Benefits of PluginsPlugins
�� To enable thirdTo enable third--party developers to create party developers to create
capabilities to extend an applicationcapabilities to extend an application
�� To support features yet unforeseenTo support features yet unforeseen
�� To reduce the size of each applicationTo reduce the size of each application
�� To separate source code from an application To separate source code from an application
because of incompatible software licenses.because of incompatible software licenses.
�� Modularization/Componentization of the Modularization/Componentization of the
softwaresoftware
–– Interfaces are modeled as Interfaces are modeled as extension pointsextension points..
Fea
tures
F
eatu
res
&
& B
enef
its
Ben
efit
s
66
General FeaturesGeneral Features
�� PluginPlugin dependencydependency
�� Plugin’sPlugin’s version controlversion control
�� PluginsPlugins forfor PluginsPlugins
�� HotplugHotplug
�� Flexible I/O handlerFlexible I/O handler
Fea
tures
F
eatu
res
&
& B
enef
its
Ben
efit
s
A dependency is declared in plugin descriptor (XML)77
PluginPlugin dependencydependency
�� We can develop newWe can develop new pluginsplugins reusing a prereusing a pre--existing one.existing one.
–– AA pluginplugin may have some dependency to a premay have some dependency to a pre--existing one.existing one.
�� Pros: Pros:
–– Fast developmentFast development
–– Less redundancy Less redundancy –– smaller programssmaller programs
�� Contras.Contras.
–– Dependency hellDependency hell
•• If myIf my pluginplugin depends on “A” and “A” depends on “B” and depends on “A” and “A” depends on “B” and so on, myso on, my pluginplugin will not work until the user obtains all will not work until the user obtains all the dependencies.the dependencies.
Fea
tures
F
eatu
res
&
& B
enef
its
Ben
efit
s
There is no need to overwrite files in order to overwrite features anymore.88
Plugin’sPlugin’s version controlversion control
�� The application can manage several The application can manage several
different versions of adifferent versions of a pluginplugin..
–– E.g. version 1.0.0, version 5.2.1...E.g. version 1.0.0, version 5.2.1...
�� Usually, the newest version is loaded by Usually, the newest version is loaded by
the application.the application.
–– Except if a givenExcept if a given pluginplugin claims dependency claims dependency
to a unique version.to a unique version.
Fea
tures
& B
enef
its
Fea
tures
& B
enef
its
An extension point is declared in plugin descriptor (XML)99
PluginsPlugins forfor PluginsPlugins
�� ...This application, under the academic ...This application, under the academic world, shall have a new birth of freedom world, shall have a new birth of freedom ---- and that government of theand that government of the pluginplugin, by , by thethe pluginplugin, for the, for the pluginplugin, shall not perish , shall not perish from the earth.from the earth.
–– If aIf a pluginplugin has an has an extension pointextension point, we can , we can add aadd a pluginplugin for it.for it.
–– In another words, we can haveIn another words, we can have pluginspluginsadding functionalities to anotheradding functionalities to another pluginplugin..F
eatu
res
F
eatu
res
&
& B
enef
its
Ben
efit
s
1010
HotplugHotplug
�� Usually, there is no need to restart the Usually, there is no need to restart the
application in order to enable aapplication in order to enable a pluginplugin..
–– Obviously, there are some exceptions.Obviously, there are some exceptions.
�� UnBBayesUnBBayes has a menu item to “reload”has a menu item to “reload”
pluginsplugins at runtime.at runtime.
Fea
tures
F
eatu
res
&
& B
enef
its
Ben
efit
s
File handling is flexible1111
Flexible I/O handlerFlexible I/O handler
�� If more than one moduleIf more than one module pluginplugin can handle a file, can handle a file,
ask for the user.ask for the user.
Fea
tures
F
eatu
res
&
& B
enef
its
Ben
efit
s
�� If more than one If more than one I/O I/O pluginplugin can handle a file, ask can handle a file, ask
for the user.for the user.
1212
ApplicationsApplications
�� Development of a full new functionalityDevelopment of a full new functionality
–– Projects / ModulesProjects / Modules
–– New formalismsNew formalisms
�� Development of a new file format.Development of a new file format.
�� Modeling new node types and/or CPDModeling new node types and/or CPD
�� Usage of new Inference AlgorithmsUsage of new Inference Algorithms
�� LocalizationLocalization
–– E.g. Spanish, JapaneseE.g. Spanish, Japanese
Ap
pli
ca
tio
ns
Ap
pli
ca
tio
ns
1313
Summary of Summary of
extension pointsextension points
I/OI/O
InferenceInference
AlgorithmAlgorithm
NewNew
ModulesModules
LocalizationLocalization
New NodesNew Nodes
andand CPDCPD
Split buttonSplit button for for newnew modulesmodules
A tool with 10 functionalities for massive data handling1414
DataminingDatamining Module Module --
UnBMinerUnBMiner
Sa
mp
le P
lug
ins
Sa
mp
le P
lug
ins
A tool that offers an easy interface for finding entries and analisis. Expert Systems.1515
Metaphor Metaphor –– Medical, Medical,
Human IdentificationHuman Identification
Sa
mp
le P
lug
ins
Sa
mp
le P
lug
ins
Generation of sample data sets from a given network.1616
Sampling Sampling -- Likelihood Likelihood
Weighting, Monte Carlo, GibbsWeighting, Monte Carlo, Gibbs
Sa
mp
le P
lug
ins
Sa
mp
le P
lug
ins
We can select another algorithm to compile a network under the core1717
Inference Algorithms Inference Algorithms ––
Likelihood Weighting, GibbsLikelihood Weighting, Gibbs
Sa
mp
le P
lug
ins
Sa
mp
le P
lug
ins
It is possible to add resource files as plugin1818
OOBN Module’s Japanese OOBN Module’s Japanese
LocalizationLocalization
Sa
mp
le P
lug
ins
Sa
mp
le P
lug
ins
Save or load different network file formats1919
I/O I/O –– DNE, XMLBIF, NETDNE, XMLBIF, NETS
am
ple
Plu
gin
sS
am
ple
Plu
gin
s
It is possible to edit a Conditional Probability Distribution using scripts2020
Conditional Probability Conditional Probability
Distribution Using ScriptsDistribution Using Scripts
Sa
mp
le P
lug
ins
Sa
mp
le P
lug
ins
Everything is configured using plugin descriptors (XML)2121
SpecificationSpecification
�� UnBBayesUnBBayes uses Javauses Java PluginPlugin Framework (JPF) Framework (JPF) forfor pluginplugin support.support.
–– JPF is a openJPF is a open--source, LGPLsource, LGPL licencedlicenced plugplug--in in mechanism adapted from Eclipse's plugmechanism adapted from Eclipse's plug--in in mechanism.mechanism.
�� The “core” ofThe “core” of UnBBayesUnBBayes is the BN module.is the BN module.
–– All other modules/functionalities are beingAll other modules/functionalities are beingrefactoredrefactored asas pluginsplugins..
�� The core has itsThe core has its pluginplugin descriptor to declare descriptor to declare extension points (extension points (unbbayesunbbayes.core)..core).
Sp
ecif
ica
tio
nS
pec
ific
ati
on
2222
Folder StructureFolder StructureS
pec
ific
ati
on
Sp
ecif
ica
tio
n
Place the Place the
plugins hereplugins here
These These areare
default pluginsdefault plugins
thatthat comecome
with thewith the corecore
These XML definitions follow the JPF specification.2323
ModulesModules
�� UnBBayes'UnBBayes' modules are basically swing modules are basically swing
internal frames.internal frames.
Exte
nsi
on
Poin
ts’
Sp
ec.
Exte
nsi
on
Poin
ts’
Sp
ec.
<extension-point id="Module">
<!--class extends unbbayes.util.extension.UnBBayesModule-->
<parameter-def id="class"/>
<!--builder implements unbbayes.util.extension.UnBBayesModuleBuilder-->
<parameter-def id="builder" multiplicity="none-or-one" />
<parameter-def id="name"/>
<parameter-def id="description" multiplicity="none-or-one" />
<parameter-def id="icon" multiplicity="none-or-one" />
<!--category creates new menu items on demmand-->
<parameter-def id="category" multiplicity="none-or-one" />
</extension-point>
This is how UnBMiner's plugin descriptor (plugin.xml) looks like2424
Sample ModuleSample Module -- UnBMinerUnBMinerE
xte
nsi
on
Poin
ts’
Sp
ec.
Exte
nsi
on
Poin
ts’
Sp
ec. <?xml version="1.0" ?>
<!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0" "http://jpf.sourceforge.net/plugin_1_0.dtd">
<plugin id="unbbayes.datamining" version="0.0.1">
<requires>
<import plugin-id="unbbayes.util.extension.core"/>
</requires>
<runtime>
<library id="unbminer" path="classes/" type="code">
<export prefix="*" />
</library>
<library type="resources" path="icons/" id="icons" />
</runtime>
<extension plugin-id="unbbayes.util.extension.core" point-id="Module" id="unbminer">
<parameter id="class" value="unbbayes.datamining.gui.extension.UnBMinerJPFModule" />
<parameter id="name" value="Data Mining Project" />
<parameter id="builder" value="unbbayes.datamining.gui.extension.UnBMinerJPFModule" />
<parameter id="description" value="UnBBayes Dataminer - UnBMiner" />
<parameter id="icon" value="mining.png" />
<parameter id="category" value="tool" />
</extension>
</plugin>
Inference Algorithms are usually started when we "compile" a BN2525
Inference AlgorithmInference Algorithm
�� This is basically a panel (for options) This is basically a panel (for options)
–– This panel holds an implementation ofThis panel holds an implementation of
unbbayes.util.extension.bn.inference.IInferenceAlgorithm, ,
which runs a which runs a specificspecific inference algorithm.inference algorithm.
Exte
nsi
on
Poin
ts’
Sp
ecE
xte
nsi
on
Poin
ts’
Sp
ec..
<extension-point id="InferenceAlgorithm">
<!--class extends
unbbayes.util.extension.bn.inference.InferenceAlgorithmOptionPanel-->
<parameter-def id="class"/>
</extension-point>
A single plugin.xml may implement several extension points2626
Sample AlgorithmSample Algorithm -- GibbsGibbsE
xte
nsi
on
Poin
ts’
Sp
ec.
Exte
nsi
on
Poin
ts’
Sp
ec. <?xml version="1.0" ?> <!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0"
"http://jpf.sourceforge.net/plugin_1_0.dtd">
<plugin id="unbbayes.simulation.sampling.GibbsSampling" version="1.0.0">
<requires><import plugin-id="unbbayes.util.extension.core"/><import plugin-
id="unbbayes.simulation.montecarlo.sampling"/></requires>
<runtime>
<library id="gibbs" path="classes/" type="code"><export prefix="*" /></library>
<library type="resources" path="icons/" id="icons" />
</runtime>
<extension plugin-id="unbbayes.util.extension.core" point-id="Module" id="gibbsSampling">
<parameter id="class" value="unbbayes.gui.GibbsSamplingModule" />
<parameter id="name" value="Gibbs Sampling" />
<parameter id="builder" value="unbbayes.gui.GibbsSamplingModule" />
<parameter id="description" value="Sampling using Gibbs" />
<parameter id="icon" value="sampling.png" />
<parameter id="category" value="sampling" />
</extension>
<extension plugin-id="unbbayes.util.extension.core" point-id="InferenceAlgorithm" id="gibbsAlgorithm">
<parameter id="class" value="unbbayes.gui.option.GibbsSamplingOptionPanel" />
</extension>
</plugin>
A single plugin.xml may specify several extension points - a plugin may expect several plugins2727
I/OI/O
�� This is just a combination of This is just a combination of
unbbayesunbbayes..ioio..BaseIO BaseIO and a nameand a name
–– The name is displayed when a conflict occursThe name is displayed when a conflict occurs
Exte
nsi
on
Poin
ts’
Sp
ecE
xte
nsi
on
Poin
ts’
Sp
ec..
<extension-point id="PNIO">
<parameter-def id="class"/>
<parameter-def id="name"/>
</extension-point>
This is how DNE's plugin descriptor (plugin.xml) looks like2828
Sample I/OSample I/O -- DNEDNEE
xte
nsi
on
Poin
ts’
Sp
ec.
Exte
nsi
on
Poin
ts’
Sp
ec.
<?xml version="1.0" ?>
<!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0"
"http://jpf.sourceforge.net/plugin_1_0.dtd">
<plugin id="unbbayes.io.DneIO" version="1.0.0">
<requires>
<import plugin-id="unbbayes.util.extension.core"/>
</requires>
<extension plugin-id="unbbayes.util.extension.core" point-id="PNIO"
id="DneIO">
<parameter id="class" value="unbbayes.io.DneIO" />
<parameter id="name" value="DNE" />
</extension>
</plugin>
This extension point is a bridge between JPF mechanism and ResourceBundle mechanism2929
Resources Resources -- LocalizationLocalization
�� This is basically a This is basically a
java.util.ListResourceBundle
–– NamingNaming: <: <ClassNameClassName>>__<<LocaleIDLocaleID>>
•• ResourcesResources_es._es.classclass ((SpanishSpanish) )
•• ResourcesResources_pt._pt.class class ((PortuguesePortuguese))
•• ResourcesResources__jaja..class class ((JapaneseJapanese))
Exte
nsi
on
Poin
ts’
Sp
ecE
xte
nsi
on
Poin
ts’
Sp
ec..
<extension-point id="ResourceBundle">
<parameter-def id="class"/>
</extension-point>
Unfortunatelly, most of classes load resources statically, so hotplug is only partial.3030
Sample LocalizationSample LocalizationE
xte
nsi
on
Poin
ts’
Sp
ec.
Exte
nsi
on
Poin
ts’
Sp
ec. <?xml version="1.0" ?>
<!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0" "http://jpf.sourceforge.net/plugin_1_0.dtd">
<plugin id="unbbayes.oobn.resources.ja" version="1.0.0">
<requires><import plugin-id="unbbayes.util.extension.core"/></requires>
<runtime>
<library id="oobnResource_ja" path="classes/" type="code"><export prefix="*" /></library>
</runtime>
<extension plugin-id="unbbayes.util.extension.core" point-id="ResourceBundle" id="oobn_gui_ja">
<parameter id="class" value="unbbayes.gui.oobn.resources.OOBNGuiResource_ja" />
</extension>
<extension plugin-id="unbbayes.util.extension.core" point-id="ResourceBundle" id="oobn_controller_ja">
<parameter id="class" value="unbbayes.controller.oobn.resources.OOBNControllerResources_ja" />
</extension>
<extension plugin-id="unbbayes.util.extension.core" point-id="ResourceBundle" id="oobn_io_ja">
<parameter id="class" value="unbbayes.io.oobn.resources.OOBNIOResources_ja" />
</extension>
<extension plugin-id="unbbayes.util.extension.core" point-id="ResourceBundle" id="oobn_prs_ja">
<parameter id="class" value="unbbayes.prs.oobn.resources.Resources_ja" />
</extension>
</plugin>
Inference algorithms or I/O must be implemented separately to compile/save these nodes3131
New Types of NodesNew Types of Nodes
�� This is a Node and This is a Node and a set of a set of additional information additional information
to display it within GUI.to display it within GUI.
Exte
nsi
on
Poin
ts’
Sp
ecE
xte
nsi
on
Poin
ts’
Sp
ec..
<extension-point id="PluginNode">
<!--class implements unbbayes.prs.extension.IPluginNode-->
<parameter-def id="class"/>
<!--shapeClass implements unbbayes.draw.extension.IPluginUShape-->
<parameter-def id="shapeClass"/>
<parameter-def id="name"/>
<!--panelBuilder implements unbbayes.gui.table.extension.IProbabilityFunctionPanelBuilder-->
<parameter-def id="panelBuilder"/>
<parameter-def id="description" multiplicity="none-or-one" />
<parameter-def id="icon" multiplicity="none-or-one" />
<parameter-def id="cursor" multiplicity="none-or-one" />
</extension-point>
This is a sample stub.3232
Sample NodesSample NodesE
xte
nsi
on
Poin
ts’
Sp
ec.
Exte
nsi
on
Poin
ts’
Sp
ec. <?xml version="1.0" ?>
<!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0" "http://jpf.sourceforge.net/plugin_1_0.dtd">
<plugin id="unbbayes.prs.extension.impl.ProbabilisticNodePluginStub" version="1.0.0">
<requires> <import plugin-id="unbbayes.util.extension.core"/> </requires>
<runtime>
<library id="ProbabilisticNodePluginStub" path="classes/" type="code">
<export prefix="*" />
</library>
<library type="resources" path="icons/" id="ProbabilisticNodePluginStub_icons" />
</runtime>
<extension plugin-id="unbbayes.util.extension.core" point-id="PluginNode" id="ProbabilisticNodePluginStub">
<parameter id="class" value="unbbayes.prs.extension.impl.ProbabilisticNodePluginStub" />
<parameter id="shapeClass" value="unbbayes.draw.extension.impl.DefaultPluginUShape" />
<parameter id="name" value="Boolean Node For Plugin Test" />
<parameter id="panelBuilder" value= "unbbayes.gui.table.extension.StubPanelBuilder" />
<parameter id="description" value="This is a stub in order to test plugins" />
<parameter id="icon" value="icon_stub.gif" />
<parameter id="cursor" value="cursor_stub.gif" />
</extension>
</plugin>
See the specs of "New Node Type" plugin for details3333
Probability Distribution Probability Distribution
EditorEditor
�� Identical to Identical to ““New Node TypeNew Node Type” ” pluginplugin
–– Difference: these are for nodes Difference: these are for nodes already already
incorporatedincorporated into into UnBBayes’ UnBBayes’ corecore
•• E.g. E.g. unbbayesunbbayes..prsprs..bnbn..ProbabilisticNodeProbabilisticNode
Exte
nsi
on
Poin
ts’
Sp
ec.
Exte
nsi
on
Poin
ts’
Sp
ec.
<extension-point id="ProbabilityFunctionPanel">
<parameter-def id="class"/> <!--Node‘s class-->
<parameter-def id="name"/>
<parameter-def id="panelBuilder"/> <!--Panel to edit node-->
<parameter-def id="description" multiplicity="none-or-one" />
<parameter-def id="icon" multiplicity="none-or-one" />
</extension-point>
This is the plugin descriptor (plugin.xml) for CPS plugin3434
Sample Probability Sample Probability
Distribution EditorDistribution Editor
Exte
nsi
on
Poin
ts’
Sp
ec.
Exte
nsi
on
Poin
ts’
Sp
ec. <?xml version="1.0" ?>
<!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0" "http://jpf.sourceforge.net/plugin_1_0.dtd">
<plugin id="edu.gmu.seor.prognos.unbbayesplugin.cps" version="1.0.0">
<requires> <import plugin-id="unbbayes.util.extension.core"/> </requires>
<runtime>
<library id="cps" path="classes/" type="code">
<export prefix="*" />
</library>
<library type="resources" path="icons/" id="cps_icons" />
</runtime>
<extension plugin-id="unbbayes.util.extension.core" point-id="ProbabilityFunctionPanel"
id="cps_ProbabilisticNode">
<parameter id="class" value="unbbayes.prs.bn.ProbabilisticNode" />
<parameter id="name" value="Script edition" />
<parameter id="panelBuilder" value=
"edu.gmu.seor.prognos.unbbayesplugin.cps.gui.extension.CPSPanelBuilder" />
<parameter id="description" value="Edit conditional probability function using scripts" />
<parameter id="icon" value="new_script.png" />
</extension>
</plugin>
A release version for UnBBayes w/ plugin support is yet to come3535
AvailabilityAvailability
�� Currently, these extension points and Currently, these extension points and
samplesample pluginsplugins are only available in theare only available in the
sourceforge’ssourceforge’s SVN (trunk).SVN (trunk).
–– By now, there are no releases supportingBy now, there are no releases supporting
pluginsplugins yet.yet.
�� SVN repository URL:SVN repository URL:
–– https://https://unbbayesunbbayes..svnsvn..sourceforgesourceforge.net/.net/svnrootsvnroot
//unbbayesunbbayes/trunk//trunk/UnBBayesUnBBayes
Av
ail
ab
ilit
yA
va
ilab
ilit
y
Although this is already an open source project, plugins makes it easier to customize3636
FinallyFinally
�� PluginsPlugins can enable thirdcan enable third--party developers to party developers to extendextend UnBBayesUnBBayes
–– Develop features yet unforeseenDevelop features yet unforeseen
•• New formalismsNew formalisms
•• CustomizationCustomization
–– Flexible software licenseFlexible software license
•• Separate sources of incompatible licenses.Separate sources of incompatible licenses.
–– Fast developmentFast development
•• PluginPlugin dependency controldependency control
�� PluginsPlugins reduce the size ofreduce the size of UnBBayesUnBBayes
–– Distribution is easier and application is lightDistribution is easier and application is lightWh
at
Wh
at
plu
gin
sp
lug
ins
can
do
fo
r y
ou
can
do
fo
r y
ou