Skip to content

Commit

Permalink
parasite code and data update
Browse files Browse the repository at this point in the history
  • Loading branch information
Anya Vostinar committed Nov 21, 2023
1 parent d8a18f2 commit b93d86b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
Binary file modified Analysis/05-02-23-ParasitesLongSpatial/FinalUpdateHost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 8 additions & 5 deletions Analysis/05-02-23-ParasitesLongSpatial/TaskComp.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ library(scales)
#Read in the data
initial_data <- read.table("05-02-23-ParasitesLongSpatial/munged_basic.dat", h=T)
initial_data$task <- factor(initial_data$task, levels=c("NOT", "NAND", "AND", "ORN", "OR", "ANDN", "NOR", "XOR", "EQU"))
initial_data[2] <- data.frame(lapply(initial_data[2], function(x) {gsub("Grid0", "Well-mixed", x)}))
initial_data[2] <- data.frame(lapply(initial_data[2], function(x) {gsub("Grid1", "Structured", x)}))
final_update <- subset(initial_data, update == "40000")
initial_data[2] <- data.frame(lapply(initial_data[2], function(x) {gsub("Grid0", "SA", x)}))
initial_data[2] <- data.frame(lapply(initial_data[2], function(x) {gsub("Grid1", "SP", x)}))
initial_data[2] <- data.frame(lapply(initial_data[2], function(x) {gsub("MOI0.0", "PA", x)}))
initial_data[2] <- data.frame(lapply(initial_data[2], function(x) {gsub("MOI1.0", "PP", x)}))
initial_data[2] <- data.frame(lapply(initial_data[2], function(x) {gsub("_", " ", x)}))
final_update <- subset(initial_data, update == "120000")

host_data <- subset(final_update, partner == "Host")

Expand All @@ -20,7 +23,7 @@ host_data <- subset(final_update, partner == "Host")
ggplot(data=host_data, aes(x=treatment, y=count, color=treatment)) + geom_violin() + ylab("Task Count Final Update") + xlab("Parasites Present or Absent") + theme(panel.background = element_rect(fill='white', colour='black')) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + guides(fill=FALSE) + scale_color_manual(name="Parasites", values=viridis(3)) + facet_wrap(~task, scales = "free") + geom_boxplot(alpha=0.5, outlier.size=0, width=0.1)

#regular box plot
ggplot(data=host_data, aes(x=treatment, y=count, color=treatment)) + geom_boxplot(alpha=0.5, outlier.size=1) + ylab("Task Count Final Update") + xlab("Parasites Present or Absent") + theme(panel.background = element_rect(fill='white', colour='black')) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + guides(fill=FALSE) + scale_color_manual(name="Parasites", values=viridis(3)) + facet_wrap(~task, scales = "free")
ggplot(data=host_data, aes(x=treatment, y=count, color=treatment)) + geom_boxplot(alpha=0.5, outlier.size=1) + ylab("Operation Count Final Update") + xlab("Structure and Parasites Absent or Present") + theme(panel.background = element_rect(fill='white', colour='black')) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + guides(fill=FALSE) + scale_color_manual(name="Treatment", values=viridis(4), labels=c("\nStructure Absent,\nParasites Absent\n", "\nStructure Absent,\nParasites Present\n", "\nStructure Present,\nParasites Absent\n", "\nStructure Present,\nParasites Present\n")) + facet_wrap(~task, scales = "free")+ scale_x_discrete(guide = guide_axis(angle = -20))



Expand All @@ -38,7 +41,7 @@ median(subset(host_data, treatment=="Present" & task=="OR")$count)
wilcox.test(subset(host_data, treatment=="Absent" & task=="ORN")$count, subset(host_data, treatment=="Present" & task=="ORN")$count)

#All tasks over time
ggplot(data=initial_data, aes(x=update, y=count, group=treatment, colour=treatment)) + ylab("Task count") + xlab("Updates") + stat_summary(aes(color=treatment, fill=treatment),fun.data="mean_cl_boot", geom=c("smooth"), se=TRUE) + theme(panel.background = element_rect(fill='white', colour='black')) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + guides(fill=FALSE) +scale_colour_manual(values=viridis(3)) + scale_fill_manual(values=viridis(3)) + facet_grid(task ~ partner, scales='free')
ggplot(data=initial_data, aes(x=update, y=count, group=treatment, colour=treatment)) + ylab("Task count") + xlab("Updates") + stat_summary(aes(color=treatment, fill=treatment),fun.data="mean_cl_boot", geom=c("smooth"), se=TRUE) + theme(panel.background = element_rect(fill='white', colour='black')) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + guides(fill=FALSE) +scale_colour_manual(values=viridis(4)) + scale_fill_manual(values=viridis(4)) + facet_grid(task ~ partner, scales='free')

# Specific host tasks over time
host_over_time <- subset(initial_data, partner=="Host")
Expand Down
11 changes: 6 additions & 5 deletions source/default_mode/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,12 @@ class Host: public Organism {
* Purpose: To add a symbionts to a host's symbionts
*/
int AddSymbiont(emp::Ptr<Organism> _in) {
if((int)syms.size() >= my_config->SYM_LIMIT()){
emp::Ptr<Organism> last_sym = syms.back();
syms.pop_back();
last_sym->SetDead();
}
// Ousting code:
// if((int)syms.size() >= my_config->SYM_LIMIT()){
// emp::Ptr<Organism> last_sym = syms.back();
// syms.pop_back();
// last_sym->SetDead();
// }

if((int)syms.size() < my_config->SYM_LIMIT() && SymAllowedIn()){
syms.push_back(_in);
Expand Down
33 changes: 29 additions & 4 deletions source/sgp_mode/GenomeLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ using Library = sgpl::OpLibrary<
inst::ShiftLeft, inst::ShiftRight, inst::Increment, inst::Decrement,
// biological operations
// no copy or alloc
inst::Reproduce, inst::PrivateIO,
//inst::SharedIO,
inst::Reproduce,
//inst::PrivateIO,
inst::SharedIO,
// double argument math
inst::Add, inst::Subtract, inst::Nand,
// Stack manipulation
inst::Push, inst::Pop, inst::SwapStack, inst::Swap,
// no h-search
//inst::Donate,
inst::Donate,
inst::JumpIfNEq, inst::JumpIfLess,
//inst::Reuptake,
//fls basics
Expand Down Expand Up @@ -72,6 +73,24 @@ class ProgramBuilder : emp::vector<sgpl::Instruction<Spec>> {
return program;
}

sgpl::Program<Spec> BuildNoRepro(size_t length) {
Add("Donate");
Add("Donate");
Add("Donate");
Add("Donate");
Add("Donate");
sgpl::Program<Spec> program;
// Set everything to 0 - this makes them no-ops since that's the first
// inst in the library
program.resize(length - size());
program[0].op_code = Library::GetOpCode("Global Anchor");
program[0].tag = START_TAG;

program.insert(program.end(), begin(), end());

return program;
}

void AddNot() {
// sharedio r0
// nand r0, r0, r0
Expand Down Expand Up @@ -289,6 +308,12 @@ sgpl::Program<Spec> CreateSquareProgram(size_t length) {
return program.Build(length);
}

sgpl::Program<Spec> CreateMutualistStart(size_t length) {
ProgramBuilder program;
program.AddNand();
return program.BuildNoRepro(length);
}

/**
* Picks what type of starting program should be created based on the config and
* creates it. It will be either random, a program that does NOT, or a program
Expand All @@ -298,7 +323,7 @@ sgpl::Program<Spec> CreateStartProgram(emp::Ptr<SymConfigBase> config) {
if (config->RANDOM_ANCESTOR()) {
return CreateRandomProgram(PROGRAM_LENGTH);
} else if (config->TASK_TYPE() == 1) {
return CreatePrivateNotProgram(PROGRAM_LENGTH);
return CreateNotProgram(PROGRAM_LENGTH);
} else {
return CreateSquareProgram(PROGRAM_LENGTH);
}
Expand Down
1 change: 0 additions & 1 deletion source/sgp_mode/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ void AddOrganismPoints(CPUState state, uint32_t output) {
}
// Set output to value of register and set register to new input
INST(SharedIO, {
std::cout << "shared io" << std::endl;
AddOrganismPoints(state, *a);
uint32_t next;
if (state.world->GetConfig()->RANDOM_IO_INPUT()) {
Expand Down
4 changes: 2 additions & 2 deletions source/sgp_mode/SGPWorldSetup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
void SGPWorld::SetupHosts(unsigned long *POP_SIZE) {
for (size_t i = 0; i < *POP_SIZE; i++) {
emp::Ptr<SGPHost> new_org = emp::NewPtr<SGPHost>(
&GetRandom(), this, my_config, CreatePrivateNotProgram(100), my_config->HOST_INT());
&GetRandom(), this, my_config, CreateNotProgram(100), my_config->HOST_INT());
if(my_config->START_MOI()==1){
emp::Ptr<SGPSymbiont> new_sym = emp::NewPtr<SGPSymbiont>(
&GetRandom(), this, my_config, my_config->SYM_INT());
&GetRandom(), this, my_config, CreateMutualistStart(100), my_config->SYM_INT());
new_org->AddSymbiont(new_sym);
}
InjectHost(new_org);
Expand Down

0 comments on commit b93d86b

Please sign in to comment.