[Ruler-commits] r47 - pkg/ruleR/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Aug 27 12:08:31 CEST 2012
Author: merysionek
Date: 2012-08-27 12:08:31 +0200 (Mon, 27 Aug 2012)
New Revision: 47
Modified:
pkg/ruleR/R/ruleR.R
Log:
ruleR - preventing combinig rules of the same class as previousRules
Modified: pkg/ruleR/R/ruleR.R
===================================================================
--- pkg/ruleR/R/ruleR.R 2012-08-26 19:23:35 UTC (rev 46)
+++ pkg/ruleR/R/ruleR.R 2012-08-27 10:08:31 UTC (rev 47)
@@ -104,10 +104,10 @@
function(x, y){
result<-y
if(!is.null(x at previousRule)){ # if there are some rules nested inside 'x'
- result <- calculate(x at previousRule,result)
- }
+ result <- calculate(x at previousRule,result)
+ }
return(calculateSpecific(x,result)) # if there are no more nested functions, execute
- })
+ })
#-------------------------------------------------------------------------------------------
#------------------------------------------------DoubleRules--------------------------------
@@ -241,14 +241,19 @@
if(is.null(a1)) {a1<-sample(2:length(singleRules),1)} #generate 'a' if no is supplied (we don't want to generate a=1 because it is identical function)
if(is.null(cv1)) {cv1<-sample(-100:100,1)} # generate a constant value if no is supplied
if(is.null(n)){n<-sample(c(0,1,2),1,prob=c(3/6,2/6,1/6)) #nesting more than two rules would be impossible to guess
- p<-as.vector(matrix(replicate(n,c(sample(1:length(singleRules),1),sample(1:100,1))),1,2*n))
- } # generate 'n' if it is set as null with different probabilities
+ k<-1:length(singleRules) #preventing nesting the same rules of the same class together
+ r<-sample(k[-a1],n,replace=FALSE)#generating rules to be nested
+ co<-sample(1:100,n) # generating constant values for nested rules
+ p<-as.vector(rbind(r,co))
+
+ } # generate 'n' if it is set as null with different probabilities
- if("constantVal"%in%slotNames(singleRules[[a1]])){m<-new(singleRules[[a1]],constantVal=cv1,previousRule=new("IdenSingleRule"))} else{m<-new(singleRules[[a1]],previousRule=new("IdenSingleRule"))}
+ if("constantVal"%in%slotNames(singleRules[[a1]])){m<-new(singleRules[[a1]],constantVal=cv1,previousRule=new("IdenSingleRule"))
+ }else{m<-new(singleRules[[a1]],previousRule=new("IdenSingleRule"))}
- if(n!=0) {k<-createSR(p[[1]],p[[2]],n-1,p[-c(1,2)]); m at previousRule<-k
- }#else{m at previousRule<-new("IdenSingleRule")}
+ if(n!=0) {k<-createSR(p[[1]],p[[2]],n-1,p[-c(1,2)])
+ m at previousRule<-k}#else{m at previousRule<-new("IdenSingleRule")}
return(m)
}
@@ -353,9 +358,10 @@
if(type==1){ # type=1 means automatic tests
- m<-sample(c(1,2),1) #if m=1 I will create a singleRule, if m=2 rule will be a combination of singleRules, if m=3 rule is a doubleRule
- if(m==1){rule<-createSR()} else{rule<-createDR()} } else
- {z<-sample(2:length(MyRules),1); rule<-MyRules[[z]] }# if m=1 create singleRule else create doubleRulr
+ m<-sample(c(1,2),1)
+ if(m==1){rule<-createSR()} else{rule<-createDR()} # if m=1 create singleRule else create doubleRulre
+
+ } else{z<-sample(2:length(MyRules),1); rule<-MyRules[[z]] }
result<-sequence(x1,x2,rule,n=seqlen)[[1]]
More information about the Ruler-commits
mailing list