コード例 #1
0
    def __init__(self, container, master, genotype):
        """Constructor for slider frame"""
        tk.Frame.__init__(self, container)

        # must make subplots and canvas instance variables so that the making sliders
        # method can access them
        # create CPPN graphs to pack onto the GUI
        f = Figure(figsize=(10, 10), dpi=100)
        self.subp_1 = f.add_subplot(211)
        self.subp_2 = f.add_subplot(212)

        # create graphs of genotype and phenotype
        graph_genotype_GUI(genotype, self.subp_2)
        # get outputs for current genotype
        norm_in = getNormalizedInputs(num_x, num_y)
        outputs = []
        for ins in norm_in:
            outputs.append(genotype.getOutput(ins)[0])
        outputs_np = np.array(outputs, copy=True)
        self.subp_1.imshow(np.reshape(outputs_np, (num_x, num_y)),
                           cmap='Greys')

        # create canvas for GUI
        self.canvas = FigureCanvasTkAgg(f, self)
        self.canvas.show()
        self.canvas.get_tk_widget().pack()

        # initialize dictionary of sliders
        self.scale_dict = {}

        # connect frame to the root
        self.controller = master
コード例 #2
0
    def slider_update_CPPN(self):
        """Pulls weight values from all sliders and updates
		the corresponding weights within the CPPN genotype, 
		then regraphs the plot of the CPPN genotype and 
		phenotype
		"""

        # get needed CPPN inputs
        norm_in = getNormalizedInputs(num_x, num_y)

        keys = list(self.scale_dict.keys())
        # for each connection with a slider, update weight to its current value
        for innov_num in keys:
            innov_num_int = int(innov_num)
            for con in genotype.connections:
                if (con.getInnovationNumber() == innov_num_int):
                    con.setWeight(self.scale_dict[innov_num].get())

        # replot the CPPN with new weights
        # both subplots must be cleared to replace them with new ones
        self.subp_1.clear()
        self.subp_2.clear()

        outputs = []
        for ins in norm_in:
            outputs.append(genotype.getOutput(ins)[0])
        outputs_np = np.array(outputs, copy=True)
        self.subp_1.imshow(np.reshape(outputs_np, (num_x, num_y)),
                           cmap='Greys')

        graph_genotype_GUI(genotype, self.subp_2)

        self.canvas.show()
        self.canvas.get_tk_widget().pack()
コード例 #3
0
    def __init__(self, container, master, genotype):
        """Constructor for the main GUI frame"""

        # instantiate the frame
        tk.Frame.__init__(self, container)

        # connect frame to the controller
        self.controller = master

        f = Figure(figsize=(10, 10), dpi=100)
        subp_1 = f.add_subplot(211)
        subp_2 = f.add_subplot(212)

        # create graphs of genotype and phenotype
        graph_genotype_GUI(genotype, subp_2)
        # get outputs for current genotype
        norm_in = getNormalizedInputs(num_x, num_y)
        outputs = []
        for ins in norm_in:
            outputs.append(genotype.getOutput(ins)[0])
        outputs_np = np.array(outputs, copy=True)
        subp_1.imshow(np.reshape(outputs_np, (num_x, num_y)), cmap='Greys')

        # create canvas for GUI
        canvas = FigureCanvasTkAgg(f, self)
        canvas.show()
        canvas.get_tk_widget().pack()

        # create labels for text entry and text entry
        tk.Label(self, text="Innovation Number").pack(pady=(10, 0))
        tk.Label(self, text="New Weight").pack()
        innov_e = tk.Entry(self)
        weight_e = tk.Entry(self)
        innov_e.pack(pady=(10, 0))
        weight_e.pack()

        # create buttons for exit and entry b      genotype, E1, subp_1, subp_2, norm_in, canvas
        tk.Button(
            self,
            text="Apply",
            command=(lambda: update_CPPN(genotype, innov_e, weight_e, subp_1,
                                         subp_2, norm_in, num_x, num_y, canvas)
                     )).pack()
        tk.Button(
            self,
            text="Sweep Weight",
            command=(lambda: sweep_CPPN(genotype, innov_e, subp_1, subp_2,
                                        norm_in, canvas))).pack()
        tk.Button(self, text="Exit", command=self.quit).pack(pady=(20, 10))
コード例 #4
0
parser.add_argument("act", type=int, 
	help="Activation Mutation Probability.")
parser.add_argument("cross", type=int, 
	help="Crossover probability.")
'''
args = parser.parse_args()

# set numpy seed number for all random numbers
SEED = args.seed
np.random.seed(SEED)

# sets global parameters for 2D structure being created by CPPN, generates inputs
NORM_IN_FILE = open("norm_in.txt", "wb")
NUM_X = 75
NUM_Y = 75
NORM_IN = getNormalizedInputs(NUM_X, NUM_Y)
pickle.dump(NORM_IN, NORM_IN_FILE)

# must get filename from parser to complete file path
FILE_PATH = './fitting_images/' + args.path
PIXELS = getBinaryPixels(FILE_PATH, NUM_X, NUM_Y)
print("Creating distance matrix...")
DIST_MAT_BLACK = get_dist_mat(np.reshape(PIXELS, (NUM_X, NUM_Y)), 1)
DIST_MAT_WHITE = get_dist_mat(np.reshape(PIXELS, (NUM_X, NUM_Y)), 0)
print("Distance matrix created...")

# determines when to save the current population
NGEN_TO_SAVE = args.ngen - 1  # save every n generations

# probability of using NSGA-II to select individuals
SELECT_PROB = 2.0