def add_chunk(self, chunk): """Adds a chunk to the V Table and generates a V value for it""" if (actr.chunk_slot_value(chunk, "kind") == "MEMORY"): if actr.chunk_slot_value(chunk, "traumatic") == "NO": self.V_TABLE[chunk] = rnd.uniform(0, 2) elif actr.chunk_slot_value(chunk, "traumatic") == "YES": self.V_TABLE[chunk] = self.currentV
def compute_difference(): c = actr.buffer_read('imaginal') n = actr.copy_chunk(c) actr.mod_chunk( n, 'difference', abs( actr.chunk_slot_value(c, 'length') - actr.chunk_slot_value(c, 'goal-length'))) return n
def spreading_activation(self, chunk): """Calculates spreading activation from imaginal""" source = actr.buffer_chunk("imaginal") if len(source) > 0: source = source[0] if (chunk != source): kind1 = actr.chunk_slot_value(source, "KIND") kind2 = actr.chunk_slot_value(chunk, "KIND") if (kind1.upper() == "MEMORY" and kind2.upper() == "MEMORY"): v1 = self.vectorize_memory(source) v2 = self.vectorize_memory(chunk) sim = self.chunk_similarity(source, chunk) w = actr.get_parameter_value(":imaginal-activation") if w is None: w = 0.0 return sim * w
def monitor_retrievals(self, chunk): """Keeps track of what is being retrieved and why""" v = 0.0 # Emotional load of retrieved memory s = 0.0 # Similarity of memory to current situation t = 0.0 # Is the memory traumatic or not? if chunk is not None and \ actr.chunk_slot_value(chunk, "kind") == "MEMORY": param_values = [] for param in sorted(self.model_params.keys()): param_values.append(self.model_params[param]) source = actr.buffer_chunk("imaginal")[0] v = self.V_TABLE[chunk] s = self.chunk_similarity(chunk, source) if actr.chunk_slot_value(chunk, "traumatic") == "YES": t = 1.0 self.TRACE.append([self.counter, self.currentV, actr.mp_time(), v, t, s] + \ param_values)
def add_to_report(target, chunk): global report stem = actr.chunk_slot_value(chunk,"stem") word = actr.chunk_slot_value(chunk,"verb") suffix = actr.chunk_slot_value(chunk,"suffix") irreg = (target[2] == 'blank') if target[0].lower() == word.lower(): if stem == word and suffix.lower() == 'ed': report.append([irreg,'reg']) elif stem == None and suffix == None: report.append([irreg,'none']) elif stem.lower() == target[1].lower() and suffix.lower() == 'blank': report.append([irreg,'irreg']) else: actr.print_warning( "Incorrectly formed verb. Presented %s and produced verb %s,stem %s,suffix %s."% (target[0],word,stem,suffx)) else: actr.print_warning( "Incorrectly formed verb. Presented %s and produced verb %s,stem %s,suffix %s."% (target[0],word,stem,suffx)) report.append([irreg,'error'])
def trial(*features): actr.reset() for slot,value in actr.permute_list(list(zip(slots,features))): attribute(slot,value) goal = actr.define_chunks(["state","categorize"])[0] actr.goal_focus(goal) actr.run(20) answer = actr.chunk_slot_value(actr.buffer_read("imaginal"),"category") if isinstance(answer,numbers.Number): if answer == 1 or answer == 2: return((answer,True)) else: actr.model_output("Model responded with invalid category.") return((0,False)) else: actr.model_output("Model did not respond or provided a non-numeric category.") return((0,False))
def handle_observation(observation): '''observation should have chunk format''' chunk = actr.define_chunks(observation) actr.schedule_simple_event_now("set-buffer-chunk", ['imaginal', chunk[0]]) actr.run(10) d = actr.get_history_data("blending-trace") d = json.loads(d) t = actr.get_history_data("blending-times") MP = actr.get_parameter_value(':mp') # #get t t = access_by_key('TEMPERATURE', d[0][1]) # #the values # vs = [actr.chunk_slot_value(x,'value') for x in chunk_names] # factors = [ 'current_altitude', 'view_left', 'view_diagonal_left', 'view_center', 'view_diagonal_right', 'view_right' ] # factors = ['needsFood', 'needsWater'] result_factors = [ 'turn', 'altitude_change', 'diagonal_right_turn', 'right_turn', 'ascending', 'drop_action' ] # result_factors = ['food','water'] results = compute_S(d, factors) # ,'f3']) for sums, result_factor in zip(results, result_factors): print("For", result_factor) for s, factor in zip(sums, factors): print(factor, MP / t * sum(s)) print("actual value is", actr.chunk_slot_value('OBSERVATION0', 'ACTUAL')) print("done")
def sentence(person, location, target, term): actr.reset() if term == 'person': actr.pdisable("retrieve-from-location") else: actr.pdisable("retrieve-from-person") actr.mod_chunk("goal", "arg1", person, "arg2", location, "state", "test") response_time = actr.run(30)[0] response = actr.chunk_slot_value(actr.buffer_read("goal"), "state") if target: if response.lower() == "'k'".lower(): return (response_time, True) else: return (response_time, False) else: if response.lower() == "'d'".lower(): return (response_time, True) else: return (response_time, False)
def compute_S(blend_trace, keys_list): '''For blend_trace @ time''' #probablities probs = [ x[3] for x in access_by_key( 'MAGNITUDES', access_by_key('SLOT-DETAILS', blend_trace[0][1])[0][1]) ] #feature values in probe FKs = [ access_by_key(key.upper(), access_by_key('RESULT-CHUNK', blend_trace[0][1])) for key in keys_list ] chunk_names = [x[0] for x in access_by_key('CHUNKS', blend_trace[0][1])] #Fs is all the F values (may or may not be needed for tss) #They are organized by chunk, same order as probs vjks = [] for name in chunk_names: chunk_fs = [] for key in keys_list: chunk_fs.append(actr.chunk_slot_value(name, key)) vjks.append(chunk_fs) #tss is a list of all the to_sum #each to_sum is Pj x dSim(Fs,vjk)/dFk #therefore, will depend on your similarity equation #in this case, we need max/min of the features because we use them to normalize max_val = 4 #max(map(max, zip(*feature_sets))) min_val = 1 #min(map(min, zip(*feature_sets))) n = max_val - min_val n = max_val #n = 1 #this case the derivative is: # Fk > vjk -> -1/n # Fk = vjk -> 0 # Fk < vjk -> 1/n #compute Tss #there should be one for each feature #you subtract the sum of each according to (7) tss = {} ts2 = [] for i in range(len(FKs)): if not i in tss: tss[i] = [] for j in range(len(probs)): if FKs[i] > vjks[j][i]: dSim = -1 / n elif FKs[i] == vjks[j][i]: dSim = 0 else: dSim = 1 / n tss[i].append(probs[j] * dSim) ts2.append(sum(tss[i])) #vios viosList = [] viosList.append([actr.chunk_slot_value(x, 'turn') for x in chunk_names]) viosList.append( [actr.chunk_slot_value(x, 'altitude_change') for x in chunk_names]) viosList.append( [actr.chunk_slot_value(x, 'diagonal_right_turn') for x in chunk_names]) viosList.append( [actr.chunk_slot_value(x, 'right_turn') for x in chunk_names]) viosList.append( [actr.chunk_slot_value(x, 'ascending') for x in chunk_names]) viosList.append( [actr.chunk_slot_value(x, 'drop_action') for x in chunk_names]) #compute (7) rturn = [] for vios in viosList: results = [] for i in range(len(FKs)): tmp = 0 sub = [] for j in range(len(probs)): if FKs[i] > vjks[j][i]: dSim = -1 / n elif FKs[i] == vjks[j][i]: dSim = 0 else: dSim = 1 / n tmp = probs[j] * (dSim - ts2[i]) * vios[j] #sum(tss[i])) * vios[j] sub.append(tmp) results.append(sub) print("compute S complete") rturn.append(results) return rturn
def custom_width (feature, angle, x, y): actr.model_output("Computing a custom width for feature: %s being approached at angle %s from position %s,%s."%(feature, angle, x, y)) h = actr.chunk_slot_value(feature, 'height') if isinstance(h,numbers.Number): return(2 * h)
def vectorize_memory(self, chunk): """Returns a vector representation of a chunk""" values = [ actr.chunk_slot_value(chunk, slot) for slot in self.slot_names ] return tuple([x for x in values if x is not None])