Ejemplo n.º 1
0
    def respond_to_demonstration_letter(self,
                                        demonstration,
                                        letter,
                                        mode='midway',
                                        mode_param=0.5):
        demo_stroke = Stroke()
        demo_stroke.stroke_from_xxyy(
            np.reshape(demonstration, len(demonstration)))
        demo_stroke.normalize_wrt_max()

        if mode == 'midway':
            learned_stroke = stroke.midway(demo_stroke,
                                           self.generated_letters[letter],
                                           mode_param)
            self.generated_letters[letter] = learned_stroke
            save_learned_allograph(self.child_path, letter, learned_stroke)
            _, score = stroke.euclidian_distance(demo_stroke,
                                                 self.refs[letter])

        if mode == 'simple':
            learned_stroke = stroke.weigthedSum(demo_stroke,
                                                self.generated_letters[letter],
                                                mode_param)
            self.generated_letters[letter] = learned_stroke
            save_learned_allograph(self.child_path, letter, learned_stroke)
            _, score = stroke.euclidian_distance(demo_stroke,
                                                 self.refs[letter])

        return self.shape_message(letter), score
Ejemplo n.º 2
0
    def respond_to_demonstration_word(self, demonstrations, mode='midway'): #mutual_modeling will act here
        if mode == 'midway':
            for letter,stroke in demonstrations:
                learned_stroke = stroke.midway(stroke, self.generated_letters[letter])

                self.generated_letters[letter] = learned_stroke
                save_learned_allograph(self.robot_data, letter, learned_stroke)
                score = stroke.euclidian_distance(demo_stroke, self.refs[letter])
Ejemplo n.º 3
0
 def respond_to_demonstration_letter(self, demonstration, letter, grade, mode='midway'):
     demo_stroke = Stroke()
     demo_stroke.stroke_from_xxyy(np.reshape(demonstration,len(demonstration)))
     #demo_stroke.uniformize()
     demo_stroke.normalize_wrt_max()
     if mode == 'midway':
         learned_stroke = stroke.midway(demo_stroke, self.generated_letters[letter], grade)
         self.generated_letters[letter] = learned_stroke
         save_learned_allograph(self.robot_path, letter, learned_stroke)
         _,score = stroke.euclidian_distance(demo_stroke, self.refs[letter])
     #if mode = 'PCA' 
     #if mode = 'sigNorm' (mixture of sigma-log-normal)
     #if mode = 'CNN' (1-D convolutionnal neural networks)
     return self.shape_message(letter),score
Ejemplo n.º 4
0
                        time = bug_variables[0]
                        name = bug_variables[1]
                        ischouchou = bug_variables[2]

                        if found_demo_bug2:
                            string2 = str(found_demo_bug2.group("path2"))
                            string = string_bug + string2
                            try:
                                path = np.array(
                                    literal_eval(string))  #.replace('"','')))
                                graph = Stroke()
                                graph.stroke_from_xxyy(path)
                                graph.downsampleShape(70)

                                if name in prev_strokes:
                                    _, score = stroke.euclidian_distance(
                                        prev_strokes[name], graph)
                                    prev_strokes[name].reset()
                                    prev_strokes[name].stroke_from_xxyy(path)
                                    prev_strokes[name].downsampleShape(70)
                                else:
                                    score = -1.
                                    prev_strokes[name] = Stroke()
                                    prev_strokes[name].stroke_from_xxyy(path)
                                    prev_strokes[name].downsampleShape(70)

                                liste = []
                                liste.append(time)
                                liste.append(child)
                                liste.append(name)
                                liste.append(score)
                                liste.append(ischouchou)
Ejemplo n.º 5
0
                    found_demo = new_demo.search(line)
                    found_button = new_button.search(line)
                    found_word = new_word.search(line)
                    found_repetition = new_repetition.search(line)
                    found_demo_bug = new_demo_bug.search(line)
                    found_demo_bug2 = new_demo_bug2.search(line)
                    found_learn = new_learn.search(line)

                    if found_repetition:
                        word_done = True
                        current_letters = {}
                        for liste in lines:
                            letter = liste[2]
                            if letter in current_demo and letter in current_learn:
                                _, score = stroke.euclidian_distance(
                                    current_demo[letter],
                                    current_learn[letter])
                                wr.writerow([
                                    liste[0], liste[1], liste[2], liste[3],
                                    float('nan'),
                                    float('nan'), 1, f2f
                                ])
#                       lines = []
#                       current_demo = {}
#                       current_learn = {}
#                       feedback = float('nan')
#                       word_done = False
#                       nb_fb=1.

                    if found_learn:
                        string = str(found_learn.group("path"))  #[:-1]
Ejemplo n.º 6
0
                    if bug_on_last_line:
                        time = bug_variables[0]
                        name = bug_variables[1]
                        ischouchou = bug_variables[2]

                        if found_demo_bug2:
                            string2 = str(found_demo_bug2.group("path2"))
                            string = string_bug + string2
                            try:
                                path = np.array(literal_eval(string))  # .replace('"','')))
                                graph = Stroke()
                                graph.stroke_from_xxyy(path)
                                graph.downsampleShape(70)

                                if name in prev_strokes:
                                    _, score = stroke.euclidian_distance(prev_strokes[name], graph)
                                    prev_strokes[name].reset()
                                    prev_strokes[name].stroke_from_xxyy(path)
                                    prev_strokes[name].downsampleShape(70)
                                else:
                                    score = -1.0
                                    prev_strokes[name] = Stroke()
                                    prev_strokes[name].stroke_from_xxyy(path)
                                    prev_strokes[name].downsampleShape(70)

                                liste = []
                                liste.append(time)
                                liste.append(child)
                                liste.append(name)
                                liste.append(score)
                                liste.append(ischouchou)
Ejemplo n.º 7
0
                        
                        path = np.array(literal_eval(string))#.replace('"','')))
                        graph = Stroke()
                        graph.stroke_from_xxyy(path)
                        graph.downsampleShape(70)
                        current_learn[name]=graph



                    if found_word:
                        word = str(found_word.group("word"))[:-1]
                        if word_done:
                            for liste in lines:
                                letter = liste[2]
                                if letter in current_demo and letter in current_learn:
                                    _,score = stroke.euclidian_distance(current_demo[letter], current_learn[letter])
                                    wr.writerow([liste[0],liste[1],liste[2],liste[3],feedback/nb_fb,1,f2f,str(current_learn[letter].x),str(current_learn[letter].y)])
                            lines = []
                            current_demo = {}
                            current_learn = {}
                            feedback = float('nan')
                            word_done = False
                            nb_fb=1.

                    if found_button:
                        
                        
                        if str(found_button.group("button"))=="+":
                            if math.isnan(feedback):
                                feedback = 1
                            else: