Skip to content

Commit

Permalink
Big backfill & Doc cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralmond committed Jan 5, 2020
1 parent d1f82ab commit 0810afa
Show file tree
Hide file tree
Showing 55 changed files with 1,604 additions and 255 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Package: Peanut
Version: 0.7-1
Date: 2019/10/21
Version: 0.8-2
Date: 2019/12/11
Title: Parameterized Bayesian Networks, Abstract Classes
Author: Russell Almond
Maintainer: Russell Almond <ralmond@fsu.edu>
Depends: R (>= 3.0), CPTtools (>= 0.5), methods, shiny (>= 1.1), shinyjs, futile.logger
Depends: R (>= 3.0), CPTtools (>= 0.5), methods, futile.logger
Imports: shiny (>= 1.1), shinyjs, utils
Description: This provides support of learning conditional probability tables parameterized using CPTtools
License: Artistic-2.0
URL: http://pluto.coe.fsu.edu/RNetica
Expand Down
9 changes: 7 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export(is.Pnet, as.Pnet, Pnet,
BuildAllTables,
is.Pnode, as.Pnode, Pnode, PnodeNet,
PnodeQ, "PnodeQ<-",
PnodeProbs, "PnodeProbs<-",
PnodePriorWeight, "PnodePriorWeight<-",
PnodePostWeight,
PnodeRules, "PnodeRules<-",
PnodeLink, "PnodeLink<-",
PnodeLnAlphas, "PnodeLnAlphas<-",
Expand Down Expand Up @@ -52,6 +54,7 @@ S3method(PnodeParentTvals, default)


## BN generics.
exportClasses(Pnet,Pnode)
export(PnodeName, "PnodeName<-",
PnodeTitle, "PnodeTitle<-",
PnodeDescription, "PnodeDescription<-",
Expand All @@ -70,7 +73,7 @@ export(PnodeName, "PnodeName<-",
PnetDescription, "PnetDescription<-",
PnetFindNode,
PnetMakeStubNodes, PnetRemoveStubNodes,PnetAdjoin,
PnetDetach,
PnetDetach, PnetCompile,
PnetSerialize, PnetUnserialize, unserializePnet
)
exportMethods(PnodeName, "PnodeName<-",
Expand All @@ -84,20 +87,22 @@ exportMethods(PnodeName, "PnodeName<-",
PnodeStateBounds, "PnodeStateBounds<-",
PnodeParents, "PnodeParents<-", PnodeParentNames, PnodeNumParents,
isPnodeContinuous,
PnodeEvidence,"PnodeEvidence<-",
PnetName, "PnetName<-",
PnetTitle, "PnetTitle<-",
PnetHub, "PnetHub<-",
PnetPathname, "PnetPathname<-",
PnetDescription, "PnetDescription<-",
PnetMakeStubNodes, PnetRemoveStubNodes,
PnetAdjoin, PnetDetach,
PnetAdjoin, PnetDetach, PnetCompile,
PnetFindNode)

## Manifests

export(BuildNetManifest,BuildNodeManifest)

## Warehouses
exportClasses(PnetWarehouse,PnodeWarehouse)
export(ClearWarehouse,WarehouseManifest,"WarehouseManifest<-",
WarehouseData,WarehouseSupply,WarehouseFetch,
WarehouseMake,WarehouseFree, WarehouseUnpack,
Expand Down
22 changes: 22 additions & 0 deletions R/BNgenerics.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
################################
## Generic objects. These are implemented as class unions, so that
## they can added to by implementing classes.

setClassUnion("Pnode","NULL")
setClassUnion("Pnet","NULL")


###
## These are functions which it is pretty safe to assume that every
## Bayes net package has. We can put them here to make generics so
Expand Down Expand Up @@ -89,6 +97,14 @@ isPnodeContinuous <- function (node)
UseMethod("isPnodeContinuous")
setGeneric("isPnodeContinuous")

PnodeEvidence <- function (node)
UseMethod("PnodeEvidence")
setGeneric("PnodeEvidence")

"PnodeEvidence<-" <- function (node,value)
UseMethod("PnodeEvidence<-")
setGeneric("PnodeEvidence<-")


#### Parents

Expand All @@ -108,6 +124,8 @@ PnodeNumParents <- function (node)
UseMethod("PnodeNumParents")
setGeneric("PnodeNumParents")


###############################################################
## Pnets
PnetName <- function (net)
UseMethod("PnetName")
Expand Down Expand Up @@ -178,5 +196,9 @@ PnetUnserialize <- function (serial) {
unserializePnet(factory,serial)
}

PnetCompile <- function(net)
UseMethod("PnetCompile")
setGeneric("PnetCompile")



2 changes: 1 addition & 1 deletion R/Manifest.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ BuildNodeManifest <- function (Pnodelist) {
if (isPnodeContinuous(nd)) {
StateValue <- c(StateValue,rep(NA_real_,k))
bnds <- PnodeStateBounds(nd)
LowerBound <- c(UpperBound,bnds[,1L])
LowerBound <- c(LowerBound,bnds[,1L])
UpperBound <- c(UpperBound,bnds[,2L])
} else {
if (!is.null(PnodeStateValues(nd))) {
Expand Down
15 changes: 15 additions & 0 deletions R/Pnets.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,21 @@ setGeneric("PnodePriorWeight")
}
setGeneric("PnodePriorWeight<-")

PnodePostWeight <- function (node) {
UseMethod("PnodePostWeight")
}
setGeneric("PnodePostWeight")

PnodeProbs <- function (node) {
UseMethod("PnodeProbs")
}
setGeneric("PnodeProbs")

"PnodeProbs<-" <- function (node,value) {
UseMethod("PnodeProbs<-")
}
setGeneric("PnodeProbs<-")

PnodeParentTvals <- function (node) {
UseMethod("PnodeParentTvals")
}
Expand Down
2 changes: 1 addition & 1 deletion R/QOmegaMat.R
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ Omega2Pnet <- function(OmegaMat,pn,nodewarehouse,
napar <- sapply(PnodeParentTvals(node),function(x) any(is.na(x)))
if (any(napar)) {
flog.error("Parents %s of node %s don't have levels set.",
paste(parnames[napar],collapse=", "),nodename)
paste(parnames[napar],collapse=", "),ndn)
stop("Parent",paste(parnames[napar],collapse=", "),
"of node", nodename, "don't have levels set.")
}
Expand Down
2 changes: 2 additions & 0 deletions R/Warehouses.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
setClassUnion("PnodeWarehouse","NULL")
setClassUnion("PnetWarehouse","NULL")


ClearWarehouse <- function (warehouse)
Expand Down
2 changes: 1 addition & 1 deletion R/shinyNode.R
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,6 @@ DPCGadget <- function(pnode, color="steelblue") {
}

##########################################
## Shiny breaks the show command
## Shinyjs breaks the show command

show <- methods::show
9 changes: 2 additions & 7 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
* checking for missing documentation entries ... WARNING
Undocumented code objects:
‘WarehouseInventory’ ‘WarehouseUnpack’
‘flog.try’ ‘name’
Undocumented S4 methods:
generic 'WarehouseSupply' and siglist 'ANY'
Functions or methods with usage in documentation object 'Pnet' but not in code:
Pnet.ANY

PnodePostWeight ‘name’


https://docs.google.com/spreadsheets/d/{key}/gviz/tq?tqx=out:csv&sheet={sheet_name}

https://docs.google.com/spreadsheets/d/1UoIfFQn5TUwDBDWqxBEQxkwJbUHHjlo7WDCebvzx9j8/edit?usp=sharing
20 changes: 10 additions & 10 deletions inst/auxdata/Mini-PP-Nodes.csv
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"","Model","NodeName","ModelHub","NodeTitle","NodeDescription","NodeLabels","Continuous","Nstates","StateName","StateTitle","StateDescription","StateValue","LowerBound","UpperBound"
"1","miniPP_CM","Physics","","Physics Understanding","General understanding of Newtonian mechanics.","pnodes,Proficiencies",FALSE,3,"High","Highest 1/3","Highest third of target population",0.967421566101701,NA,NA
"1","miniPP_CM","Physics","","Physics Understanding","General understanding of Newtonian mechanics.","Proficiencies,pnodes",FALSE,3,"High","Highest 1/3","Highest third of target population",0.967421566101701,NA,NA
"2","miniPP_CM","Physics","","","","",NA,NA,"Medium","Middle 1/3","Middle Third of target Population",0,NA,NA
"3","miniPP_CM","Physics","","","","",NA,NA,"Low","Lowest 1/3","Lowest third of target population",-0.967421566101701,NA,NA
"4","miniPP_CM","IterativeD","","Use iterative design to solve a problem","Mass and GPE are directly related
Height and GPE are directly related","pnodes,LowLevel,Proficiencies",FALSE,3,"High","","Complete Mastery",0.967421566101701,NA,NA
Height and GPE are directly related","Proficiencies,pnodes,LowLevel",FALSE,3,"High","","Complete Mastery",0.967421566101701,NA,NA
"5","miniPP_CM","IterativeD","","","","",NA,NA,"Medium","","Partial Mastery",0,NA,NA
"6","miniPP_CM","IterativeD","","","","",NA,NA,"Low","","No Mastery",-0.967421566101701,NA,NA
"7","miniPP_CM","EnergyTransfer","","Energy can Transfer","Energy can transfer from one object to another.","pnodes,LowLevel,Proficiencies",FALSE,3,"High","","Can use to solve difficult problems",0.967421566101701,NA,NA
"7","miniPP_CM","EnergyTransfer","","Energy can Transfer","Energy can transfer from one object to another.","Proficiencies,pnodes,LowLevel",FALSE,3,"High","","Can use to solve difficult problems",0.967421566101701,NA,NA
"8","miniPP_CM","EnergyTransfer","","","","",NA,NA,"Medium","","Can use to solve simple but not difficult problems",0,NA,NA
"9","miniPP_CM","EnergyTransfer","","","","",NA,NA,"Low","","Can not solve simple problems.",-0.967421566101701,NA,NA
"10","miniPP_CM","NTL","","Newton's Third Law","Force pairs act in opposite directions
Force pairs have equal magnitudes","pnodes,LowLevel,Proficiencies",FALSE,3,"High","","",0.967421566101701,NA,NA
Force pairs have equal magnitudes","Proficiencies,pnodes,LowLevel",FALSE,3,"High","","",0.967421566101701,NA,NA
"11","miniPP_CM","NTL","","","","",NA,NA,"Medium","","",0,NA,NA
"12","miniPP_CM","NTL","","","","",NA,NA,"Low","","",-0.967421566101701,NA,NA
"13","miniPP_CM","POfMom","","Properties of momentum","Momentum is directly related to mass
Momentum is directly related to velocity
Momentum is parallel to velocity","pnodes,LowLevel,Proficiencies",FALSE,3,"High","","",0.967421566101701,NA,NA
Momentum is parallel to velocity","Proficiencies,pnodes,LowLevel",FALSE,3,"High","","",0.967421566101701,NA,NA
"14","miniPP_CM","POfMom","","","","",NA,NA,"Medium","","",0,NA,NA
"15","miniPP_CM","POfMom","","","","",NA,NA,"Low","","",-0.967421566101701,NA,NA
"Right","PPcompEM","CompensatoryObs","miniPP_CM","Compensatory Observable","A binary response which requires both parent variables for high probability of success.","onodes,Observables,pnodes",FALSE,2,"Right","","",NA,NA,NA
Expand All @@ -25,11 +25,11 @@ Momentum is parallel to velocity","pnodes,LowLevel,Proficiencies",FALSE,3,"High"
"Full","PPtwostepEM","TwoStepObs","miniPP_CM","Partial Credit observable","A partial credit response where each step requires different inputs.","onodes,Observables,pnodes",FALSE,3,"Full","Complete Solution","",NA,NA,NA
"Partial","PPtwostepEM","TwoStepObs","","","","",NA,NA,"Partial","First step but not second","",NA,NA,NA
"None","PPtwostepEM","TwoStepObs","","","","",NA,NA,"None","No attempt of failed first step","",NA,NA,NA
"one","PPdurAttEM","Attempts","miniPP_CM","Number of Attempts","The number of times level was started or restarted","onodes,Observables,pnodes",TRUE,4,"one","1","",NA,0.5,1.5
"two","PPdurAttEM","Attempts","","","","",NA,NA,"two","2","",NA,1.5,2.5
"three","PPdurAttEM","Attempts","","","","",NA,NA,"three","3","",NA,2.5,3.5
"fourPlus","PPdurAttEM","Attempts","","","","",NA,NA,"fourPlus","4 or more","",NA,3.5,Inf
"Q1","PPdurAttEM","Duration","miniPP_CM","Time spent on level","Total time spent on level less time spent on learning supports","onodes,Observables,pnodes",TRUE,4,"Q1","0–30.190","",NA,0,30.19
"one","PPdurAttEM","Attempts","miniPP_CM","Number of Attempts","The number of times level was started or restarted","pnodes,onodes,Observables",TRUE,4,"one","1","",NA,0.1,1.1
"two","PPdurAttEM","Attempts","","","","",NA,NA,"two","2","",NA,1.1,2.1
"three","PPdurAttEM","Attempts","","","","",NA,NA,"three","3","",NA,2.1,3.1
"fourPlus","PPdurAttEM","Attempts","","","","",NA,NA,"fourPlus","4 or more","",NA,3.1,Inf
"Q1","PPdurAttEM","Duration","miniPP_CM","Time spent on level","Total time spent on level less time spent on learning supports","pnodes,onodes,Observables",TRUE,4,"Q1","0–30.190","",NA,0,30.19
"Q2","PPdurAttEM","Duration","","","","",NA,NA,"Q2","30.190–67.037","",NA,30.19,67.037
"Q3","PPdurAttEM","Duration","","","","",NA,NA,"Q3","67.037–154.893","",NA,67.037,154.893
"Q4","PPdurAttEM","Duration","","","","",NA,NA,"Q4","154.893—Inf","",NA,154.893,Inf
89 changes: 0 additions & 89 deletions man/BNgenerics.Rd

This file was deleted.

22 changes: 13 additions & 9 deletions man/BuildNodeManifest.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ BuildNodeManifest(Pnodelist)
are used instead.}
\item{LowerBound}{This servers as the lower bound for each partition
of the continuous variagle. \code{-Inf} is a legal value for the
first row.}
first or last row.}
\item{UpperBound}{This is only used for continuous variables, and the
value only is needed for one of the states. This servers as the
upper bound of range each state. Note the upper
bound needs to match the lower bounds of the next state. \code{Inf}
is a legal value for the last row.}
is a legal value for the first or last row.}

}
\section{Continuous Variables}{

Expand Down Expand Up @@ -192,6 +192,8 @@ nodeman1 <- read.csv(file.path(library(help="Peanut")$path, "auxdata",

\dontrun{
library(PNetica) ## Requires PNetica
sess <- NeticaSession()
startSession(sess)

netpath <- file.path(library(help="PNetica")$path, "testnets")
netnames <- paste(c("miniPP-CM","PPcompEM","PPconjEM","PPtwostepEM",
Expand All @@ -210,13 +212,15 @@ for (n in 1:length(EMs)) {
BuildNodeManifest(lapply(NetworkAllNodes(EMs[[n]]),
as.Pnode)))
}
## Exclude node labels from this test, as they could appear in arbitrary order
stopifnot(all.equal(nodeman[,-6],nodeman1[,-6]))
## Note: This test might fail because of node order. Need to improve it.

nl <- strsplit(nodeman$NodeLabels,",")
nl1 <- strsplit(nodeman1$NodeLabels,",")
stopifnot(all(mapply(setequal,nl,nl1)))
## Need to ensure that labels are in cannonical order only for the
## purpose of testing
nodeman[,6] <- sapply(strsplit(nodeman[,6],","),
function(l) paste(sort(l),collapse=","))
nodeman1[,6] <- sapply(strsplit(nodeman1[,6],","),
function(l) paste(sort(l),collapse=","))

stopifnot(all.equal(nodeman,nodeman1))

## This is the node warehouse for PNetica
Nodehouse <- NNWarehouse(manifest=nodeman1,
Expand Down
7 changes: 5 additions & 2 deletions man/BuildTable.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ BuildAllTables(net, debug=FALSE)
}

\seealso{
\code{\link{Pnode}}, \code{\link{PnodeQ}},
\code{\link{Pnode}}, \code{\link{PnodeProbs}}, \code{\link{PnodeQ}},
\code{\link{PnodePriorWeight}}, \code{\link{PnodeRules}},
\code{\link{PnodeLink}}, \code{\link{PnodeLnAlphas}},
\code{\link{PnodeAlphas}}, \code{\link{PnodeBetas}},
\code{\link{PnodeLinkScale}},\code{\link{GetPriorWeight}},
\code{\link[CPTtools]{calcDPCTable}}

In many implementations, it will be necessary to run
\code{\link{PnetCompile}} after building the tables.
}
\examples{

Expand All @@ -88,7 +91,7 @@ BuildAllTables(net, debug=FALSE)
## NodeExperience functions are part of the RNetica implementation.

BuildTable.NeticaNode <- function (node) {
node[] <- calcDPCFrame(ParentStates(node),NodeStates(node),
node[] <- calcDPCFrame(ParentStates(node),PnodeStates(node),
PnodeLnAlphas(node), PnodeBetas(node),
PnodeRules(node),PnodeLink(node),
PnodeLinkScale(node),PnodeQ(node),
Expand Down
Loading

0 comments on commit 0810afa

Please sign in to comment.