#colourvision simulation example #Optimum set of photoreceptors #Maximum deltaS library(colourvision) #photoreceptors data("bee") photoreceptor.bee <- bee #background data(Rb) cerrado<-Rb ## Illuminant ## data("D65") I<-D65 #flower data setwd("~/Documents/Felipe Virtual/UFG/Manuscripts/Colour Vision Model Simulations") flower<-read.csv("fred.flowers.csv") flower<-spec.denoise(flower) flower[flower<0]<-0 cols<-sample(2:length(flower), size=50) flower<-flower[,c(1,cols)] #photoreceptors lambda.max<-seq(330,630,30) #dichromat #dichromat #dichromat lambda.max.cbn<-combn(x=lambda.max, m=2, fun=NULL, simplify=TRUE) CTTK2<-list() CTTK2edge<-list() RNL2<-list() for (i in 1:ncol(lambda.max.cbn)) { C<-photor(lambda.max = lambda.max.cbn[,i]) CTTK2[[i]]<-CTTKmodel(R=flower, I=I, Rb=cerrado, C=C) CTTK2edge[[i]]<-GENmodel(R=flower, type="edge", edge=sqrt(3), I=I, Rb=cerrado, C=C, func=function(x){x<-x/(x+1)}) RNL2[[i]]<-RNLmodel(model = "log", R1=flower, I=I, Rb=cerrado, C=C, noise = TRUE, e = rep(0.1,length(lambda.max.cbn[,i]))) } ###trichromat ###trichromat ###trichromat ###trichromat lambda.max.cbn<-combn(x=lambda.max, m=3, fun=NULL, simplify=TRUE) CTTK3<-list() CTTK3edge<-list() RNL3<-list() for (i in 1:ncol(lambda.max.cbn)) { C<-photor(lambda.max = lambda.max.cbn[,i]) CTTK3[[i]]<-CTTKmodel(R=flower, I=I, Rb=cerrado, C=C) CTTK3edge[[i]]<-GENmodel(R=flower, type="edge", edge=sqrt(3), I=I, Rb=cerrado, C=C, func=function(x){x<-x/(x+1)}) RNL3[[i]]<-RNLmodel(model = "log", R1=flower, I=I, Rb=cerrado, C=C, noise = TRUE, e = rep(0.1,length(lambda.max.cbn[,i]))) } ###tetrachromat ###tetrachromat ###tetrachromat ###tetrachromat lambda.max.cbn<-combn(x=lambda.max, m=4, fun=NULL, simplify=TRUE) CTTK4<-list() CTTK4edge<-list() RNL4<-list() for (i in 1:ncol(lambda.max.cbn)) { C<-photor(lambda.max = lambda.max.cbn[,i]) CTTK4[[i]]<-CTTKmodel(R=flower, I=I, Rb=cerrado, C=C) CTTK4edge[[i]]<-GENmodel(R=flower, type="edge", edge=sqrt(3), I=I, Rb=cerrado, C=C, func=function(x){x<-x/(x+1)}) RNL4[[i]]<-RNLmodel(model = "log", R1=flower, I=I, Rb=cerrado, C=C, noise = TRUE, e = rep(0.1,length(lambda.max.cbn[,i]))) } ###pentachromat ###pentachromat ###pentachromat ###pentachromat lambda.max.cbn<-combn(x=lambda.max, m=5, fun=NULL, simplify=TRUE) CTTK5<-list() CTTK5edge<-list() RNL5<-list() for (i in 1:ncol(lambda.max.cbn)) { C<-photor(lambda.max = lambda.max.cbn[,i]) CTTK5[[i]]<-CTTKmodel(R=flower, I=I, Rb=cerrado, C=C) CTTK5edge[[i]]<-GENmodel(R=flower, type="edge", edge=sqrt(3), I=I, Rb=cerrado, C=C, func=function(x){x<-x/(x+1)}) RNL5[[i]]<-RNLmodel(model = "log", R1=flower, I=I, Rb=cerrado, C=C, noise = TRUE, e = rep(0.1,length(lambda.max.cbn[,i]))) } #Results CTTK2.mean.deltaS<-NULL CTTK3.mean.deltaS<-NULL CTTK4.mean.deltaS<-NULL CTTK5.mean.deltaS<-NULL CTTK2edge.mean.deltaS<-NULL CTTK3edge.mean.deltaS<-NULL CTTK4edge.mean.deltaS<-NULL CTTK5edge.mean.deltaS<-NULL RNL2.mean.deltaS<-NULL RNL3.mean.deltaS<-NULL RNL4.mean.deltaS<-NULL RNL5.mean.deltaS<-NULL for (i in 1:length(CTTK2)) { CTTK2.mean.deltaS[[i]]<-mean(CTTK2[[i]]$deltaS) CTTK3.mean.deltaS[[i]]<-mean(CTTK3[[i]]$deltaS) CTTK4.mean.deltaS[[i]]<-mean(CTTK4[[i]]$deltaS) CTTK5.mean.deltaS[[i]]<-mean(CTTK5[[i]]$deltaS) CTTK2edge.mean.deltaS[[i]]<-mean(CTTK2edge[[i]]$deltaS) CTTK3edge.mean.deltaS[[i]]<-mean(CTTK3edge[[i]]$deltaS) CTTK4edge.mean.deltaS[[i]]<-mean(CTTK4edge[[i]]$deltaS) CTTK5edge.mean.deltaS[[i]]<-mean(CTTK5edge[[i]]$deltaS) RNL2.mean.deltaS[[i]]<-mean(RNL2[[i]]$deltaS) RNL3.mean.deltaS[[i]]<-mean(RNL3[[i]]$deltaS) RNL4.mean.deltaS[[i]]<-mean(RNL4[[i]]$deltaS) RNL5.mean.deltaS[[i]]<-mean(RNL5[[i]]$deltaS) } #Set of photoreceptors #di CTTK2.max<-match(max(CTTK2.mean.deltaS),CTTK2.mean.deltaS) CTTK2edge.max<-match(max(CTTK2edge.mean.deltaS),CTTK2edge.mean.deltaS) RNL2.max<-match(max(RNL2.mean.deltaS),RNL2.mean.deltaS) lambda.max.cbn<-combn(x=lambda.max, m=2, fun=NULL, simplify=TRUE) lambda.max.cbn[,CTTK2.max] lambda.max.cbn[,CTTK2edge.max] lambda.max.cbn[,RNL2.max] #tri CTTK3.max<-match(max(CTTK3.mean.deltaS),CTTK3.mean.deltaS) CTTK3edge.max<-match(max(CTTK3edge.mean.deltaS),CTTK3edge.mean.deltaS) RNL3.max<-match(max(RNL3.mean.deltaS),RNL3.mean.deltaS) lambda.max.cbn<-combn(x=lambda.max, m=3, fun=NULL, simplify=TRUE) lambda.max.cbn[,CTTK3.max] lambda.max.cbn[,CTTK3edge.max] lambda.max.cbn[,RNL3.max] #tetra CTTK4.max<-match(max(CTTK4.mean.deltaS),CTTK4.mean.deltaS) CTTK4edge.max<-match(max(CTTK4edge.mean.deltaS),CTTK4edge.mean.deltaS) RNL4.max<-match(max(RNL4.mean.deltaS),RNL4.mean.deltaS) lambda.max.cbn<-combn(x=lambda.max, m=4, fun=NULL, simplify=TRUE) lambda.max.cbn[,CTTK4.max] lambda.max.cbn[,CTTK4edge.max] lambda.max.cbn[,RNL4.max] #penta CTTK5.max<-match(max(CTTK5.mean.deltaS),CTTK5.mean.deltaS) CTTK5edge.max<-match(max(CTTK5edge.mean.deltaS),CTTK5edge.mean.deltaS) RNL5.max<-match(max(RNL5.mean.deltaS),RNL5.mean.deltaS) lambda.max.cbn<-combn(x=lambda.max, m=5, fun=NULL, simplify=TRUE) lambda.max.cbn[,CTTK5.max] lambda.max.cbn[,CTTK5edge.max] lambda.max.cbn[,RNL5.max] #plotting CTTK<-c(CTTK2.mean.deltaS,CTTK3.mean.deltaS,CTTK4.mean.deltaS,CTTK5.mean.deltaS) CTTKedge<-c(CTTK2edge.mean.deltaS,CTTK3edge.mean.deltaS,CTTK4edge.mean.deltaS,CTTK5edge.mean.deltaS) RNL<-c(RNL2.mean.deltaS,RNL3.mean.deltaS,RNL4.mean.deltaS,RNL5.mean.deltaS) names<-c(rep("2",length(CTTK2.mean.deltaS)), rep("3",length(CTTK3.mean.deltaS)), rep("4",length(CTTK4.mean.deltaS)), rep("5",length(CTTK5.mean.deltaS))) names<-factor(names,levels(names)[c(1,4,3,2)]) quartz(width=12, height=4) par(mfrow=c(1,3)) boxplot(CTTK~names, ylim=c(0,0.30), ylab = expression(paste(Delta, "S"))) boxplot(CTTKedge~names, ylim=c(0,0.30), xlab= "Number of photoreceptors") boxplot(RNL~names)