def __init__(self, app, config): super().__init__(config) self.app = app self.app.from_json(config["app_config"]) self.obs_space = self.app.observation_space().as_json().to_python() self.action_space = self.app.action_space().as_json().to_python() # Setup encoder if ("encoder_array" in config.keys()): self.encoder = neuro.EncoderArray(config["encoder_array"]) else: ea_json = {} if ("encoders" in config.keys()): ea_json["encoders"] = config["encoders"] elif ("named_encoders" in config.keys()): ea_json["named_encoders"] = config["named_encoders"] ea_json["use_encoders"] = config["use_encoders"] else: ea_json["encoders"] = [config["encoder"]] ea_json["dmin"] = self.obs_space["low"] ea_json["dmax"] = self.obs_space["high"] ea_json["interval"] = config["encoder_interval"] self.encoder = neuro.EncoderArray(ea_json) if ("decoder_array" in config.keys()): self.decoder = neuro.DecoderArray(config["decoder_array"]) else: da_json = {} if ("decoders" in config.keys()): da_json["decoders"] = config["decoders"] elif ("named_decoders" in config.keys()): da_json["named_decoders"] = config["named_decoders"] da_json["use_decoders"] = config["use_decoders"] else: da_json["decoders"] = [config["decoder"]] if ("low" in self.action_space.keys()): da_json["dmin"] = self.action_space["low"] da_json["dmax"] = self.action_space["high"] else: val = self.action_space["max"] da_json["dmin"] = [0] da_json["dmax"] = [val - 1] self.decoder = neuro.DecoderArray(da_json) self.n_inputs = self.encoder.get_num_neurons() self.n_outputs = self.decoder.get_num_neurons()
def __init__(self, config, X, y): split_test_size = config["split_test_size"] split_seed = config["split_seed"] self.runtime = config["runtime"] self.network_filename = config["network_filename"] self.labels = sorted(np.unique(y)) self.config = config self.X_train, self.X_test, self.y_train, self.y_test = train_test_split( X, y, test_size=split_test_size, random_state=split_seed) ea_json = {} if ("encoders" in config.keys()): ea_json["encoders"] = config["encoders"] elif ("named_encoders" in config.keys()): ea_json["named_encoders"] = config["named_encoders"] ea_json["use_encoders"] = config["use_encoders"] else: ea_json["encoders"] = [config["encoder"]] ea_json["dmin"] = [min(X[:, i]) for i in range(len(X[0]))] ea_json["dmax"] = [max(X[:, i]) for i in range(len(X[0]))] ea_json["interval"] = config["encoder_interval"] self.encoder = neuro.EncoderArray(ea_json) self.n_inputs = self.encoder.get_num_neurons() self.n_outputs = config["num_outputs"]
def __init__(self, config, X, y): split_test_size = config["split_test_size"] split_seed = config["split_seed"] self.runtime = config["runtime"] if ("app_params" not in config.keys()): config["app_params"] = {} config["app_params"]["split_test_size"] = config["split_test_size"] config["app_params"]["split_seed"] = config["split_seed"] else: split_test_size = config["app_params"]["split_test_size"] split_seed = config["app_params"]["split_seed"] self.network_filename = config["network_filename"] self.labels = sorted(np.unique(y)) self.config = config if (config["split"] == 1): self.X_train, self.X_test, self.y_train, self.y_test = train_test_split( X, y, test_size=split_test_size, random_state=split_seed) else: self.X_train = [] self.y_train = [] self.X_test = X self.y_test = y if ("encoder_array" in config.keys()): self.encoder = neuro.EncoderArray(config["encoder_array"]) else: ea_json = {} if ("encoders" in config.keys()): ea_json["encoders"] = config["encoders"] elif ("named_encoders" in config.keys()): ea_json["named_encoders"] = config["named_encoders"] ea_json["use_encoders"] = config["use_encoders"] else: ea_json["encoders"] = [config["encoder"]] if (config["timeseries"] == "false"): ea_json["dmin"] = [np.min(X[:, i]) for i in range(len(X[0]))] ea_json["dmax"] = [np.max(X[:, i]) for i in range(len(X[0]))] elif (config["timeseries"] == "true"): ea_json["dmin"] = [np.min(X[:, i]) for i in range(len(X[0]))] ea_json["dmax"] = [np.max(X[:, i]) for i in range(len(X[0]))] ea_json["interval"] = config["encoder_interval"] self.encoder = neuro.EncoderArray(ea_json) # TODO: Encode all of the data as spikes here and store spikes instead of/in addition to data # TODO: Allow for multiple outputs scenarios if ("decoder_array" in config.keys()): self.decoder = neuro.DecoderArray(config["decoder_array"]) else: da_json = {} if ("decoders" in config.keys()): da_json["decoders"] = config["decoders"] elif ("named_decoders" in config.keys()): da_json["named_decoders"] = config["named_decoders"] da_json["use_decoders"] = config["use_decoders"] else: da_json["decoders"] = [config["decoder"]] da_json["dmin"] = [0] da_json["dmax"] = [len(np.unique(y)) - 1] self.decoder = neuro.DecoderArray(da_json) self.n_inputs = self.encoder.get_num_neurons() self.n_outputs = self.decoder.get_num_neurons()